Repository navigation
fix(sql): preserve LOAD locality during primary-key validation - #30527
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
8dae998 to
b0c5ee7
Compare
|
mo-bot review · Commit: Review completed. Read the assessment. |
|
mo-bot review · Commit: "interrupted" |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: b0c5ee7a6854988cd28b609570bc4b394c577536
Assessment: request_changes
Reviewed the complete five-file delta and affected callers. Sharing the prepared image appropriately separates validation from writer partitioning and reuses existing rollback ownership. Functional and race tests pass, but a confirmed optimizer-orientation mismatch disables lock promotion for eligible LOADs.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1
- P2
pkg/sql/compile/load_unique_index_promotion.go:453: A promotion-eligible ordinary LOAD with unique indexes selects RIGHT DEDUP because the incoming stream exceeds the existing target and its key map fits the memory budget.
Impact: The optimizer swaps DEDUP's children, placing the shared input at child 0. This check requires it at child 1, so promotion silently becomes ineligible. Such LOADs retain per-batch unique-key encoding, sorting, submission and lock coarsening that promotion previously avoided. Resolve incoming/target sides using IsRightJoin and cover both orientations.
Evidence: A retained white-box probe executed determineBuildAndProbeSide, disableMemoryUnsafeRightDedup and swapJoinChildren with a 1 GiB estimated input and 100 target rows, confirming the legal swapped orientation. The shared-image right-sided admission assertion failed; left-sided and original single-writer right-sided controls passed. See right-dedup-probe.log and checks/1792384600955847084-3.json in the attempt directory.
Validation:
-
Preflight, exact-head native build and native-provenance verification passed; assigned source remained unchanged.
-
Nine focused planner/compiler/public LOAD tests passed, including 92 test/subtest results: focused.log, receipt 1792384355932554901-3.json.
-
TestLoadRejectsDuplicatePrimaryKeys passed under -race with matrixone_test: load-race.log, receipt 1792384604377016234-3.json.
-
Diagnostic overlay reproduced the admission regression with passing controls; production source was unchanged.
-
Commands, source fingerprints, exits and log contents were reconciled. Full evidence: /home/xupeng/.local/state/mo-bot/jobs/1d96822314a1a1bebd70f87a/attempt-1/review-evidence.json.
Limitations:
-
The reproduction establishes lost promotion eligibility, not a measured latency regression.
-
Author-reported layout gains and large-scale TPCC/multi-CN throughput were not independently reproduced. Shared-image fanout adds copying and coordinator traffic; validation carries only keys.
-
Frozen evidence reports successful exact-head CI, but supplies no raw CI logs or standalone linked-issue body.
aptend
left a comment
There was a problem hiding this comment.
Deep review of exact head 4bc10ff451448ac2515f040c6fc758b4339a74b7, actual base/merge-base def799e1260dd547cae2e0e54323ea20ec1b7685. Read the complete five-file diff, previous review and latest orientation-fix increment, all discussion and issue #30520. No remaining blocking finding identified.
The earlier RIGHT DEDUP admission defect is closed: logical input/target roles are resolved with IsRightJoin, while malformed identities, sources, cycles and mismatched orientation metadata fail admission. Both orientations retain copied canonical lock targets. This is a focused routing fix using existing sink/scan, DEDUP, writer and transaction owners, not a new lifecycle abstraction; the ordinary-fix design exemption applies.
I traced the shared prepared/locked image through both executable primary branches, source-step index resolution, receiver registration/fanout, validation drain and statement-wide cancellation/wait before commit. The target reader retains the statement's frozen workspace offset, so concurrent writes from this LOAD are not incorrectly read back as pre-existing conflicts. IGNORE/REPLACE, fake-PK, foreign-key fallback and index/check behavior retain their established owners.
Fresh native evidence: complete planner/compiler normal and race suites passed; public TestLoadRejectsDuplicatePrimaryKeys normal/race plus four race repetitions (T=6.8s => N=4); six individually measured admission/orientation/cancellation/lifecycle/proof race roots, N=100 each. My additional native SQL/race probe confirmed NEXTVAL defaults execute exactly once per source row, writer CHECK failure rolls back all new rows, and a later LOAD succeeds. All runs terminated successfully; temporary probes are removed afterward.
| Unhappy-path question | Verified closure |
|---|---|
| Q1 — ownership | One evaluated image; existing bounded fanout/spool borrowers and canonical transaction/lock owners. |
| Q2 — failure/liveness | Independent validator is a required executable step; duplicate or CHECK failure cancels/drains sibling scopes before statement completion, rollback and reuse pass. |
| Q3 — bounds/reuse | Exact three-step topology, bounded two-consumer fanout, existing key shuffle/spill; invalid graph rejected and promotion proof/lifecycle remain scoped. |
Limits: ALL CI39210251557 is still running at the latest check, not counted as green. I did not independently reproduce the author-reported 400k-row layout measurements, two-CN forced-spill experiment or original fixed-config 1000W/1000T benchmark. This approval does not certify TPCC throughput recovery; that qualification remains outstanding.
|
mo-bot review · Commit: Review completed. Read the assessment. |
|
mo-bot review · Commit: Review belongs to an older commit; it is not a review of the current head. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 4bc10ff451448ac2515f040c6fc758b4339a74b7
Assessment: approve
Reviewed the complete five-file delta and surrounding execution, cleanup, and transaction owners. The shared prepared image cleanly separates PK validation from writer partitioning while retaining existing cancellation and rollback mechanisms. RIGHT DEDUP admission is corrected. No actionable findings remain.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1
Validation:
-
Full planner and compiler suites passed normally and under the race detector. Public LOAD duplicate/rollback tests passed normally, under race, and in four repeated race runs.
-
Diagnostic SQL verified volatile-default single evaluation, CHECK-error rollback, index cleanup, connection reuse, and rejection after 400,000 valid rows.
-
Matched base/head probes reduced objects and scanned blocks from four to one, and range-read volume from 535.09 KiB to 128.49 KiB. Single-sample LOAD times were 336 ms and 346 ms; these do not establish a throughput trend.
-
The candidate passed forced-spill execution with 9,776,384 spill bytes and retained correct late-duplicate rollback. Base topology regressions failed as intended. An initial base-only spill-cap failure was superseded by a successful matched-cap comparison.
-
Verified clean frozen source, native provenance, commands, exit receipts, and retained logs. Correlations are recorded in /home/xupeng/.local/state/mo-bot/jobs/4340d6bb55d4f0b873d13009/attempt-1/validation-summary.json.
Limitations:
-
Full-scale TPCC throughput and remote-CN spill execution were not independently reproduced; the measured locality probe exercised local four-way shuffle.
-
Separate linked-issue text and raw author/CI artifacts were not supplied. Their assertions were distinguished from independently executed validation.
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
aunjgr
left a comment
There was a problem hiding this comment.
Reviewed 4bc10ff independently. No blocking finding.
The shared prepared/locked image keeps volatile and auto-increment evaluation single-owned, while the independent FAIL DEDUP step can retain its hash/shuffle/spill layout without feeding that layout into bulk writers. Validation remains executable and all DML steps must succeed before commit. I also traced promotion admission across SourceStep edges and both physical DEDUP orientations; malformed/cyclic/foreign-source shapes fail closed.
Reviewed the structural and public rollback/index/single-evaluation regressions and reused passing exact-head CI and the documented two-CN evidence. The bounded object/block-read comparison supports the locality change; it is not a claim that the original large TPCC throughput benchmark has been rerun. No new local service run is claimed.
…0637) Join-spill appends can make XFS speculatively allocate beyond EOF. Disk admission tracks logical payload bytes, so automatic capacity refresh can mistake that extra allocation for outside disk consumption, shrink the active cap to current usage, and reject the next write. Preextend the file to the admitted append end before writing, through a shared helper used by both initial hashbuild spill and probe/repartition bucket writes. Keep disk admission before extension and retain file/reservation ownership through terminal cleanup on errors. Budget policy, primary-key validation, and spill record format remain unchanged. ### Validation - Owning packages: `spillio`, `hashbuild`, and `spillutil` passed through `mo-cgo-test`. - Current-main SQL: `TestLoadRejectsDuplicatePrimaryKeys` and `TestHashBuildSharedBudgetRecoverySQL` passed. - Added roundtrip/error, rejected-growth preservation, and cleanup tests. `TestWritePreextendedXFSAllocation` ran and passed on real Linux/XFS; it explicitly skips other filesystems. - Formatting, focused `go vet`, incremental `golangci-lint`, and diff checks passed. - [Real-XFS reproduction and evidence](#30544 (comment)): 400,000 unique composite-key rows, automatic spill budgeting, private XFS LOCAL storage, and real concurrent SQL capacity refresh. With identical input/settings, original code failed with `requested=117712, used=115348584, limit=115348584` and rolled back; patched code imported all rows with correct checksums and complete disk/FD/file cleanup. Patched peak logical/allocated bytes were 176,386,048 / 176,664,576. The causal SQL before/after used issue revision `65bcea5d` to retain its original full-row LOAD plan. The affected production writer/native sources are identical at PR base `309f618995`; current-main public regressions were tested separately because #30527 changed LOAD planning. This does not claim a replay of the original TPCH1000 run or an adjacent-commit bisect of #30421. ### Performance A bounded 64 KiB append microbenchmark measured median 29.35 µs before versus 32.87 µs after (~12% per-append overhead for the extra operations). Two complete SQL comparisons with enough disk space for both versions measured 1.593/1.418 s before versus 1.304/1.460 s after. No SQL slowdown was observed at this scale; large-scale throughput remains unmeasured. Approved by: @XuPeng-SH, @aptend, @aunjgr
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #30520
What this PR does / why we need it:
Ordinary LOAD's primary-key DEDUP sends its hash-partitioned output directly to bulk writers. An ordered import consequently produces overlapping key ranges, increasing the blocks read by subsequent OLTP range queries. This affects transactions after LOAD, independently of the COS boundary-reader Close cost tracked in #30511.
Share the prepared, locked row image once. An independent, key-only DEDUP step retains exact input/snapshot conflict checks, while base/index writers consume the original image. All steps must complete before statement commit; duplicate errors still cancel and roll back writes. This preserves #30411 correctness, generated/autoincrement values, and existing LOAD exemptions without adding a global sort or disabling shuffle/spill.
Validation on macOS arm64 / Go 1.27.1:
def799e126. The compiler admission tests cover the real planner topology, shared-image source resolution, and malformed/cyclic graph rejection. The new structural regression fails on the base for scalar, composite and indexed real PKs; IGNORE/REPLACE and exemptions remain covered.IsRightJoin, preserving eligibility after the optimizer swaps RIGHT DEDUP children. Both orientations retain identical copied lock targets and reject malformed source/identity/orientation metadata; real optimizer-pass tests cover a 1 GiB estimated stream against 100 target rows, including memory-budget fallback.matrixone_testtag.The side branch adds existing sink fanout but reduces validation to PK data instead of carrying full payloads through DEDUP. The compiler recognizes the bounded shared-image topology so eligible LOADs retain existing unique-index lock promotion; malformed cross-step sources and unrelated branches remain ineligible. No persistence/wire format changes. The original fixed-config 1000W/1000T test has not been rerun: both benchmark slots on 129 were occupied. Its throughput recovery and upstream CI remain to be verified. Design and final review use gpt-6-astra with medium reasoning.