Repository navigation
Conversation
…w a row only where a version the base shows holds it A stored expansion's member was shown when the base showed its code system's HEAD. A row that only a release the caller isn't shown holds (a private release of a public code system) was then listed with its own content. FhirResolver.shown_concepts adds that a version the base shows must hold the row, as the evaluation of carried content already reads members. A row no version holds (an older row OCL keeps for the value sets that took it) still goes with its code system. HEAD, which holds nearly every row, is asked first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVWYYmWDsL1uzvh9q7
…ing a member's row A deleted release the base shows no longer makes a row it holds shown, and a row only deleted versions hold goes with its code system, as one no version holds. The $validate-code test compares the statements run too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVWYYmWDsL1uzvh9q7
…code only in a row the base shows ConceptMap $translate's source or target value set held a code when its default expansion had any active row of it in a code system the caller is shown, so a row only a release the caller isn't shown holds still put the code in scope. holds() now reads the rows as stored $expand lists members (FhirResolver.shown_concepts), so the code answers as one the value set doesn't hold, as ValueSet $validate-code answers it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVWYYmWDsL1uzvh9q7
…es), which the FHIR series builds on fhir-452-b-codes ends the queue of OCL API PRs, so the FHIR series sits on all of them: #1085, #1086, #1089, #1088, #1087, #1090, #1091, #1092 and #1093, and the core changes that need them together. No conflicts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qV2gzsF5GhF5BwTJ6x
|
Please hold this one: a performance fix is coming before it merges. With the check added here, two queries of a stored |
…ound with joins, so its statements can run in parallel The check that a version the base shows holds a row was an OR of correlated subqueries. Postgres checks those row by row and keeps the statement out of parallel workers, so the total and the code systems used of a large expansion lost theirs. FhirResolver.shown_members is the same rule over a whole expansion, as joins: not among the expansion's rows that active versions hold and none of them is shown. $expand uses it. shown_concepts stays for the rows of one code ($validate-code, $translate). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qTD1YeFE2hv9XunNvZ
|
The performance fix is pushed (2078274), so this is ready for review again. The answers are the same, and every earlier test passes unchanged. The rule is now written as joins for a whole expansion, so the large statements run in parallel again, with no index and no migration. The Cost paragraph above has the new numbers. Please merge this and #1092 before #1094, which contains both. |
|
Please hold this one again, sorry. The new form of the check (2078274) can hang in a test database: when autovacuum records the tables as empty in the middle of a test run, Postgres picks a plan for it that doesn't finish. A server with real statistics plans it well, so this is about CI failing or hanging at random, not about production's answers or speed. We're testing a form that avoids it, and I'll say here when it's pushed. |
…ws one by one, and finds a large one's with joins Postgres nests shown_members' joins without end where it has recorded the tables as empty. A test's are, once autovacuum passes: its rows are in an open transaction, and a hundred of them are enough. An expansion of up to 1000 rows has them checked one by one again, by shown_concepts: it is no slower there, and can't be nested. A larger one keeps the joins. Row by row, an expansion of 90,000 rows takes $expand past the time an answer has when members are in no public release. Which of the two depends on the expansion's stored rows alone (one small statement more), so a private release changes no statement. The $expand cases now run for a large expansion too, with ANALYZE in each test's transaction: Postgres then knows its rows, and autovacuum keeps off the tables until it ends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qTD1YeFE2hv9XunNvZ
|
Codex review, full pass on the rule's final form (codex-cli 0.169.0, commit fdc25ba) Verdict: no P0 or P1. Three P2s, all accepted.
findings.json{
"reviewer": "codex-cli 0.169.0",
"perspective": "defects",
"mode": "full",
"commit": "fdc25ba282182bf7915804014b1d9367572024b6",
"verdict": "findings",
"prior": [],
"findings": [
{
"id": "F1.1",
"severity": "P2",
"tag": null,
"file": "core/fhir/resolve.py",
"line": 342,
"claim": "A hidden member can switch the SQL at the cutoff and make its presence observable in the HTTP status.",
"scenario": "An anonymous caller expands a value set with 1,000 stored rows. Adding one row held only by a private release leaves the visible members unchanged but selects the join path. After a bulk load, PostgreSQL can still estimate the relevant tables as empty. If the resulting nested joins hit the request deadline while the row-by-row path finishes, the caller sees 422 too-costly instead of 200 without measuring latency. Creating a private release alone leaves the branch unchanged when stored membership stays fixed. [PostgreSQL planner statistics](https://www.postgresql.org/docs/14/planner-stats.html)",
"action": "Keep hidden rows from selecting a different execution path. Test equivalent requests at 1,000 and 1,001 stored rows with stale statistics and the operation deadline active.",
"lines_delta": null,
"confidence": "medium"
},
{
"id": "F1.2",
"severity": "P2",
"tag": null,
"file": "core/fhir/tests_ops_expand.py",
"line": 477,
"claim": "The plan test can pass while the actual total and used-codesystem scans run serially.",
"scenario": "The test forces the join branch on a four-row expansion, replaces the captured SELECT lists with SELECT 1, and accepts any plan without a SubPlan. A serial join plan passes. The rewrite also removes the release lookups projected by the real used-codesystem query. [PostgreSQL parallel plans](https://www.postgresql.org/docs/14/parallel-plans.html)",
"action": "Explain both captured statements intact on a fixture and planner configuration that permit parallel scans, then assert that the main scans can run below a Gather or Gather Merge.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F1.3",
"severity": "P2",
"tag": null,
"file": "core/fhir/tests_ops_expand.py",
"line": 489,
"claim": "The stale-statistics regression test fails for an ordinary PostgreSQL test database owner.",
"scenario": "A developer runs the FHIR suite with a non-superuser DB_USER that has CREATEDB and owns the test database. PostgreSQL rejects UPDATE pg_class with a permission error before the test sends an expansion request. [PostgreSQL database creation](https://www.postgresql.org/docs/14/sql-createdatabase.html) \u00b7 [PostgreSQL privileges](https://www.postgresql.org/docs/14/ddl-priv.html)",
"action": "Create stale statistics with an ANALYZE before inserting the fixture, or skip the catalog-specific test when the test role lacks the required privilege.",
"lines_delta": null,
"confidence": "high"
}
]
} |
|
This one is ready for review again, at fdc25ba. The hold is over: the new form of the check is tested against what hung the old one (tables recorded as empty), and its test run passed (4,331 and 816 tests). The description has what changed and what it costs: a page of a large value set takes longer than on master. Please merge it before oclapi2#1094, with a merge commit. |
snyaggarwal
left a comment
There was a problem hiding this comment.
Verdict: approve.
Merge order: this PR doesn't depend on the #1087 → #1090 → #1103 stack and can merge to master now. You asked for it before #1094, with a merge commit. git merge-tree shows no textual conflict with #1090 or #1103. Once this lands, #1090 should merge master and rerun CI, since its Expander.entries() builds on members().
What I checked:
- Both forms of the rule give the same answer.
shown_membersdrops the "HEAD holds it" clause safely: the row's parent HEAD must already be shown and active, so that clause is a special case of "a version the caller is shown holds it". Your row-by-row equivalence tests cover holders, callers and bases. $validate-codeand$translate's value set scope use the same rule. Their per-code lookups stay onshown_concepts.- There is no migration and no index. The OCL API is unchanged.
- Cost: the slowdown on large value sets is in the description. The 92,670-member filter goes from 3.5 s to 5.5 s, past the 5 s limit. The FHIR lead accepted it on Dec 3, as you recorded on the ticket, so I'm not treating it as blocking. One cheaper form is suggested inline as a follow-up.
| Exists(held.filter(Exists(shown.filter(id=OuterRef('source_id'))))) | | ||
| ~Exists(held.filter(source__is_active=True))) | ||
|
|
||
| def shown_members(self, expansion_id): |
There was a problem hiding this comment.
Suggestion for a follow-up, non-blocking. The hidden rows are the same for every statement of one request. They depend on the caller and the base, not on activeOnly, filter or the offset.
You could read them once per request: hidden is normally empty, because nearly every member is held by its HEAD or by a release the caller is shown, and that's true of the 92,670-member case too. Then apply ~Q(id__in=hidden_ids), or no condition at all when the list is empty. The count, the page and used() would go back to master's plans, and the anti-join would run once instead of in each of them.
That would likely bring the 5.5 s filter back under the 5 s limit. Expansions of 1,000 rows or fewer can still compute it row by row, to avoid the plan for tables recorded as empty.
There was a problem hiding this comment.
Thank you. Noted as a follow-up, not for this PR.
We measured something close to it: listing the hidden rows first, then leaving them out by id. It was fast while the list was short, but a large private release makes the list long, and the cap that needed made small value sets slower. Reading them once per request, only for expansions of more than 1,000 rows, is different enough to be worth measuring. It would go with another saving we've noted: when some members are in no public release, $expand works out the members twice, on master too.
$expand finds the members of a large expansion that a caller is shown with parallel joins (#1093). PostgreSQL keeps the hash tables those joins share between workers in shared memory, about 45 MB a request. This repository's compose files give the database 128 MB, so a few requests at once failed. Its statements no longer share hash tables: each worker builds its own, about 1 MB a request. The setting ends with $expand's transaction; searches and other operations keep theirs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
|
Merge call update: merge this together with #1092, not on its own. #1092's description (9ac0986) shows that this PR's parallel joins share hash tables in shared memory. That's 38 to 46 MB per So merge this, with a merge commit and before #1094, in the same deploy as #1092. My approval of the code stands. The two conflict only in imports and a helper in |
A stored expansion's shown rows are found with joins (FhirResolver.shown_members), so $expand's statements over a whole expansion can run in parallel. Merged cleanly; no change to this branch's own code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
$expand checks the rows of a small expansion one by one, and finds a large one's with joins. Merged cleanly; no change to this branch's own code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
Part of OpenConceptLab/ocl_online#452.
What it does
FHIR's stored
$expand, ValueSet$validate-codeand the value set scope of ConceptMap$translateread a stored value set's default expansion. A member row was shown whenever the request's FHIR base showed its code system. Concept rows are held by source versions, though, and a public code system can have a release the base doesn't show. A row only such a release holds now leaves no trace in those answers, as FHIR's rule for members says (OpenConceptLab/ocl_online#451): not listed, not counted, not in scope, and with the same statements run as without it.FhirResolver.shown_concepts: a row is shown when its code system is shown and an active version the base shows holds it. A row that no active version holds (an older row OCL keeps for the collections that took it, or one whose only release was deleted) still goes with its code system, as before. In production that's tens of thousands of expansion links, and they stay shown.Cost: a page of a large value set takes longer than on master. SQL for a page of 1,000, measured on value sets built from a local copy of real data, with production's planner settings (medians):
$expandthen also looks for another version of each concept.$expandanswers 422 (too costly).How the rule is checked: an expansion of up to 1,000 stored rows has each row checked by
shown_concepts. A larger one uses the same rule written as joins (shown_members), so its statements keep their parallel plans: two workers for each statement over the members in production's plans, as on master. Only the number of rows stored in the expansion decides which, and counting them (up to 1,001) is one small statement more. Looking up one code always usesshown_concepts: HEAD holds nearly every row, so it is asked first.The evaluation of content a request carries (the phase B work) reads stored members the same way, so stored and carried answers agree.
The OCL API is unchanged. It lists a collection's stored members to anyone who can view the collection, and it serves a concept's versions under its code system's access. These members were already listed there, so this restores FHIR's rule rather than closing an exposure.
What the rule decides (noted for review):
Tests
core/fhir/tests_ops_expand.py:core/fhir/tests_ops_validate_code.py: such a row's code answers as one the value set doesn't have, with the same statements.core/fhir/tests_translate.py: such a row doesn't put its code in a source or target value set's scope (same answer and statements, forward and reverse).$expandcase runs with each form.--parallel=4, then the search-index tests) on fdc25ba: pylint 10.00; 4,111 + 804 tests OK; coverage 97%.Review
$validate-codetest now compares the statements run.$translate's value set scope still on the old rule. Fixed, with a test; a Codex check of that commit was clean.CI note (Nov 30): the first Tests run failed on
ConceptParentsViewTest.test_get_200, which compares two parents that can come back in either order. That's an order-dependent test this PR doesn't touch; the rerun passed.🤖 Generated with Claude Code
https://claude.ai/code/session_01AaZ4qVWYYmWDsL1uzvh9q7