Skip to content

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

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

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

Conversation

@manerow

@manerow manerow commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Cherry-pick of #37582 to 2.0. No linked issue, by choice. The 2.1 backport is #37583.

Problem. getAllRelationshipsAfter reads entity_relationship one page at a time. It writes "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.

On 2.0 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.

Both return the same rows in the same order: all four key columns are NOT NULL.

What differs from main. The cherry-pick did not apply cleanly, because 2.0 is older:

  • On 2.0 the query lives in CollectionDAO, not CoreRelationshipDAOs. The change to it is the same.
  • The decision record does not exist on 2.0 (its first version came with the 2.1.0 lineage migration). It is added here as it reads on main and 2.1, so the three branches carry the same record. Its Related line names a record and a 2.1.0 migration class that 2.0 does not have.
  • The test's entity_relationship table follows the 2.0 schema: it drops the 2.1 columns relationshipId / relationshipTypeId and the indexes that came with 2.1.

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 2.0 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. Both plan checks fail on the old 2.0 query, which has no per-engine version.
  • EntityRelationshipCleanupIT (existing, uses this query) passed on Postgres (-Ppostgres-opensearch), the engine whose query changed.

Local results (base origin/2.0)

Test Engine Tests Failed
RelationshipKeysetPageSqlTest MySQL 8.3 + Postgres 15 (Testcontainers) 4 0
EntityRelationshipCleanupIT Postgres + OpenSearch 4 0

Scope: focused; merge readiness is not established.

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.
  • Decision check: adds the existing record to 2.0, unchanged.

@manerow
manerow requested a review from a team as a code owner November 25, 2026 12:50
@manerow
manerow requested review from IceS2 and removed request for a team November 25, 2026 12:50
@manerow manerow self-assigned this Nov 25, 2026
@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.

@manerow manerow added the skip-pr-checks Bypass PR metadata validation check label Nov 25, 2026
@gitar-bot

gitar-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk

Replacing PostgreSQL’s OR cursor with a composite-key comparison changes relationship scan pagination; a cursor mismatch could skip rows during cleanup or migration.

Fixes the relationship keyset page query on Postgres by replacing the OR-chain cursor condition with a row comparison on the primary key, so full-table walks in the Data Retention cleanup, the relationshipCleanup ops command, and the 2.0.3 lineage migration no longer grow quadratically. MySQL keeps the existing OR query, and both return identical rows in the same order. 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 ed5b803 into 2.0 Nov 25, 2026
62 of 68 checks passed
@manerow
manerow deleted the fix/relationship-keyset-scan-postgres-2.0 branch November 25, 2026 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-pr-checks Bypass PR metadata validation check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant