Skip to content

perf(exec): reduce accounted work on short index range scans - #32895

Merged
mergify[bot] merged 7 commits into
matrixorigin:mainfrom
LeftHandCold:fix/32857-text-range-cost
Nov 19, 2026
Merged

mergify[bot] merged 7 commits into
matrixorigin:mainfrom
LeftHandCold:fix/32857-text-range-cost

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #32857.

What this PR does / why we need it:

Short text-protocol index range counts can pay for predicate validity and dictionary publication buffers that they never use. For an unmasked prefix_between with proven non-NULL inputs, reuse the existing non-null Boolean result path. NULL inputs still produce NULL. Create dictionary publication slots only when the reader returns a partial selection that can publish dictionary output. Apply-only and all-match reads avoid this setup.

Committed replay uses the existing scalar projection and allocation order. A replay iterator can traverse many invisible versions inside one call, so buffering output until after that call delays a capacity error. Bulk allocation can also admit a batch below the existing scalar replacement peak. The final change removes the replay gather and its tombstone and iterator guards.

Validation

  • A real replay iterator with two visible rows and an invisible suffix verifies admission before advancing. A 7-byte budget returns the typed capacity error after one call. A 23-byte budget denies the second row's 8+16 byte replacement after two calls. At 24 bytes the reader returns both visible rows and releases the account. The previous PR head fails the first two checks.
  • Focused tests cover non-NULL and NULL prefix predicates, publication after a partial selection, and apply-only scans.

The 100-row replay microbenchmark quantifies the cost of restoring scalar behavior relative to the superseded PR head. Median time was 8.83 µs with gathering and 11.73 µs with scalar projection. Reservations went from two back to the base reader's eight. The previous implementation's combined SQL throughput gains do not apply to the final executor-only patch. End-to-end throughput on this revision has not been measured.

Full normal and race suites passed for disttae, colexec, and table_scan on Go 1.27.1 with SIMD. Incremental formatting, vet, golangci-lint, and molint passed for the same scope.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify

mergify Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH

XuPeng-SH commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 11c4e9046b6937b26dfc7f51e85d93a445ee759b

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 11c4e9046b6937b26dfc7f51e85d93a445ee759b

Assessment: request_changes

The revised gather fixes the earlier split-batch admission regression and reuses MPool’s growth policy. The dictionary workspace and prefix predicate changes passed their targeted tests. The remaining defect is that replay buffers rows from sources already known to require scalar appends, delaying budget refusal and allowing a later tombstone error to replace it.

Model: gpt-6.2-sol / xhigh

Session: 01a1ee7f-fdcb-7b83-ad57-3b17a0e9d494 · slot 1 · generation 1

  • P2 pkg/vm/engine/disttae/local_disttae_datasource.go:1078: A fresh, accounted replay scan projects one column with out-of-line values, and its remaining budget cannot admit the first output row.
    Impact: The reader advances and checks tombstones for later rows before attempting the first scalar append. A later persisted tombstone failure can replace the typed capacity error the merge-base reader returns on the first row.
    Evidence: The source eligibility check runs at line 903, after offsets have been buffered. The paired replay control advanced 64 rows on the candidate and one with the merge-base reader. With a fault injected on the second persisted tombstone check, the candidate returned that fault and the merge-base reader returned ErrAllocationAccountCapacity. See replay-baseline-control.log, replay-candidate-control.log and the paired replay-*-tombstone.log files. Check source eligibility before buffering the first offset so ineligible sources keep immediate scalar appends.

