Repository navigation
perf(top): prune dominated rows in verified reverse-ordered batches - #31847
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? |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: bec800ab33f02ce12fa0e19f090da3b7816bc142
Assessment: approve
The pruning proof preserves Top correctness across fixed, resident and spill paths. No actionable defects remain; the documented fallback cost is acceptable against the measured gains.
Model: gpt-6-astra / xhigh
Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2
Validation:
-
Full Top suite passed: 60 tests and 50 subcases, without failures or skips.
-
Package vet and changed-file formatting checks passed.
-
Exact-base/candidate benchmarks passed independent row oracles across 40 combinations; targeted workloads improved approximately 6–16×.
-
A bounded eight-control rerun measured 6–11% overhead for constructed late-inversion inputs.
-
Source, native provenance, discussion coverage, receipts and logs reconciled in /home/xupeng/.local/state/mo-bot/jobs/8c948360bf8b7d5f5d1e3369/attempt-1/validation-summary.json.
Limitations:
-
Remote CI remains pending.
-
Performance measurements are operator-level results on a shared host; universal speedup is not claimed.
-
Author-reported public two-CN SQL, race and lint results were not independently verified.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #31803
What this PR does / why we need it:
Small Top-N over input ordered opposite to the requested keys repeatedly copies temporary winners and fixes the heap. On 200k composite-primary-key rows this makes DESC LIMIT and shallow OFFSET much slower than ASC. Both directions already use a bounded Top heap; the defect is input-order-sensitive replacement cost, not a missing DESC heap orientation. Deep offsets use a different Order pipeline.
Before processing a batch, Top can now prove that its keys are reverse ordered under the complete ORDER comparator. Each omitted prefix row is then dominated by at least K rows in that batch, so only the final K rows need enter the existing fixed-width, bounded-resident or spill path. K already includes OFFSET. All input batches and order expressions are still consumed; this is not early scan termination.
A cheap same-batch progress check avoids speculative full verification on common tie plateaus. It only selects fallback, and every actual prefix omission still requires full adjacent verification. Constant, array and JSON order keys retain ordinary processing: constant comparator binding expands vectors, while array/JSON comparison does not provide the transitivity required by this proof for every value. Cancellation checks remain bounded. No candidate cache, persistent state, planner, wire, format or configuration change is added. Equal-key ties retain SQL's existing unspecified ordering. Existing JSON comparator nontransitivity is not fixed by this PR. Some nonmonotone inputs can still incur an extra verification pass; no universal speedup is claimed.
Validation:
Design and independent final review: actual gpt-6.1-terra/max. Validated commit:
bec800ab33f02ce12fa0e19f090da3b7816bc142. CI will run after publication; pending or skipped checks are not passes.