Repository navigation
fix(jdbi): read the relationship keyset page as a primary key range on Postgres (backport 2.0 #37582) - #38688
Conversation
…n Postgres (backport 2.0 #37582)
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
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 |
Code Review ✅ Approved 🟡 Medium riskReplacing 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. VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. 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:
Cherry-pick of #37582 to
2.0. No linked issue, by choice. The2.1backport is #37583.Problem.
getAllRelationshipsAfterreadsentity_relationshipone page at a time. It writes "rows after the cursor" as fourORed 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.0three callers walk the whole table with it:relationshipCleanupops command, pages of 1,000 by default;Fix. The query now has one version per engine:
(fromId, toId, relation, relationType) > (...), which Postgres reads as a primary key range.ORquery 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, because2.0is older:2.0the query lives inCollectionDAO, notCoreRelationshipDAOs. The change to it is the same.2.0(its first version came with the 2.1.0 lineage migration). It is added here as it reads onmainand2.1, so the three branches carry the same record. ItsRelatedline names a record and a 2.1.0 migration class that2.0does not have.entity_relationshiptable follows the2.0schema: it drops the 2.1 columnsrelationshipId/relationshipTypeIdand the indexes that came with 2.1.Type of change:
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 the2.0indexes:relationorrelationType;2.0query, 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)RelationshipKeysetPageSqlTestEntityRelationshipCleanupITScope: focused; merge readiness is not established.
UI screen recording:
Not applicable: backend only.
Checklist:
Fixes #(no issue, by choice)2.0, unchanged.