Skip to content

perf(scan): apply complete local key domains before shuffle and probing - #32098

Merged
mergify[bot] merged 29 commits into
matrixorigin:mainfrom
aunjgr:perf/local-shuffle-filter
Nov 10, 2026
Merged

mergify[bot] merged 29 commits into
matrixorigin:mainfrom
aunjgr:perf/local-shuffle-filter

Conversation

@aunjgr

@aunjgr aunjgr commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

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 #30844. Part of #32379.

What this PR does / why we need it:

Reject impossible integer-key rows in eligible unfiltered local scans before payload routing and hash probing. Collect a complete necessary domain from an independent filtered primary-key scan and propagate it through proven INNER-join equality lineage, including a component of a composite join. Existing row/block/runtime-filtered readers keep their current path; composing membership before their predicates belongs to the separate reader integration. Keep the exact join, SQL types, join order, estimates and placement unchanged.

Use one query-generation-owned Bloom filter per domain, sized from its estimate and admitted with all producer/probe scratch under the execution budget and a combined 64 MiB query cap. Publish immutable membership only after every actual source worker completes. Each target retains the strict 10% build-cardinality/probe-NDV gate, using completed source keys; stop optional construction early with PASS when every target is already unprofitable. Unknown hints, unsupported topology, partial construction and optional admission failure use ordinary execution; genuine query errors retain their outcome.

Apply completed membership in TableScan with reusable scratch and ordinary NULL/constant semantics. Preserve existing join-map readiness, cancellation and scope ownership. Remap optional annotations through the optimizer's final node compaction using node identity, then independently revalidate them before binding to actual scans. Keep unproven computed projections on ordinary execution and remove the superseded private-per-producer shuffle hook.

Design

Approved early-domain design and completed-cardinality amendment. The separate dictionary foundation is #32394; this implementation enables no dictionary producers and does not depend on it.

Current consumer-cost boundary and final-compaction implementation notes are versioned in the implementation design.

Validation

Owning planner/compiler, Bloom/runtime-domain and TableScan tests, focused lifecycle race stress, and a self-contained SQL BVT cover lineage, final node renumbering, duplicate/NULL/constant/empty keys, unsafe boundaries, independent source fanout, partial preparation, cost/budget fallback and cleanup. Live activation/work diagnostics and all benchmark evidence are appended in the conversation.

Performance acceptance

The replacement passes the declared source-pinned SF10 acceptance and SF100 acceptance: a confirmed Q9 memory-profile wall-time benefit at both scales, with no confirmed Q1–Q22 or Total regression in either memory/disk profile. Five independent process pairs per profile, cold full suites excluded, Holm query checks and a separate Total check. Any SF100 spill invalidates the run. Benchmark scripts execute/drain and collect resources without data/schema/row/result verification. Historical variants and their former acceptance rules remain in comments; they do not qualify this replacement.

aunjgr commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged authoritative main and resolved the add/add design-document conflict in 7e27b80021, then clarified that the design's Q10 regression rationale describes earlier variants (8c6bf4601c). Production files are byte-for-byte unchanged from the accepted SF10 candidate db399919ca; its source-pinned measurements remain applicable. Full required pre-push static checks pass with 0 issues; no redundant SQL/benchmark rerun was added for the documentation conflict.

The previous failed Compose jobs stopped during HTTP504 dependency downloads (including Java setup), and coverage aggregation was blocked by missing producer profiles. Fresh CI is running on the new head; this is not a CI-green claim. SF100 acceptance remains outstanding.

Superseded benchmark-table comments are now collapsed as outdated. The latest complete SF10 result remains visible: #32098 (comment)

This comment has been minimized.

@aunjgr
aunjgr marked this pull request as ready for review November 9, 2026 09:12
@aunjgr
aunjgr requested a review from LeftHandCold as a code owner November 9, 2026 09:12
@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 →

@XuPeng-SH

XuPeng-SH commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 8c6bf4601c282f8a3b36be07f90a2ae4c042477c

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: 8c6bf4601c282f8a3b36be07f90a2ae4c042477c

