Repository navigation
Fixes 22530: index container direct-child listings by parent FQN hash - #33795
Conversation
Listing a container's children resolved "exactly one segment below this FQN"
with `fqnHash LIKE '<parent>.%' AND fqnHash NOT LIKE '<parent>.%.%'`. Those
select the right rows, but neither predicate is an indexable equality, so the
listing's `ORDER BY name, id LIMIT n` made idx_storage_container_entity_
deleted_name_id -- which already supplies that order -- the cheapest plan on
both MySQL and PostgreSQL, and the query scanned container rows until the page
filled. A container near the root of a deep tree has a large subtree but few
direct children, so the scan ran to the end of the table: the cost was
O(containers in the deployment), not O(children returned), and both the page
and count queries paid it on every render. The service root listing
(?root=true) had the same shape and the same problem.
Add a generated `parentFqnHash` column -- the row's own fqnHash minus its last
segment -- plus (parentFqnHash, deleted, name, id), turning both listings into
indexed equalities. Generated rather than application-maintained so it cannot
drift from the bulk `UPDATE ... SET fqnHash = REPLACE(...)` that re-parenting
uses, which bypasses the entity layer. This is the pattern already applied to
table_entity and stored_procedure_entity in the 1.10.0 migration; containers
were the outlier. The index leads with parentFqnHash rather than `deleted`
(as 1.10.0 does) because the container listing's `include` is tri-state, and
include=ALL has no `deleted` predicate to anchor a deleted-leading index.
Measured on the hierarchy attached to the issue (10,376 containers, 14 levels
deep, root with one direct child and 10,375 descendants) plus 40k unrelated
containers, warm:
MySQL 8.3 PostgreSQL 15
children page 182 ms -> 0.022 ms 48.8 ms -> 0.038 ms
children count 105 ms -> 0.018 ms 8.1 ms -> 0.353 ms
children search 189 ms -> 1.7 ms
root page 305 ms -> 0.077 ms
root count 139 ms -> 0.025 ms
Before the fix the scan grew with deployment size rather than the answer:
10,376 containers scanned 10,376 rows to return 1; adding 40k unrelated
containers made the same query scan 50,376 rows to return the same 1 row.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
✅ PR checks passedThe linked issue has a description and all required Shipping project fields set. Thanks! |
| ALTER TABLE storage_container_entity | ||
| ADD COLUMN parentFqnHash VARCHAR(768) CHARACTER SET ascii COLLATE ascii_bin |
There was a problem hiding this comment.
MySQL migration is not idempotent
The new ADD COLUMN and CREATE INDEX operations are unconditional, which violates the repository requirement to make migrations idempotent where possible. MySQL DDL commits implicitly, so if either operation succeeds without its migration-log entry being persisted, a retry can fail on the duplicate column or index and block the upgrade. Both operations should use the information_schema and prepared-statement guard pattern already used elsewhere in this migration. This repository requirement must be satisfied before merging.
Context Used: CLAUDE.md (source)
Knowledge Base Used: Roll back version history pagination and its large-table migration
| assertNotNull(page); | ||
| assertNotNull(page.getData()); | ||
| Set<UUID> returned = | ||
| page.getData().stream().map(Container::getId).collect(java.util.stream.Collectors.toSet()); |
There was a problem hiding this comment.
The new test code calls java.util.stream.Collectors.toSet() here and again in childIdsOf. This violates the repository's Java directive to import classes instead of using fully qualified names in code. Import Collectors and use Collectors.toSet() at both new call sites. This repository requirement must be satisfied before merging.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
…hildren-index
Conflicts in bootstrap/sql/migrations/native/2.1.0/{mysql,postgres}/schemaChanges.sql:
both sides appended to the end of the file. Resolved by keeping main's additions
(audit_log_event.entity_fqn -> TEXT, announcement type column + index, MySQL charset
pin) followed by this branch's parentFqnHash block, so main's version of each file is
an exact prefix of the result and this branch's change remains a pure append.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three Javadoc blocks on the ?root=true tests still described the depth check as `fqnHash NOT LIKE :serviceHashChild` with a `'%.%.%'` default, which this branch replaced with `parentFqnHash LIKE :serviceHashExact` (default `'%'`) plus a `parentFqnHash NOT LIKE '%.%'` companion. Comment-only; the assertions are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every other DDL block added to 2.1.0/mysql on main is wrapped in an information_schema check executed through a prepared statement, because MySQL has no ADD COLUMN / CREATE INDEX ... IF NOT EXISTS. This branch's column and index were plain statements, so any re-execution -- the runner re-runs a statement whenever its text hash is not yet recorded, e.g. after an interrupted run -- would abort the migration with "Duplicate column name". Both are now guarded and re-run as no-ops. The PostgreSQL side already uses IF NOT EXISTS and needs no change. The prepared-statement names are unique rather than the `PREPARE stmt FROM @ddl` form some blocks reuse: the runner records statements by (version, hash of text) and skips text it has already executed, so a reused `EXECUTE stmt;` would be skipped instead of run. Verified on MySQL 8.3: first run creates the column and index, second and third runs exit 0 as no-ops, the stored generation expression is identical to the previous unguarded form, and parentFqnHash equals fqnHash minus its last segment on every row, including a quoted name containing dots. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hildren-index Conflict in bootstrap/sql/migrations/native/2.1.0/postgres/schemaChanges.sql: main appended the Data Consumer ExecuteSparqlQuery policy rule (#34231) at the end of the file, where this branch's parentFqnHash block sits. Resolved by keeping main's addition followed by this branch's block, so main's version stays an exact prefix. The MySQL file and ListFilter.java merged cleanly; ListFilter's new condition is unrelated to the service/FQN-prefix binds this branch changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hildren-index Conflict in bootstrap/sql/migrations/native/2.1.0/postgres/schemaChanges.sql: main appended the sso_test_login_session table and indexes (#34054) at the end of the file, where this branch's parentFqnHash block sits. Resolved by keeping main's addition followed by this branch's block, so main's version stays an exact prefix. The MySQL migration, ListFilter.java and ListFilterTest.java merged cleanly; main's ListFilter changes do not touch the service/FQN-prefix binds this branch changed, and nothing on main references the old serviceHashChild bind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🚦 Removed from the merge queue —
|
…hildren-index Conflict in bootstrap/sql/migrations/native/2.1.0/postgres/schemaChanges.sql: main appended the announcement type enum rewrite (#34162) at the end of the file, where this branch's parentFqnHash block sits. Resolved by keeping main's addition followed by this branch's block, so main's version stays an exact prefix. The MySQL migration, ListFilter.java and ListFilterTest.java merged cleanly; main's ListFilter change does not touch the service/FQN-prefix binds this branch changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FlowableCharsetMigrationTest.mysqlUpgradeChangesTheCurrentDatabaseDefault requires the final statement of 2.1.0/mysql/schemaChanges.sql to be main's `ALTER DATABASE CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci` (#33659). When I first merged main into this branch (5005a67) I resolved the conflict by appending this branch's parentFqnHash block after main's content, which pushed that statement off the end; every later merge kept the order, and the service unit-test job has failed on that one test since. Move this branch's block above main's Flowable comment and ALTER DATABASE, which is where main's own later MySQL additions go. Main's text is untouched (the file minus this branch's block is byte-identical to origin/main) and no statement's text changes, so databases that already applied an earlier 2.1.0 snapshot re-run nothing. The block specifies its own CHARACTER SET/COLLATE, so running before the database default changes does not affect it. Verified with the CI command (mvn package -pl openmetadata-service -am -Pstatic-code-analysis): 11,089 tests, 0 failures, FlowableCharsetMigrationTest 6/6. The run's only errors were K8sPipelineClientBotTokenBugTest picking up a local stub ~/.kube/config with no server entry; with HOME isolated, as on CI runners, it passes 2/2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code Review ✅ Approved 1 closed / 1 findings🔴 High risk · Adds generated columns and indexes, including a PostgreSQL table-rewriting migration. Replaces inefficient ✅ 1 closed✅ Quality: MySQL migration DDL not idempotent unlike Postgres
OptionsDisplay: compact → Counting what did not apply, without listing it. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
Describe your changes:
Fixes #22530
Listing a container's children resolved "exactly one segment below this FQN" with
fqnHash LIKE '<parent>.%' AND fqnHash NOT LIKE '<parent>.%.%'. Those select the right rows, butneither predicate is an indexable equality — so the listing's
ORDER BY name, id LIMIT nmadeidx_storage_container_entity_deleted_name_id(which already supplies that order) the cheapest planon both MySQL and PostgreSQL, and the query scanned container rows until the page filled.
A container near the root of a deep tree has a large subtree but few direct children, so that scan
runs to the end of the table. The cost was O(containers in the deployment) — not O(children
returned) — and the page and count queries each paid it on every render. That is also why the
reporter saw a flat structure stay instant: there, every row matches, so
LIMIT 10is satisfiedimmediately.
The service root listing (
?root=true) had the same shape and the same problem.The fix: a generated
parentFqnHashcolumn (the row's ownfqnHashminus its last segment)plus
(parentFqnHash, deleted, name, id), turning both listings into indexed equalities. This isthe pattern already applied to
table_entity/stored_procedure_entityin the 1.10.0 migration;containers were the outlier.
Type of change:
High-level design:
Why a generated column rather than one maintained in application code. Re-parenting a container
(#24294) rewrites descendant FQNs with a bulk
UPDATE ... SET fqnHash = REPLACE(fqnHash, ...)thatbypasses the entity layer entirely. A plain column would silently go stale there and the moved
subtree would keep answering
/childrenunder its old parent. A generated column cannot miss it.Column order. The index leads with
parentFqnHash, where the 1.10.0 precedent leads withdeleted. The container listing'sincludeis tri-state, and oninclude=ALLthere is nodeletedpredicate at all — which would strand a deleted-leading index. Leading with
parentFqnHashkeepsthe equality usable in all three include modes (verified on both engines).
Migration cost. MySQL uses a
VIRTUALgenerated column, so theALTERis metadata-only and onlythe index build touches rows. PostgreSQL has no virtual generated columns, so the column is
STOREDand the
ALTERrewrites the table — the same cost the 1.10.0 migration already paid on the muchlarger
table_entity.Alternatives rejected. Adding an explicit range predicate, and
FORCE INDEX, both leavePostgreSQL (which has no index hints) unfixed. Routing the endpoint to Elasticsearch — as the issue
suggested — would reintroduce indexing lag on a read that is currently consistent, and would drop
containers whose
entity_relationshiprows are missing but whose FQN is intact; there is an existingIT (
test_listChildren_orphanWithMissingRelationship_isStillDiscoverable) asserting those staydiscoverable. Making the DB path fast keeps that guarantee.
Tests:
Use cases covered
children without scanning the rest of the deployment's containers
?root=true), with and without a?service=filterfile.parquet) still resolve as one FQN segmentUnit tests
openmetadata-service/src/test/java/org/openmetadata/service/jdbi3/ContainerChildrenQueryShapeTest.java— pins the access path of all five listing queries. The old and new SQL return identical rows, so
no behavioural test can tell them apart; a revert would surface only as production latency. I
confirmed these fail when the DAO is reverted to the
LIKEform and pass with the fix.ListFilterTestfor the renamed:serviceHashExactbind, including an assertion thatit stays wildcard-free so the
LIKEdegenerates to an indexable equality.ContainerChildrenQueryShapeTest3/3,ListFilterTest40/40.Backend integration tests
openmetadata-integration-tests/.../ContainerResourceIT.java:test_listChildren_parentWithLargeSubtreeReturnsOnlyDirectChildren— the reporter's shapetest_parentFqnHashColumn_matchesJavaComputedParentHash— the SQL-side derivation must agreewith
FullyQualifiedName.buildHash, including dotted names that get quoted into one segment.If these ever drift,
/childrenreturns an empty page rather than failing, so the bug wouldreach users as "my containers disappeared" instead of as an error.
test_parentChildrenIndex_existsOnDeployedSchema— a missing index is invisible to everycorrectness test (same rows, just scanned), so assert the migration actually created it
test_listChildren_followsContainerReparent— listings follow the bulk FQN rewriteContainerResourceIT: 274/274 passing on MySQL and on PostgreSQL, including the 21pre-existing hierarchy/root-listing tests as a regression gate.
Ingestion integration tests
Playwright (UI) tests
/childrenand/ancestorsendpoints; only their execution plan changes.
Manual testing performed
Reproduced against the hierarchy attached to the issue (
output_anon.json— 10,376 containers, 14levels, root with 1 direct child and 10,375 descendants) loaded into MySQL 8.3 and PostgreSQL 15 with
the production schema and indexes, plus 40k unrelated containers.
Cost scaled with deployment size, not with the answer:
EXPLAIN ANALYZE, same 50,376-row fixture, warm:q=)Also verified: the index is still chosen when the value arrives as a JDBC bound parameter
(
useServerPrepStmts=trueis the default) —type=ref, rows=1— since anascii_bincolumn comparedagainst a utf8mb4 parameter could otherwise have blocked it; and that the generated column reproduces
the Java-computed parent hash for all 50,376 rows on both engines, checked against an independent
derivation of the hierarchy.
Note on the reported 8–10 s. These numbers are warm and in-memory on one machine, so they are
much smaller in absolute terms than the reporter's 8–10 s on v1.8.6. Part of that latency was the
fields=childrenN+1 (onegetEntityReferenceByIdper child), whichmainhas already removed.What this PR fixes is the remaining scan — the part that grows without bound as a deployment adds
containers.
GET /containers/name/{fqn}itself no longer has any subtree-scaling work, so it needsno Elasticsearch routing.
UI screen recording / screenshots:
Not applicable.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.🤖 Generated with Claude Code
The query redesign appears behaviorally sound, but the explicit migration and Java-style requirements from the previous review must still be satisfied before merging.
Findings
Summary
This PR replaces hierarchy
LIKEscans in container child and root listings with lookups against a generatedparentFqnHashcolumn and adds supporting indexes and regression coverage.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR FQN[Container fqnHash] --> Generated[parentFqnHash generated column] Parent[Requested parent FQN] --> Hash[Java parent hash] Hash --> Equality[parentFqnHash equality] Generated --> Equality Equality --> Index[(parentFqnHash, deleted, name, id)] Index --> Page[Direct-child page and count]Reviews (2) · Last reviewed commit: "Build the PostgreSQL parent-children ind..."