Skip to content

Fixes 22530: index container direct-child listings by parent FQN hash - #33795

Merged
mohityadav766 merged 10 commits into
mainfrom
fix/22530-container-children-index
Oct 5, 2026
Merged

mohityadav766 merged 10 commits into
mainfrom
fix/22530-container-children-index

Conversation

@mohityadav766

@mohityadav766 mohityadav766 commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

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, 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 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 10 is satisfied
immediately.

The service root listing (?root=true) had the same shape and the same problem.

The fix: a generated parentFqnHash column (the row's own fqnHash minus its last segment)
plus (parentFqnHash, deleted, name, id), turning both listings into indexed equalities. This is
the pattern already applied to table_entity / stored_procedure_entity in the 1.10.0 migration;
containers were the outlier.

Type of change:

  • Bug fix

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, ...) that
bypasses the entity layer entirely. A plain column would silently go stale there and the moved
subtree would keep answering /children under its old parent. A generated column cannot miss it.

Column order. The index leads with parentFqnHash, where the 1.10.0 precedent leads with
deleted. The container listing's include is tri-state, and on include=ALL there is no deleted
predicate at all — which would strand a deleted-leading index. Leading with parentFqnHash keeps
the equality usable in all three include modes (verified on both engines).

Migration cost. MySQL uses a VIRTUAL generated column, so the ALTER is metadata-only and only
the index build touches rows. PostgreSQL has no virtual generated columns, so the column is STORED
and the ALTER rewrites the table — the same cost the 1.10.0 migration already paid on the much
larger table_entity.