Assessment: approve

The bounded domain owner is justified by early scan rejection and reuses existing lineage, Bloom and selection paths. Source-matched Q9 gains address the earlier performance objection. No actionable findings remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

Validation:

  • Reviewed all 24 changed files and affected owners; reconciled all 13 discussion keys and both linked issues. Source remains unchanged. Records: discussion-assessment.json, closure-assessment.md, final-evidence-audit.log.

  • Focused normal tests passed in five packages, including all 14 new top-level tests: focused-tests.jsonl; checks/1794224787630981162-2.json.

  • Race checks passed: 100 exact ConcurrentSources repetitions and all 73 top-level tests across Bloom, runtimefilter and table_scan. Logs and matching receipts are indexed in validation-ledger.json.

  • Private-runtime preflight passed. Recovered Go 1.27.1 and built native prerequisites; native-evidence.json verifies 196 input and seven output hashes. Generated descriptor audit confirms only additive Query field 23 and two messages.

  • SF10 candidate/control executable trees match the measured revisions; SF100 pins this exact head/base. Reused supplied five-pair RAM/disk results, all-query/Total checks and completed successful CI evidence.

Limitations:

  • SQL/BVT and TPC-H were not rerun locally. SF100 Q17 has a positive raw RAM interval, without a Holm-confirmed regression under the agreed acceptance rule.

  • Duplicate CI runs remain pending in the snapshot. One unrelated planner interval-expression subtest was skipped and received no validation credit.

aunjgr commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Report-label correction: the earlier generated report mistakenly said that SF1000 qualification remained required. The approved gate here is SF10/SF100, and both are complete. All measurements, intervals and acceptance decisions are unchanged. The earlier table comment is superseded by this corrected copy.

SF100 acceptance for the unfiltered-probe revision: PASS for these source pins.

Main e2459cc55f4b514893e19732743460bc5f16d552; early-filter 8c6bf4601c282f8a3b36be07f90a2ae4c042477c. Both controls use the same native build profile on server129, all64 logical CPUs, original DECIMAL(15,2), five independent process pairs per mode. The cold full22 suite is excluded on every startup. The memory profile uses ordinary native backing with128GiB MO cache/200GiB application budget and requires zero scored physical reads; disk uses16GiB cache/96GiB budget. Aggregation/join spill thresholds are64GiB. No accepted run spilled, swapped or suffered an OOM.

This campaign uses the requester-approved process CPU guard: host user/nice/system/steal minus application CPU, with the unchanged2-core ceiling; IRQ/softIRQ and the old combined counter remain recorded separately. Prior exclusions were preserved. These are fresh matching arms; no failed earlier run was reclassified. Only193,408 bytes of compressed measurement metadata were fetched; the loaded SF100 database stayed on server129.

The declared gate requires a confirmed Q9 memory benefit plus no confirmed Q1–Q22/Total regression in either profile. The matching SF10 qualification is in the SF10 result comment. Benchmark tables are kept out of the PR description.

Early complete-domain screen: PASS. SF100 qualification complete; SF10 is reported separately.

Five independent process pairs per mode, one excluded cold full suite and one scored warm full suite per startup. All Q1–Q22 are executed/drained. Times below are paired sample means; Total is the sum of per-query wall/CPU times. Raw paired 95% intervals and Holm query tests are retained. No data/result verification.

Cache-resident native backing (zero scored physical reads) SF100

Query Main wall (s) Early-filter wall (s) Paired wall change Raw 95% interval Main CPU (s) Early-filter CPU (s) Holm slowdown
Q1 2.758145 2.666109 -3.32% [-4.90%, -1.72%] 161.114773 160.028719 none
Q2 0.340442 0.302896 -10.68% [-23.42%, +4.17%] 10.124701 9.890664 none
Q3 1.739512 1.639788 -5.61% [-12.28%, +1.58%] 63.656760 62.430803 none
Q4 0.878780 0.860852 -2.04% [-6.52%, +2.66%] 42.601371 42.477495 none
Q5 1.209328 1.189780 -1.58% [-12.98%, +11.31%] 52.797868 53.200557 none
Q6 0.288810 0.287153 -1.32% [-26.28%, +32.11%] 13.898922 14.504255 none
Q7 1.170692 1.070712 -8.26% [-22.73%, +8.93%] 52.120293 49.372128 none
Q8 1.852006 1.849684 -0.17% [-23.56%, +30.36%] 51.375927 52.549105 none
Q9 6.642630 4.286794 -35.45% [-37.53%, -33.31%] 287.932423 170.385294 none
Q10 3.370035 3.377964 +0.23% [-2.03%, +2.55%] 118.477294 119.264108 none
Q11 0.297860 0.292580 -1.83% [-14.64%, +12.90%] 12.940830 12.838892 none
Q12 1.038545 1.044928 +0.51% [-12.19%, +15.05%] 54.780939 53.954205 none
Q13 2.477885 2.540621 +2.51% [-7.91%, +14.10%] 129.880501 131.895300 none
Q14 1.313349 1.329008 +1.38% [-7.61%, +11.25%] 35.412721 35.542040 none
Q15 2.745898 2.801541 +2.20% [-7.11%, +12.44%] 67.083389 68.902241 none
Q16 2.124301 2.290383 +8.25% [-5.30%, +23.73%] 37.926439 37.148304 none
Q17 1.082994 1.198713 +10.64% [+1.58%, +20.50%] 47.681932 49.193082 none
Q18 8.666402 8.668384 +0.08% [-3.95%, +4.28%] 161.315633 163.314792 none
Q19 1.610075 1.632726 +1.46% [-3.66%, +6.86%] 76.903612 76.536748 none
Q20 3.880617 3.808564 -1.84% [-4.28%, +0.66%] 117.718979 116.690529 none
Q21 4.786138 4.743471 -0.88% [-5.92%, +4.42%] 223.830900 223.338909 none
Q22 0.642659 0.639037 -0.54% [-3.18%, +2.17%] 30.300154 30.249093 none
Total (sum Q1–Q22) 50.917101 48.521686 -4.68% [-7.26%, -2.03%] 1849.876361 1733.707263 separate Total gate

Disk-backed warm SF100

Query Main wall (s) Early-filter wall (s) Paired wall change Raw 95% interval Main CPU (s) Early-filter CPU (s) Holm slowdown
Q1 5.064230 5.036837 -0.54% [-1.45%, +0.37%] 265.125660 265.052004 none
Q2 0.318671 0.318820 +0.06% [-4.69%, +5.05%] 11.709474 11.642210 none
Q3 2.447685 2.433513 -0.59% [-3.35%, +2.25%] 94.820075 94.876901 none
Q4 1.829129 1.836397 +0.35% [-6.58%, +7.80%] 66.546242 66.769099 none
Q5 2.222906 2.283921 +2.69% [-5.82%, +11.97%] 76.273495 77.131075 none
Q6 1.241368 1.238709 -0.21% [-1.35%, +0.94%] 30.183703 29.822245 none
Q7 2.314366 2.305398 -0.39% [-1.97%, +1.22%] 83.007576 83.553527 none
Q8 3.168594 3.180552 +0.38% [-5.64%, +6.77%] 82.226598 81.887068 none
Q9 8.016496 5.947189 -25.82% [-28.81%, -22.71%] 331.841824 223.946404 none
Q10 4.738784 4.734651 -0.09% [-4.80%, +4.85%] 168.306711 168.309788 none
Q11 0.345017 0.339630 -1.57% [-5.38%, +2.39%] 13.981789 13.724262 none
Q12 2.619683 2.597922 -0.83% [-2.51%, +0.88%] 111.177818 110.744877 none
Q13 2.825004 2.820863 -0.14% [-2.03%, +1.78%] 153.262381 152.427808 none
Q14 1.810355 1.803238 -0.38% [-3.25%, +2.57%] 53.252722 54.446032 none
Q15 3.328431 3.322680 -0.17% [-1.24%, +0.91%] 93.273321 93.350847 none
Q16 1.895202 1.831209 -3.26% [-11.17%, +5.36%] 36.398094 36.680223 none
Q17 2.269862 2.307425 +1.63% [-7.26%, +11.38%] 65.649103 65.759108 none
Q18 8.583105 8.771728 +2.20% [-3.78%, +8.56%] 196.431679 202.117775 none
Q19 4.065629 4.135026 +1.69% [-5.44%, +9.36%] 166.541116 167.084657 none
Q20 4.177636 4.112245 -1.57% [-4.24%, +1.17%] 132.890488 132.377654 none
Q21 7.005399 7.102732 +1.38% [-4.56%, +7.69%] 269.016251 269.475698 none
Q22 0.684696 0.702921 +2.64% [-0.18%, +5.55%] 31.191999 32.204925 none
Total (sum Q1–Q22) 70.972248 69.163607 -2.55% [-6.00%, +1.01%] 2533.108118 2433.384187 separate Total gate

