Repository navigation
perf(objectio): bulk-copy disjoint sorted batches - #28074
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? |
LeftHandCold
left a comment
There was a problem hiding this comment.
Reviewed exact HEAD cafc61be6fd2ad62c5aaef7a43d384b16a922df8 against base ffc8d9f0625c76e87ba967984ce19db2d082b0ba. No blocking code findings.
The fast path is conservatively gated by strict, comparator-consistent range separation; equal/overlapping ranges and FLOAT/DOUBLE retain the existing k-way merge. Block splitting remains bounded by objectio.BlockMaxRows, and source batches are returned only after UnionWindow has made an independent copy. Sink/pre-extend failures preserve the existing buffer and outer cleanup ownership.
Q1 ownership: pass. Q2 waits/control: pass; no new asynchronous or unbounded wait edge. Q3 growth: pass; order/heap scratch is bounded by input batch count and output remains one block at a time.
Evidence reviewed: exact-head focused/race/consumer/build and 30M indexed/control evidence in the PR; shared CI build is green and the remaining CI jobs are still governed by branch protection. A local duplicate of the focused package test was not run because this detached worktree has no matching cgo/libmo.dylib; I did not reuse a mismatched native artifact. Distributed 100M/1B confirmation appropriately remains follow-up acceptance for #27775 rather than a correctness blocker for this general optimization.
|
Tick the box to add this pull request to the merge queue (same as
|
## Summary - detect when already-sorted input batch key ranges are strictly disjoint - concatenate those batches with bounded UnionWindow copies instead of a row-at-a-time heap merge - retain the existing k-way merge for overlapping or equal boundaries and floating-point keys - preserve sink-buffer and putBack ownership, including the existing comparator-visible row domain - avoid extra fallback allocations by reusing row-index scratch and building the heap only when required - make the general path handle all-empty batch sets without indexing a missing heap element Related to matrixorigin#27775. This PR does not close the issue; distributed 100M/1B confirmation remains the final acceptance step. ## First-principles design MergeSortBatches already requires every input batch to be sorted by the same ascending key relation. If the batches can be ordered so that every next minimum is strictly greater than the previous maximum, their sorted union is exactly their concatenation. Per-row heap comparison is then redundant. The fast path is deliberately conservative: - overlapping ranges fall back - equal range boundaries fall back so duplicate-key tie behavior remains unchanged - FLOAT and DOUBLE fall back because NaN does not define the total order needed by endpoint proof - NULL boundaries use the same NULL-first relation as the existing merge - output remains bounded by objectio.BlockMaxRows - each source is returned only after its copied data is independent of that source - failures return the current buffer and retain the existing cleanup owner There is no LOAD, index kind, schema, issue, or data-size branch. ## Performance evidence Apple M4, Go 1.26.4, 16 input batches x 8192 rows, two int64 columns: | Shape | main | PR | Allocations | |---|---:|---:|---:| | strictly disjoint | 12.95-13.81 ms | 48.48-56.06 us | 7 alloc/op on both | | fully overlapping | 15.67-15.89 ms | 15.52-16.78 ms | 7 alloc/op on both | The disjoint merge itself improves about 99.6%; the required overlap fallback has no measurable median regression. Fresh-process local 30M LOAD DATA with composite PK, secondary index, UNIQUE index, and a no-index control: | Revision/run | Indexed | Control | Ratio | |---|---:|---:|---:| | current-main baseline | 9.32 s | 2.64 s | 3.53x | | PR run 1 | 7.40 s | 2.76 s | 2.68x | | PR final run | 8.57 s | 3.05 s | 2.81x | The control-normalized remaining overhead improves about 20-24% across the two fresh PR runs. Lowering the existing 1 GiB promotion threshold was separately rejected: forcing that path at 10M was about 40% slower. ## Correctness and unhappy paths The 30M black-box run verified: - base and control counts, sums, and payload min/max match - base, hidden secondary, and hidden UNIQUE tables each contain 30M rows - forced UNIQUE point lookups at first/middle/last keys return exact rows - forced secondary range lookup returns the expected 60,030 rows Focused coverage includes: - reversed disjoint ranges and exact BlockMaxRows boundary splitting - overlapping ranges - equal boundaries - mixed/all-NULL boundaries - varlena keys - sink failure propagation and buffer ownership - all-empty floating-point/general path - putBack ordering and payload association ## Validation - .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=120s ./pkg/objectio/mergeutil - .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=240s ./pkg/objectio/mergeutil - .agents/skills/mo-dev/scripts/mo-cgo-test -run '^TestMergeSortBatches$' -count=1 -timeout=120s ./pkg/sql/colexec - .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=180s ./pkg/objectio/ioutil - go vet ./pkg/objectio/mergeutil ./pkg/objectio/ioutil with repository CGo flags - make build - fresh-process 30M indexed/control SQL validation described above
## Summary - detect when already-sorted input batch key ranges are strictly disjoint - concatenate those batches with bounded UnionWindow copies instead of a row-at-a-time heap merge - retain the existing k-way merge for overlapping or equal boundaries and floating-point keys - preserve sink-buffer and putBack ownership, including the existing comparator-visible row domain - avoid extra fallback allocations by reusing row-index scratch and building the heap only when required - make the general path handle all-empty batch sets without indexing a missing heap element Related to matrixorigin#27775. This PR does not close the issue; distributed 100M/1B confirmation remains the final acceptance step. ## First-principles design MergeSortBatches already requires every input batch to be sorted by the same ascending key relation. If the batches can be ordered so that every next minimum is strictly greater than the previous maximum, their sorted union is exactly their concatenation. Per-row heap comparison is then redundant. The fast path is deliberately conservative: - overlapping ranges fall back - equal range boundaries fall back so duplicate-key tie behavior remains unchanged - FLOAT and DOUBLE fall back because NaN does not define the total order needed by endpoint proof - NULL boundaries use the same NULL-first relation as the existing merge - output remains bounded by objectio.BlockMaxRows - each source is returned only after its copied data is independent of that source - failures return the current buffer and retain the existing cleanup owner There is no LOAD, index kind, schema, issue, or data-size branch. ## Performance evidence Apple M4, Go 1.26.4, 16 input batches x 8192 rows, two int64 columns: | Shape | main | PR | Allocations | |---|---:|---:|---:| | strictly disjoint | 12.95-13.81 ms | 48.48-56.06 us | 7 alloc/op on both | | fully overlapping | 15.67-15.89 ms | 15.52-16.78 ms | 7 alloc/op on both | The disjoint merge itself improves about 99.6%; the required overlap fallback has no measurable median regression. Fresh-process local 30M LOAD DATA with composite PK, secondary index, UNIQUE index, and a no-index control: | Revision/run | Indexed | Control | Ratio | |---|---:|---:|---:| | current-main baseline | 9.32 s | 2.64 s | 3.53x | | PR run 1 | 7.40 s | 2.76 s | 2.68x | | PR final run | 8.57 s | 3.05 s | 2.81x | The control-normalized remaining overhead improves about 20-24% across the two fresh PR runs. Lowering the existing 1 GiB promotion threshold was separately rejected: forcing that path at 10M was about 40% slower. ## Correctness and unhappy paths The 30M black-box run verified: - base and control counts, sums, and payload min/max match - base, hidden secondary, and hidden UNIQUE tables each contain 30M rows - forced UNIQUE point lookups at first/middle/last keys return exact rows - forced secondary range lookup returns the expected 60,030 rows Focused coverage includes: - reversed disjoint ranges and exact BlockMaxRows boundary splitting - overlapping ranges - equal boundaries - mixed/all-NULL boundaries - varlena keys - sink failure propagation and buffer ownership - all-empty floating-point/general path - putBack ordering and payload association ## Validation - .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=120s ./pkg/objectio/mergeutil - .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=240s ./pkg/objectio/mergeutil - .agents/skills/mo-dev/scripts/mo-cgo-test -run '^TestMergeSortBatches$' -count=1 -timeout=120s ./pkg/sql/colexec - .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=180s ./pkg/objectio/ioutil - go vet ./pkg/objectio/mergeutil ./pkg/objectio/ioutil with repository CGo flags - make build - fresh-process 30M indexed/control SQL validation described above
## Summary - detect when already-sorted input batch key ranges are strictly disjoint - concatenate those batches with bounded UnionWindow copies instead of a row-at-a-time heap merge - retain the existing k-way merge for overlapping or equal boundaries and floating-point keys - preserve sink-buffer and putBack ownership, including the existing comparator-visible row domain - avoid extra fallback allocations by reusing row-index scratch and building the heap only when required - make the general path handle all-empty batch sets without indexing a missing heap element Related to matrixorigin#27775. This PR does not close the issue; distributed 100M/1B confirmation remains the final acceptance step. ## First-principles design MergeSortBatches already requires every input batch to be sorted by the same ascending key relation. If the batches can be ordered so that every next minimum is strictly greater than the previous maximum, their sorted union is exactly their concatenation. Per-row heap comparison is then redundant. The fast path is deliberately conservative: - overlapping ranges fall back - equal range boundaries fall back so duplicate-key tie behavior remains unchanged - FLOAT and DOUBLE fall back because NaN does not define the total order needed by endpoint proof - NULL boundaries use the same NULL-first relation as the existing merge - output remains bounded by objectio.BlockMaxRows - each source is returned only after its copied data is independent of that source - failures return the current buffer and retain the existing cleanup owner There is no LOAD, index kind, schema, issue, or data-size branch. ## Performance evidence Apple M4, Go 1.26.4, 16 input batches x 8192 rows, two int64 columns: | Shape | main | PR | Allocations | |---|---:|---:|---:| | strictly disjoint | 12.95-13.81 ms | 48.48-56.06 us | 7 alloc/op on both | | fully overlapping | 15.67-15.89 ms | 15.52-16.78 ms | 7 alloc/op on both | The disjoint merge itself improves about 99.6%; the required overlap fallback has no measurable median regression. Fresh-process local 30M LOAD DATA with composite PK, secondary index, UNIQUE index, and a no-index control: | Revision/run | Indexed | Control | Ratio | |---|---:|---:|---:| | current-main baseline | 9.32 s | 2.64 s | 3.53x | | PR run 1 | 7.40 s | 2.76 s | 2.68x | | PR final run | 8.57 s | 3.05 s | 2.81x | The control-normalized remaining overhead improves about 20-24% across the two fresh PR runs. Lowering the existing 1 GiB promotion threshold was separately rejected: forcing that path at 10M was about 40% slower. ## Correctness and unhappy paths The 30M black-box run verified: - base and control counts, sums, and payload min/max match - base, hidden secondary, and hidden UNIQUE tables each contain 30M rows - forced UNIQUE point lookups at first/middle/last keys return exact rows - forced secondary range lookup returns the expected 60,030 rows Focused coverage includes: - reversed disjoint ranges and exact BlockMaxRows boundary splitting - overlapping ranges - equal boundaries - mixed/all-NULL boundaries - varlena keys - sink failure propagation and buffer ownership - all-empty floating-point/general path - putBack ordering and payload association ## Validation - .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=120s ./pkg/objectio/mergeutil - .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=240s ./pkg/objectio/mergeutil - .agents/skills/mo-dev/scripts/mo-cgo-test -run '^TestMergeSortBatches$' -count=1 -timeout=120s ./pkg/sql/colexec - .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=180s ./pkg/objectio/ioutil - go vet ./pkg/objectio/mergeutil ./pkg/objectio/ioutil with repository CGo flags - make build - fresh-process 30M indexed/control SQL validation described above
Summary
Related to #27775. This PR does not close the issue; distributed 100M/1B confirmation remains the final acceptance step.
First-principles design
MergeSortBatches already requires every input batch to be sorted by the same ascending key relation. If the batches can be ordered so that every next minimum is strictly greater than the previous maximum, their sorted union is exactly their concatenation. Per-row heap comparison is then redundant.
The fast path is deliberately conservative:
There is no LOAD, index kind, schema, issue, or data-size branch.
Performance evidence
Apple M4, Go 1.26.4, 16 input batches x 8192 rows, two int64 columns:
The disjoint merge itself improves about 99.6%; the required overlap fallback has no measurable median regression.
Fresh-process local 30M LOAD DATA with composite PK, secondary index, UNIQUE index, and a no-index control:
The control-normalized remaining overhead improves about 20-24% across the two fresh PR runs. Lowering the existing 1 GiB promotion threshold was separately rejected: forcing that path at 10M was about 40% slower.
Correctness and unhappy paths
The 30M black-box run verified:
Focused coverage includes:
Validation