Validation:

  • Frozen head, merge base, patch identity, clean checkout, whitespace, and isolation preflight passed. See scope.log, diff-check.log, preflight.log and their receipts under checks/.

  • The full colexec and table_scan packages passed in owning-packages.log. DistTAE passed in disttae-normal.log with receipt checks/1795022406659505817-2.json after the first run hit its 150-second package timeout. The focused split test verified a 768-byte peak for 64 values and rejected a 511-byte limit.

  • Both replay probes used the supplied test executor and the same fixture on each side. The baseline overlay substituted the merge-base reader file. The control and fault-injection receipts are checks/1795022301604795188-3.json, checks/1795022309960527596-2.json, checks/1795022390232356001-3.json and checks/1795022398091266841-2.json. All discussion entries are accounted for.

Limitations:

  • The tombstone fault was injected at the reader interface. The probe establishes error ordering under pressure and leaves production frequency unmeasured.

  • The author reports a 4.2% gain for the short Linux COM_QUERY workload. Throughput and original-scale performance were outside local validation.

@gouhongshen gouhongshen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex automated review

Completed a fresh pass at HEAD 11c4e90: reran git diff origin/main...HEAD (8 files, +334/-18), reloaded the PR reviews, inline comments and issue comments, and re-verified the analysis of all three changes. No independent blocking or non-blocking defects were found. First, the buffered replay gather in filterInMemCommittedInserts only coalesces a fresh, accounted, single ordinary column; I extracted the checkout's mpool.GrowCapacity ladder verbatim and mechanically verified across element widths 1..256 and up to 4096 rows that the parity simulation in appendInitialReplayRows always equals the capacity the real row-wise accounted append produces, and that the bulk Union is taken only when it leaves exactly that same capacity, so later growth, transient peaks and account admission decisions are identical to the row-wise baseline; the intermediate-capacity admission regression fixed by the second commit cannot recur under this guard, matching the reader-level split, peak and budget-refusal tests. Second, the prefix_between no-NULL-result proof in booleanProducesNoNulls was audited against every NULL-producing path of opBetweenBytesWithFunc and opBetweenBytesRows and the function registry (a single audited overload at index 0); NULL operands keep the normal nullable admission and partial selections keep the old path, as the new test covers. Third, delaying the dictionary publication slots into selectReaderFilter was checked against every consumer (publishReaderSelection, the inline Call selection path, the slot-restore loop and Free): apply-only, all-match, error and zero-row paths never publish, and slots exist before a partial selection returns. Per-row tombstones, minTS, BlockMaxRows accounting and hidden-physical-column alignment are all restored by the flush before the shrink phase. One existing CHANGES_REQUESTED review by XuPeng-SH reports a single P2 - buffering rows from sources that would take scalar appends delays budget refusal so a later tombstone error can replace the typed capacity error, demonstrated only under fault injection - which the author has not yet addressed; per the no-duplicate rule it is excluded from my findings, and I did not independently find a blocking problem in that path. Test limitation: none of the changed packages' focused Go tests could be built locally because this checkout lacks thirdparties/install headers (jemalloc.h, usearch.h, xxhash.h, roaring.h) produced by the documented make cgo target, which I did not build, and the tree's CGO_ENABLED=0 fallback cannot compile pkg/common/mpool because malloc.SimpleCAllocator lives in a cgo file with no cgo-disabled stub, a pre-existing main issue unrelated to this PR. As substitutes I ran the verbatim GrowCapacity parity harness (0 mismatches), audited the kernels and slot consumers statically, confirmed gofmt-cleanliness of all changed files, and noted the head's CI UT, build and e2e runs passing; no local execution of the changed packages' tests was possible.

@XuPeng-SH

XuPeng-SH commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 11c4e9046b6937b26dfc7f51e85d93a445ee759b

New discussion was assessed; the previous review remains unchanged.

@XuPeng-SH

XuPeng-SH commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 4cdf4f268c295a79b737ee95c4d5dc48d176cddc

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 4cdf4f268c295a79b737ee95c4d5dc48d176cddc

Assessment: request_changes

The new counter fixes the workspace-delete regression and preserves dense replay batching. One iterator call can still scan an entire suffix of versions newer than the snapshot before the first output allocation is attempted.