Alternatives rejected. Adding an explicit range predicate, and FORCE INDEX, both leave
PostgreSQL (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_relationship rows are missing but whose FQN is intact; there is an existing
IT (test_listChildren_orphanWithMissingRelationship_isStillDiscoverable) asserting those stay
discoverable. Making the DB path fast keeps that guarantee.

Tests:

Use cases covered

  • Browsing to a container near the root of a deeply nested S3-style hierarchy renders its immediate
    children without scanning the rest of the deployment's containers
  • The children tab's total count, its name search, and the Deleted toggle all stay correct
  • A storage service's root-container listing (?root=true), with and without a ?service= filter
  • Re-parenting a container moves it in the children listings of both the old and new parent
  • Container names containing dots (file.parquet) still resolve as one FQN segment

Unit tests

  • Added 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 LIKE form and pass with the fix.
  • Updated ListFilterTest for the renamed :serviceHashExact bind, including an assertion that
    it stays wildcard-free so the LIKE degenerates to an indexable equality.
  • Unit results: ContainerChildrenQueryShapeTest 3/3, ListFilterTest 40/40.

Backend integration tests

  • Added 4 tests to openmetadata-integration-tests/.../ContainerResourceIT.java:
    • test_listChildren_parentWithLargeSubtreeReturnsOnlyDirectChildren — the reporter's shape
    • test_parentFqnHashColumn_matchesJavaComputedParentHash — the SQL-side derivation must agree
      with FullyQualifiedName.buildHash, including dotted names that get quoted into one segment.
      If these ever drift, /children returns an empty page rather than failing, so the bug would
      reach users as "my containers disappeared" instead of as an error.
    • test_parentChildrenIndex_existsOnDeployedSchema — a missing index is invisible to every
      correctness test (same rows, just scanned), so assert the migration actually created it
    • test_listChildren_followsContainerReparent — listings follow the bulk FQN rewrite
  • Full ContainerResourceIT: 274/274 passing on MySQL and on PostgreSQL, including the 21
    pre-existing hierarchy/root-listing tests as a regression gate.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable — no UI changes. The UI already calls the paginated /children and /ancestors
    endpoints; only their execution plan changes.

Manual testing performed

Reproduced against the hierarchy attached to the issue (output_anon.json — 10,376 containers, 14
levels, 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:

Containers in table Rows scanned Rows returned Time
10,376 10,376 1 90 ms
50,376 50,376 1 169 ms

EXPLAIN ANALYZE, same 50,376-row fixture, warm:

Query MySQL 8.3 PostgreSQL 15
children page 182 ms → 0.022 ms 48.8 ms → 0.038 ms (19,604 → 5 buffers)
children count 105 ms → 0.018 ms 8.1 ms → 0.353 ms
children search (q=) 189 ms → 1.7 ms —
root listing page 305 ms → 0.077 ms —
root listing count 139 ms → 0.025 ms —

Also verified: the index is still chosen when the value arrives as a JDBC bound parameter
(useServerPrepStmts=true is the default) — type=ref, rows=1 — since an ascii_bin column compared
against 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=children N+1 (one getEntityReferenceById per child), which main has 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 needs
no Elasticsearch routing.

UI screen recording / screenshots:

Not applicable.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: not applicable — no schema changes; the DB migration is included for both MySQL and PostgreSQL.
  • For UI changes: not applicable.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • I have added a test that covers the exact scenario we are fixing, with the issue number referenced in the test.

🤖 Generated with Claude Code

RetriggerConfidence Score: 4/5

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

  1. P2 Invalid index survives retries ▶
  2. P2 MySQL migration is not idempotent ▶
  3. P2 Fully qualified class usage ▶
Summary

This PR replaces hierarchy LIKE scans in container child and root listings with lookups against a generated parentFqnHash column and adds supporting indexes and regression coverage.

  • Adds generated parent-hash columns and covering indexes for MySQL and PostgreSQL.
  • Updates child and root listing queries to use parent-hash equality.
  • Adds query-shape, hierarchy, reparenting, and deployed-schema tests.
  • The latest revision builds the PostgreSQL index concurrently, but its retry path does not recover an invalid interrupted build.
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]
Loading

Reviews (2) · Last reviewed commit: "Build the PostgreSQL parent-children ind..."

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>
@mohityadav766
mohityadav766 requested a review from a team as a code owner September 22, 2026 09:41
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Sep 22, 2026
Comment on lines +387 to +388
ALTER TABLE storage_container_entity
ADD COLUMN parentFqnHash VARCHAR(768) CHARACTER SET ascii COLLATE ascii_bin

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Fully qualified class usage

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!

mohityadav766 and others added 5 commits October 1, 2026 13:08
…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>
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — manual (2026-10-05T08:32:21Z)

The entry left the queue before it was built, so no checks ran against it.

mohityadav766 and others added 3 commits October 5, 2026 15:34
…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>
@gitar-bot

gitar-bot Bot commented Oct 5, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 closed / 1 findings

🔴 High risk · Adds generated columns and indexes, including a PostgreSQL table-rewriting migration.

Replaces inefficient LIKE scans in container child and root listings with indexed equality lookups against a generated parentFqnHash column. The fix reduces query cost from O(containers in deployment) to O(direct children returned), with comprehensive test coverage including query-shape validation, hierarchy reparenting, and schema verification on both MySQL and PostgreSQL. MySQL migration DDL has been made idempotent.

✅ 1 closed
✅ Quality: MySQL migration DDL not idempotent unlike Postgres

📄 bootstrap/sql/migrations/native/2.1.0/mysql/schemaChanges.sql:387-401 📄 bootstrap/sql/migrations/native/2.1.0/postgres/schemaChanges.sql:347-361
The new MySQL migration adds parentFqnHash and idx_storage_container_entity_parent_children with a bare ALTER TABLE ... ADD COLUMN and CREATE INDEX, with no existence guard. The PostgreSQL companion uses ADD COLUMN IF NOT EXISTS / CREATE INDEX IF NOT EXISTS, and other statements in this very file wrap DDL in an information_schema-driven prepared statement precisely because "MySQL has no CREATE INDEX IF NOT EXISTS" (see the automations_workflow block). If this migration is re-run or retried after a mid-migration failure, MySQL hard-fails with Duplicate column name 'parentFqnHash' / Duplicate key name, whereas Postgres re-runs cleanly. This contradicts the repo's append-only/idempotent migration guideline and the established guard pattern in the same file.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UI rendering very slow for nested containers

2 participants