CI passes and this PR is ready for review.

aunjgr commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Resolved the main conflict and pushed 98084d16ea37ee7de371241caa07876c561389a1 using normal merges. The conflict was adjacent imports in pkg/sql/compile/types.go; both main's productl2 import and this PR's runtimefilter import are retained. Latest main 22a02c581f is included.

Focused local-domain compiler/planner tests pass, and the mandatory full pre-push static gate passes with zero issues. The domain producer, probe, binder and planner implementation files are unchanged from the qualified 8c6bf4601c revision, so the existing source-pinned SF10/SF100 evidence remains applicable. Fresh CI is required for this merge head.

aunjgr commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@fengttt Your November 5 review was against eba414b4af, the shuffle-only implementation. Those measurements did not establish a useful optimization. The PR has since replaced that implementation with early scan-stage rejection and qualified the replacement separately.

The current evidence shows a Q9 latency reduction in all four measured profiles and a confirmed SF100 memory-profile improvement in the full Q1–Q22 total:

Profile Query Main mean wall (s) PR mean wall (s) Paired wall change [raw 95% CI]
SF10 memory Q9 0.2467 0.2199 −10.81% [−15.36%, −6.02%]
SF10 memory Total 2.8598 2.8466 −0.46% [−1.73%, +0.82%]
SF10 disk Q9 0.2524 0.2228 −11.71% [−16.77%, −6.34%]
SF10 disk Total 2.8878 2.8445 −1.50% [−3.52%, +0.56%]
SF100 memory Q9 6.6426 4.2868 −35.45% [−37.53%, −33.31%]
SF100 memory Total 50.9171 48.5217 −4.68% [−7.26%, −2.03%]
SF100 disk Q9 8.0165 5.9472 −25.82% [−28.81%, −22.71%]
SF100 disk Total 70.9722 69.1636 −2.55% [−6.00%, +1.01%]

Total is the sum of Q1–Q22 query wall times. Percentages and intervals use the paired analysis, rather than ratios of rounded means. Full per-query wall/CPU tables and protocols: SF10, SF100.

There is a concrete reduction in work behind these results. Q9's filtered PART keys are a necessary condition for both PARTSUPP.ps_partkey and LINEITEM.l_partkey, including the part-key component of the latter's composite join. The PR collects that domain from the already-required filtered PART scan, waits for complete source membership, and applies a single Bloom filter to eligible unfiltered scan output before payload routing, shuffle and hash probing. Exact joins and their order remain in place.

Separate, unscored SF10 work diagnostics for the qualified revision show 108,782 source keys with all 32 source workers completed, followed by:

  • PARTSUPP: 7,564,428 of 8,000,000 rows rejected before downstream work.
  • LINEITEM: 56,721,239 of 59,986,052 rows rejected before downstream work.

That removes about 94.56% of those input rows from the downstream stages. Initial scan/decode work remains; the saving comes from handling fewer payload rows and performing fewer downstream probes. The measured SF100 Q9 CPU time also falls: 287.93 → 170.39 CPU-seconds in memory (−40.82%) and 331.84 → 223.95 CPU-seconds on disk (−32.51%), summed across application workers.