Model: gpt-6.2-sol / xhigh

Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3

  • P2 pkg/vm/engine/disttae/local_disttae_datasource.go:1047: An accounted single-column scan buffers its first visible row, the remaining budget cannot admit that row, and later replay versions are newer than the snapshot.
    Impact: The next iterator call can traverse the entire invisible suffix before returning. The deadline counts yielded rows, so the work before the capacity error grows with retained replay history.
    Evidence: With 7 bytes available for an 8-byte value, the candidate visited 131,073 versions and the merge-base reader visited one. Both returned ErrAllocationAccountCapacity. At 8 bytes, both returned the correct single row and released the account. The iterator skips newer versions inside Next at pkg/vm/engine/disttae/logtailreplay/rows_iter.go:99. Bound the iterator work while admission is pending, or admit pending output before advancing an iterator that lacks such a bound.

Validation:

  • Verified the frozen head, merge base, clean checkout, patch, formatting, and isolation preflight. See scope.log, gofmt.log, and preflight.log.

  • Nine focused tests and the full disttae, colexec, and table_scan suites passed. See focused.log and owning-packages.log, with receipts 1795044377585075472-3 and 1795044474580438031-3.

  • The maintained workspace-delete test passed on the candidate. The prior-reader overlay failed at 129 yielded rows. See prior-workspace-deletes.log and receipt 1795044423096883049-439.

  • The invisible-suffix probe failed the work-bound assertion on the candidate and passed with the merge-base reader overlay. See candidate-invisible-suffix.log and merge-base-invisible-suffix.log, with receipts 1795044409494072756-3 and 1795044416304043167-241. All 12 discussion keys are accounted for.

Limitations:

  • The paired probe counted iterator visits in a controlled reader fixture. Production latency and frequency remain unmeasured.

  • The author reports race and component performance results for the current head. The end-to-end throughput results in the frozen evidence come from earlier revisions.

@XuPeng-SH

XuPeng-SH commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 7fb22c67e430110d7f4abf71097c4af161fb80c2

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 7fb22c67e430110d7f4abf71097c4af161fb80c2

Assessment: approve

The committed replay reader matches the merge base and admits each visible row before advancing, resolving the earlier allocation and read-ahead findings. The remaining changes reuse existing Boolean storage and defer dictionary publication slots until selection, preserving NULL handling and scan ownership.

Model: gpt-6.2-sol / xhigh

Session: 01a1ee80-0d82-7030-a965-b51f496c3054 · slot 2 · generation 1

Validation:

  • Verified the frozen head, merge base, patch identity, whitespace, and unchanged production replay code. Isolation preflight passed. See source-audit.log, preflight.log, and receipts 1795049298017664031-2 and 1795049280159648515-2.

  • Focused tests passed for prefix predicate validity, reader selection, and replay admission at the 7-, 23-, and 24-byte boundaries. Reader-owner tests also passed. See focused.jsonl, reader-owners.jsonl, and receipts 1795049509030960740-2 and 1795049503789759439-2.

  • Full colexec and table_scan packages passed locally. See executor-packages.jsonl and receipt 1795049526265266099-2. Frozen CI records successful x86 unit tests and multi-CN BVT.

  • The review plan, complete discussion ledger, logs, and receipts are in model-switch-1795049241774024032.

Limitations:

  • Reported SQL throughput measurements cover earlier revisions. End-to-end throughput on this head remains unmeasured.

@mergify mergify Bot added the queued label Nov 19, 2026
@mergify

mergify Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as ae9e665 at 02:02 UTC

1 h 9 min in the queue, 1 h 8 min of it CI.

So far

  • ✅ Entered the queue Thu 19 Nov, 00:53 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Passed · in place
  • ✅ Merged 02:02 · ae9e665 · squash
3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

This branch was previously deployed

1 inactive deployment
ci — ac820093 Deployed Nov 19, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/enhancement size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants