Skip to content

fix(jdbi): read the relationship keyset page as a primary key range on Postgres (backport 2.1 #37582) - #37583

Merged
manerow merged 1 commit into
2.1from
fix/relationship-keyset-scan-postgres-2.1
Nov 13, 2026
Merged

manerow merged 1 commit into
2.1from
fix/relationship-keyset-scan-postgres-2.1

Conversation

@manerow

@manerow manerow commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Describe your changes:

Cherry-pick of #37582 to 2.1. No linked issue, by choice. Follow-up to #37561, which gave the 2.1.0 lineage migration step its own fast query.

Problem. getAllRelationshipsAfter reads entity_relationship one page at a time. It wrote "rows after the cursor" as four ORed conditions. Postgres cannot use that as a range on the primary key, so each page re-reads the table up to the cursor and a full walk grows with the square of the table. MySQL is not affected.

Three callers walk the whole table with it:

  • the relationship cleanup in the Data Retention app (weekly), pages of 10,000;
  • the relationshipCleanup ops command, pages of 1,000 by default;
  • the 2.0.3 lineage migration step, once, on upgrades from before 2.0.3.

Fix. The query now has one version per engine:

  • Postgres: a row comparison, (fromId, toId, relation, relationType) > (...), which Postgres reads as a primary key range.
  • MySQL: the same OR query as today, which MySQL already reads as a range. A row comparison would make MySQL read from the start.

Both return the same rows in the same order: all four key columns are NOT NULL. The decision record gets a v2 amendment that extends its rule to this shared query.

Type of change:

  • Bug fix

High-level design:

Recorded in ADR:2026-11-11-a-composite-keyset-page-is-a-row-comparison-on-postgres-and-an-or-chain-on-mysql (v2).

Tests:

Use cases covered

  • RelationshipKeysetPageSqlTest (new) attaches the real DAO to MySQL and Postgres with the production indexes:
    • walking in pages of 7 returns every row once, in key order, including rows that differ only in relation or relationType;
    • on each engine the page's query plan is a primary key range. The Postgres check fails on the old query.
  • EntityRelationshipCleanupIT (existing, uses this query) passed on MySQL (in the block below); on Postgres it passed on the main change (fix(jdbi): read the relationship keyset page as a primary key range on Postgres #37582), which is the same code.

The new test repeats the table definition of LineageEdgePipelineCleanupMigrationTest on purpose: that one is the frozen 2.1.0 schema of a migration step, this one follows the current schema.

Backend integration tests

Local Java test run: PASSED

  • Commit: ecfbb1efa72c (base origin/2.1)
  • Finished: 2026-11-11 14:43 UTC · 3.9 min
  • Scope: focused; merge readiness is not established. Broader steps deferred: 9 (run --scope full).
Step Scope Classes Tests Failed Skipped Min Result
unit openmetadata-service (1 class) 1 4 0 0 1.2 passed
integration mysql-elasticsearch · parallel 1 4 0 0 2.7 passed
  • Impacted, not run locally: 2 classes (listed in the details)

Manual testing performed

relationshipCleanup --skip-hierarchy-cleanup (dry run) on a Postgres database with 931k relationships, 2.1 nightly with and without this change:

Page size Before After Orphans found
10,000 (Data Retention) 25 to 26 s 7 to 9 s 14,613 both
1,000 (ops default) 204 s 8 s 14,613 both

Times include about 5 s of JVM start.

UI screen recording:

Not applicable: backend only.

Checklist:

  • I have read the CONTRIBUTING document.
  • Title and Fixes # (no issue, by choice)
  • I have commented on my code.
  • I have added tests and listed them above.
  • Self-review against REVIEW.md on fb3e4a73366 (main): no 🔴; this is the same change. 6f28ca153a9 only rewords the record amendment, as that pass suggested.
  • Decision check: amends the record above.

@manerow
manerow requested a review from a team as a code owner November 11, 2026 14:44
@manerow
manerow requested review from yan-3005 and removed request for a team November 11, 2026 14:44
@manerow

manerow commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Local Java test run: PASSED — details

  • Commit: ecfbb1efa72c (base origin/2.1)
  • The summary is in the PR description.

Tests run locally

  • unit · openmetadata-service (1 class): RelationshipKeysetPageSqlTest (4 passed)
  • integration · mysql-elasticsearch · parallel: EntityRelationshipCleanupIT (4 passed)

Broader coverage not executed by this focused run

  • mvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=CheckEntityAttributesImplTest,CustomPropertyReferencesTest,DataProductDomainContainmentRepairTest,EntityDAOTest,EntityRepositoryBulkFieldsTest,EntityRepositorySecretStorageTest,InListChunkingTest,MemoryDerivationsTest,OrphanTestCaseRelationshipCleanupTest,RdfBatchProcessorTest,RdfIndexAppTest,RdfRestorePlannerTest,RdfUpdaterTest,RelationshipKeysetPageSqlTest,SecretMapEntriesExternalStoreTest,ServiceEntitySecretsTest,TableMetadataLoaderTest,VersionHistoryArchitectureTest -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel '-Dit.test=<495 classes>' -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=global-state '-Dit.test=<34 classes>' -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=rdf '-Dit.test=<37 classes>' -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pcache-tests -DintegrationTests.lane=parallel -Dit.test=AlertStateIT,BundleWarmupCertificationIT,ContainerCacheCorrectnessIT,EntityCacheWriteOrderIT,OneTransactionFlushAtomicityIT,RelationshipCacheInvalidationIT,TagRenameCacheIT,UncachedReadIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pcache-tests -DintegrationTests.lane=global-state -Dit.test=CredentialRedisDownIT,CredentialRedisNoRoundTripIT,SessionRedisMultiNodeIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Ppostgres-opensearch -DintegrationTests.lane=parallel '-Dit.test=<47 classes>' -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Ppostgres-opensearch -DintegrationTests.lane=global-state -Dit.test=EntityShapeIT,OntologyConcurrentHardDeleteIT,PatchTableEmbeddingIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Ppostgres-opensearch -DintegrationTests.lane=rdf -Dit.test=RdfSoftDeleteIT,RdfSoftDeleteReindexIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
Why these tests
  • added by author: It pages entity_relationship through getAllRelationshipsAfter, the query this change gives a Postgres variant ← EntityRelationshipCleanupIT
Impacted, not run locally (2)
  • ReindexBenchmarkIT → nightly: openmetadata-nightly k8s-java-it (scale-it)
  • EntityLoaderSmokeUIIT → nightly: openmetadata-nightly k8s-java-it (ui-it + embedded JavaUIIT)
Commands
mvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=RelationshipKeysetPageSqlTest -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel -Dit.test=EntityRelationshipCleanupIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false

@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@gitar-bot

gitar-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk

Switching PostgreSQL relationship pagination to a composite-key range changes cleanup reads; mismatched cursor ordering could skip or repeat relationships.

Backports the relationship keyset page fix to 2.1: on Postgres, getAllRelationshipsAfter now uses a row comparison over (fromId, toId, relation, relationType) so the query reads as a primary key range instead of re-scanning the table on every page, while MySQL keeps the existing OR query. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

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

@manerow
manerow merged commit 10e33cc into 2.1 Nov 13, 2026
51 of 57 checks passed
@manerow
manerow deleted the fix/relationship-keyset-scan-postgres-2.1 branch November 13, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant