Repository navigation
fix(frontend): retain primary keys in data branch projections - #28133
Conversation
|
Unrelated CI blocker update for MatrixOne ALL CI run 33846244114: attempt 1 had three producer jobs fail on separate self-hosted runners with the identical runner-communication annotation; the final coverage merge job then failed as their downstream prerequisite check.
The three producer check-runs contain only Attempt 1 failed jobs were rerun once as attempt 2. Attempt 2 coverage completed its tests but exposed a PR-owned stale assertion in The rerun 33852883820 completed all required jobs successfully; no unrelated CI blocker remains on that PR head. |
7f9da30 to
5b69d8d
Compare
f65e79e to
1120ce0
Compare
1120ce0 to
3e596fb
Compare
3e596fb to
4a35a36
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review completed at exact head 7c5b2c7 (associated issue #25244).
Design/correctness: the shared effective projection now has one explicit contract across result metadata, ordinary rows, projected LIMIT, and OUTPUT AS: explicit PK components first in PK-definition order, then requested non-PK columns in request order, with deduplication. This directly restores row identity for the issue reproduction. No-COLUMNS, fake-PK/no-PK, COUNT, SUMMARY, and OUTPUT FILE behavior remains unchanged; OUTPUT FILE plus COLUMNS still fails before worker creation.
Counterexamples checked: composite PK order differing from physical order; requested/duplicate/case-insensitive PK names; UPDATE, DELETE, INSERT, unrelated endpoint tables, target/base schema drift, LIMIT 0 and positive LIMIT, generated columns, metadata-name collisions, and OUTPUT AS rollback/error paths. Endpoint schema reconciliation requires explicit PKs to remain compatible and common, so the newly projected key cannot become a target-only/null identity. Result rows and schema consume the same resolved index order.
Performance/lifecycle: resolution is bounded O(visible columns + requested columns + PK columns) with schema-width allocations only. Diff scanning and PK ordering complexity are unchanged. The projection validation executes before pool creation and producer goroutines; this patch adds no goroutine, wait, storage, or cleanup ownership.
Validation: diff-check is clean. The pre-rebase exact patch completed SCA, UT, coverage, build, BVT, and connector checks successfully; the rebase is patch-equivalent and the only new main delta is outside these paths. Focused UT/BVT coverage exercises the exact composite-PK reproduction, output shape and values, LIMIT, all row kinds, OUTPUT AS, fake PK, and error validation.
No blocking correctness, performance, or unhappy-path issue found.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review completed at exact head 7c5b2c77ab8607c93ae42575eeb29f2c8b9d8e77 (related issue #25244).
The design direction is sound: an explicit primary key is row identity, so COLUMNS may prune payload columns but must not prune any PK component. Centralizing that rule in resolveProjectedIdxes keeps ordinary row output, result metadata, LIMIT compaction/sorting, and OUTPUT AS schemas on one effective projection contract. PK definition order is stable; requested non-PK order remains stable; requested/duplicate/case-insensitive PK names are deduplicated. Fake-PK tables intentionally retain the prior behavior.
Counterexamples reviewed: composite PK order differing from physical column order; partial and duplicate PK requests; normal and fake PKs; renamed/schema-reconciled endpoints; UPDATE/DELETE/INSERT and unrelated-table rows; LIMIT 0 and bounded top-K; OUTPUT AS types/nullability/name collisions; generated and target-only columns; unknown columns and cancellation/cleanup paths. The production table binding validates PK indices, and base/historical rows are projected into target layout before this output layer, so the added indices do not create row/schema skew.
Performance impact is proportional only to the required PK values returned/materialized. LIMIT already extracted PK values for ordering before this change; there is no new scan, worker, lock, or lifecycle path. Exact-head substantive CI on the prior identical PR diff was green; this head only rebases onto main, and focused frontend output tests pass locally, including a 100-run repetition and 20-run race repetition on the previous identical diff. At this head, go test -count=1 ./pkg/frontend -run Test(DataBranchOutput|NewApplyBatchInfoExcludesGeneratedColumns|DataBranchDiffAsFile) and git diff --check pass.
No P0/P1/P2/P3 finding remains. APPROVE.
|
Tick the box to add this pull request to the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
Related to #25244
What this PR does / why we need it:
Root cause
When
DATA BRANCH DIFFusedCOLUMNS,resolveProjectedIdxesreturned only the requested visible columns. The row path temporarily extracted primary-key values forOUTPUT LIMITsorting, but final row compaction and result-schema construction still used the requested-only list. Composite primary-key values were therefore absent from both the result rows and their metadata.OUTPUT ASreused the same incomplete list.The older worker-pool leak finding recorded in #25244 is already addressed on current
mainby #26369 (09855ae9b1) and is not changed here.Changes
OUTPUT AStable schemas.COUNT,SUMMARY, andOUTPUT FILEbehavior unchanged.OUTPUT AScontract.Issue-to-test proof
TestDataBranchOutputColumnsIncludeCompositePrimaryKeyasserts the exact five-column metadata (diff,flag, both PK columns, andval) and the exact update row values.TestDataBranchOutputResolveProjectedIdxescovers normal and composite PKs, definition order different from physical order, duplicate/case-insensitive requests, unknown columns, and the fake-PK control case. Table-schema tests cover ordinary output andOUTPUT ASordering.diff_composite_pk_columns.sqlcovers the issue reproduction, partial/duplicate PK requests, UPDATE/DELETE/INSERT rows, projectedOUTPUT LIMIT, unrelated tables, andOUTPUT ASmetadata plus rows.diff_11,diff_13,diff_17,branch_output_limit_order, andmerge_generated_columncases cover the broader data types, lineage depth, materialized schema, limit ordering, and generated-column interactions affected by the shared resolver.Tests run
make buildpkg/frontendCGo test package: passed.28/28each run.diff_11158/158;diff_13137/137;diff_17154/154;branch_output_limit_order21/21;merge_generated_column80/80; remaining branch edge cases314/314.The existing
diff_13,diff_17, and edge/merge result files use historical metadata-width encodings that do not compare cleanly with the current tester. Those runs used-n, which still compared all SQL output, column names/order, and row values. The new regression result was checked twice with metadata comparison enabled.Residual risks
For explicit-PK tables, callers using
COLUMNSwill now receive additional PK columns, in PK definition order, as required for row identity. Fake-PK/no-PK tables and non-row output modes retain their prior behavior. This change does not alter concurrency, storage, or resource-lifecycle code; #25244 remains open for manual validation.CI follow-up
pkg/tests/dmloutput-limit regression assertion to expect the retained primary-key column introduced by this fix; focusedTestDataBranchDiffAsFilepasses locally.Rebase follow-up