The aggregate result is consistent with this mechanism: in SF100 memory, Q9 saves 2.356 mean wall seconds, while the entire suite saves 2.395 seconds. Q9 accounts for almost all of the observed suite improvement. The other three Total intervals include zero, so those profiles support a Q9 improvement rather than a confirmed suite-wide gain.

The profitability restriction matters. Earlier eager-filter experiments improved Q9 but regressed Q10; those variants were rejected and their tables are collapsed as historical evidence. The current rule applies only to scans without existing row/block/runtime filters, so it avoids adding post-reader membership work to already-filtered inputs. Current Q10 diagnostics show no optional domain activity. This is a structural rule, with no query-name special case. Admission also retains the 10% completed-source/probe-NDV threshold and a combined 64 MiB query cap; the SF10 diagnostic used approximately a 1 MiB native filter and 5.52 MiB admitted peak.

Each case compared this PR alone with its matching main, using five independent process pairs per profile and excluding each process's complete cold suite. Resource settings match within each pair. Accepted runs have no spill/swap/OOM; SF100 memory scores require zero physical reads. All 22 queries are included in the previously agreed Holm slowdown screen, with a separate Total gate.

One caveat remains visible: SF100 memory Q17 is 1.0830 → 1.1987 s, with paired +10.64% and raw 95% CI [+1.58%, +20.50%]. Its Holm-adjusted p-value is 0.333, so it does not trigger the declared regression gate. Its cause is unresolved; I am retaining that signal explicitly rather than treating it as proven noise.

The measured source pins are db399919ca versus 70952cb466 for SF10, and 8c6bf4601c versus e2459cc55f for SF100. Current head 98084d16ea merges newer main and resolves imports; its domain builder/probe/binder/planner implementation is unchanged. This comment summarizes the existing qualified runs, not a new timing of that merge-head binary.

The supported optimization claim is therefore specific: materially lower Q9 wall and CPU cost, plus lower SF100 memory-suite wall time, with the full-suite checks and residual Q17 signal exposed for review.

@XuPeng-SH

XuPeng-SH commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 98084d16ea37ee7de371241caa07876c561389a1

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: 98084d16ea37ee7de371241caa07876c561389a1

Assessment: approve

The bounded completion owner enables early scan rejection while reusing existing lineage, Bloom, selection and resource-budget mechanisms. Qualified Q9 gains address the objection to the superseded shuffle-only implementation. No actionable findings remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed all 24 changed files and affected owners; reconciled all 18 discussion keys. Source remains unchanged.

  • All 14 new focused tests passed. Full normal runs passed in all six owning packages.

  • Race checks passed: all 73 shared-owner tests and 100 repetitions of each of nine lifecycle/concurrency tests.

  • Private-runtime preflight passed; 196 native inputs and seven output hashes verified. Generated-code audit confirmed additive Query field 23 and two messages.

  • Reused supplied current-head CI results and pinned SF10/SF100 qualification after source comparison. Receipts and retained logs reconcile in validation-ledger.json and final-evidence-audit.log.

Limitations:

  • SQL/BVT and TPC-H were not rerun locally. Benchmark numbers remain tied to their reported revisions; later common-main changes, including decimal aggregation, were reviewed without fresh timing claims.

  • SF100 Q17 retains an unresolved positive raw memory interval, without a Holm-confirmed regression under the agreed rule (adjusted p=.333). Two unrelated planner subtests were skipped and receive no validation credit.

@fengttt fengttt 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.

Are you saying this "optimization" actually makes the query SLOWER? At least for SF10, warm cache (which is the typical case).

Nevermind, seems I read the sign wrong.

@XuPeng-SH

XuPeng-SH commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 98084d16ea37ee7de371241caa07876c561389a1

"interrupted"

@mergify

mergify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as de2790b at 01:16 UTC

1 h 13 min in the queue, 1 h 12 min of it CI.

So far

  • ✅ Entered the queue Tue 10 Nov, 00:03 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Passed · in place
  • ✅ Merged 01:16 · de2790b · 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 — cca25da9 Deployed Nov 10, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement kind/feature size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants