Skip to content

perf(sql): bound local set/window parallelism and batch hash-join projection - #31998

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
aptend:perf/bounded-local-execution-20261102
Nov 2, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
aptend:perf/bounded-local-execution-20261102

Conversation

@aptend

@aptend aptend commented Nov 2, 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 #26768.

What this PR does / why we need it:

Remove serial execution bottlenecks in eligible local set/window stages and reduce per-row copying overhead in duplicate-key hash joins. This PR contains four commits; it does not change cardinality estimation, join ordering, automatic spill policy, or merge defaults.

Design review

Design addendum, revision 1 and its author design-review record cover routing invariants, bounded fanout/memory, ownership, success/error/cancel/reset cleanup, alternatives and validation. They explicitly extend the earlier analytics RFC scope for this PR; that RFC's older exclusion of parallel UNION DISTINCT is not used as approval of this change. The immutable document SHA-256 is b9918c0abe9918ecbb1f2dc7950ac541936aa3d13acb34f7c37b2e7e00cc8bf7. Author review is recorded as PASS for this bounded scope; external design/implementation review remains requested in this same PR. Design/evidence files stay outside the implementation diff.

Measured benefits

TPC-DS 1 TB, host 129: 64 logical CPUs, approximately 251 GiB RAM, one local CN, 192 GiB cgroup limit, swap disabled, automatic merge disabled for testing. Settings were unchanged between each pair: max_dop=0, agg_spill_mem=4294967296, join_spill_mem=0, sort_spill_mem=536870912, GOGC=200.

Query Optimization Control Optimized Elapsed reduction
Q75 Parallel local UNION DISTINCT 285.09 s 95.41 s 66.5%
Q51 Parallel complete-partition Window 335.55 s 190.00 s 43.4%
Q38 Parallel local INTERSECT DISTINCT 77.55 s 55.63 s 28.3%
Q87 Parallel local EXCEPT DISTINCT 92.30 s 62.97 s 31.8%
Q4 Batched fixed-width duplicate-build projection 211.29 s 205.03 s 3.0% observed

These are retained, per-feature on/off comparisons on the same data and settings (October 31–November 1), not a single full-suite comparison against today's main. Q75 and Q51 report the mean of two runs per variant; Q38, Q87 and the Q4 row report individual paired runs. All listed pairs passed output comparison; the Q4 improvement is modest.

With all four commits together, the November 1 full run completed 99/99 query files (103 statements):

  • 3,004.95 s = 50 min 04.95 s cumulative query time.
  • 3,456.76 s = 57 min 36.76 s suite wall time, including EXPLAIN, guards and launcher waits. Foreign CI overlapped part of this run, so this is not an idle-host benchmark.
  • Zero timeouts, OOM kills, budget rejections, automatic merges, or nonzero terminal resource ledgers.
  • Against the retained result corpus: 93 byte-identical outputs, four equal row multisets, and two differing only in floating-point tails (maximum absolute differences 7.11e-15 / 6.66e-16).

The 50-minute result already includes these four commits. It is not a baseline from which their individual savings should be subtracted again. Its source was defe806fe9d123285449cc8db406c85dcbc31b9a; this PR rebases the same four patches onto 87fe4e0c3ac3f9a98b308f8931fd3f8be345b076 with all four entries unchanged in git range-diff.

Implementation and safety boundaries

  1. UNION DISTINCT: hash the complete supported fixed-width equality tuple to bounded local Group owners, then concatenate their disjoint results. Physical and visible key domains must match; collisions cannot remove rows.
  2. Window: dispatch each already-complete logical partition to exactly one Window owner. Do not split partitions or change frame evaluation. Unsupported/global/Top-N window shapes retain the existing path.
  3. HashJoin: batch scattered fixed-width build rows for duplicate matches of at least eight rows. Preserve row order, NULLs, allocation admission and copied-payload ownership; unsupported metadata/representations fall back to UnionOne.
  4. INTERSECT / EXCEPT DISTINCT: route by proven identity comparison columns and retain full-key comparison and duplicate suppression in each existing membership kernel. Computed/cast keys are not used for routing; ALL semantics are unchanged.

The three new parallel compiler paths require a single coordinator-local CN, non-prepared AP execution and an explicit positive spill threshold. Worker counts respect CPU/session DOP and a 128 MiB-per-owner threshold floor; membership adds an eight-owner ceiling. UNION/Window divide the existing threshold rather than multiplying it. Membership kernels do not gain spill support: their setting only bounds fanout, and shared allocation admission remains authoritative. Automatic mode and unsupported paths retain existing behavior.

The implementation reuses existing Shuffle/Dispatch/Merge/Group/Window/set operators and cancellation protocols. Each feeder has one owner; native hash scratch is mpool-backed and freed on reset/free. Local-only routing metadata is copied on operator duplication and rejected at remote serialization. No persisted or wire-format change is introduced. Parallelism can increase exchange memory: for example Q75's observed RSS peak rose from roughly 26 to 30 GiB while staying within the unchanged limits.

Validation

  • Full short-mode tests passed for vector, HashJoin, Shuffle, Window, compile, INTERSECT, MINUS and Group. After the latest main rebase, compile, mergeorder and fileservice packages were rerun and passed; the prior compile/planner rebase checks and unchanged runtime/race evidence are retained.
  • Full race tests passed for all four modified owning packages. Focused race checks passed for the new paths and directly affected dispatch, merge, partition and window cleanup; the two new shuffle reset/admission tests also passed 100 repetitions each.
  • Selected-package molint and golangci-lint: 0 issues.
  • All 22 TPC-H 1 TB fixture plans generated successfully at the previously published head: 358 nodes, no UNION DISTINCT, INTERSECT, MINUS or Window nodes, so none selects the new parallel compiler paths. Subsequent upstream rebases add exclusive SELECT-lock authorization metadata and anonymous-file unlink error handling; these ordinary SELECT routing functions are unchanged. This is plan-path validation, not a new TPC-H runtime measurement.
  • Retained public SQL checks cover exact results, NULL/duplicate handling, spill, cancellation and post-cancel service health; the full TPC-DS run above supplies the combined scale check.

Inspectable runtime evidence, pinned revision now publishes executed UNION physical graphs, active Window/Minus stack blocks, complete paired Q75/Q51/Q38/Q87 outputs, cancellation records, terminal resource ledgers and package-test logs. A 13-check artifact revalidation binds those retained executions to the current routing implementation; source hashes and rebase differences are included. These are October 30–November 1 execution records, not a claimed fresh SQL rerun at the current head. UNION cancellation was checked at query registration; Window and EXCEPT cancellation were checked in active operator phases. Compiler graph-construction tests and multi-CN CI are not presented as proof of local parallel execution.

Raw benchmark records, fixture data, experimental planner changes and the subsequent Q23 unique-projection optimization remain outside this PR.

@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 2, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 27db8652dfa710de46c0c96d60aef84ed12e833b

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: 27db8652dfa710de46c0c96d60aef84ed12e833b

Assessment: request_changes

The new parallel execution topologies require a design review that is not established by the supplied evidence. This is a design-gate finding, not a demonstrated runtime defect.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

  • P2 pkg/sql/compile/parallel_union_distinct.go:85: The PR introduces multiple local owners for UNION DISTINCT, INTERSECT/EXCEPT and Window, changing compiler/executor ownership, concurrency and threshold allocation.
    Impact: These changes trigger the repository's mandatory design-first contract. Implementation approval cannot proceed without a reviewed design covering routing invariants, resource bounds and terminal cleanup for the new topologies.
    Evidence: .agents/skills/mo-dev/references/feature-design-review.md sections 1–2 require a versioned design and traceable review decision for these complexity triggers. The existing analytics RFC explicitly excludes new parallel UNION DISTINCT ownership at line 161; the Window hash-partition design covers the existing coordinator flow. The PR and supplied discussion identify no applicable reviewed revision. Extend an existing design with these changes, link its exact revision and record the design decision; a separate RFC is unnecessary.

Validation:

  • Read the complete 17-file delta, both discussion entries, and linked issue #26768 with its two comments. Saved review-plan.md, change-map.json and discussion-assessment.json.

  • Verified clean frozen source, patch identity, complete discussion coverage and that the design contract predates this PR. Static audit passed: checks/1793593773334668414-4.json and review-audit-final.log.

  • Inspected frozen CI metadata: 13 successful, 14 skipped and 2 neutral checks. Skipped checks were not treated as passes.

Limitations:

  • Detailed implementation validation stopped at the mandatory design gate; no local product tests were run.

  • The PR's reported race, public-SQL and performance results were not independently reproduced; local_validation is empty and supporting raw logs were not supplied.

@aptend

aptend commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the missing public design/evidence link from this review.

  • Published the design addendum, revision 1 with a traceable author design-review record, and linked both from the PR body. This supplements the earlier analytics RFC scope rather than treating its explicit exclusion as approval.
  • It covers complete-key/identity-subset routing, indivisible Window partitions, worker and resource bounds, effective owners and success/error/cancel/reset cleanup, alternatives and retained validation. The document identifies [Task]: Build a robust, resource-aware optimizer beyond TPCH-shaped workloads #26768 and this PR. Its author review is explicitly distinguished from independent/external approval.
  • Rebased onto latest main ea184ad906; new head dbbdf2e9cb. All four patches are identical in range-diff, and compile/planner package tests passed again. No execution-code edit, extra implementation commit, separate RFC PR or benchmark rerun was needed for this response.

The design can now be reviewed first and implementation review continued within this PR. The prior head's CI Required, UT, SCA, coverage and selected BVT jobs passed; skipped jobs are not counted as passes, and the rebased head will have its own CI results. Re-review is requested through GitHub's review-request API as well.

@XuPeng-SH

XuPeng-SH commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: dbbdf2e9cbfb17a939a574c72be972146e5dba52

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: dbbdf2e9cbfb17a939a574c72be972146e5dba52

Assessment: request_changes

The design addendum resolves the previous design-gate finding. Implementation review found no demonstrated runtime defect, but validation of the new parallel execution graphs remains incomplete.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

  • P2 pkg/sql/compile/parallel_partition_window_test.go:80: Single-CN, non-prepared AP execution with sufficient explicit spill thresholds selects the new parallel Window, UNION DISTINCT and membership graphs.
    Impact: The new compiler tests only construct and inspect these graphs. They do not establish runtime result preservation or cancellation/cleanup across the newly connected owners. This is a validation gap, not a demonstrated production failure.
    Evidence: The Window test at line 80, distinct_set_merge_test.go:79 and parallel_set_membership_test.go:86 never execute their constructed scopes. Component tests cover individual operators; existing SQL cases and successful multi-CN CI do not establish selection of these local branches. The reported SQL/cancellation runs have no inspectable selections or terminal logs in the supplied evidence; local_validation is empty. Under validation-evidence.md sections 2/4, provide matching records from those existing runs, or run small single-CN cases asserting parallel selection, results against serial controls, and cancellation/error cleanup. No full benchmark rerun is needed.

Validation:

  • Reviewed the complete 17-file delta, affected owners/consumers, all five discussion entries, and linked issue context.

  • Verified the pinned design addendum checksum and recorded design acceptance and discussion dispositions.

  • Inspected frozen CI: 13 successful, 14 skipped and 2 neutral checks; skipped checks were not treated as passes.

  • Static audit passed: review-audit.log and checks/1793603855878591663-5.json confirm frozen head, clean source, patch identity and complete discussion coverage.

Limitations:

  • No local product tests or benchmarks were run. Reported public-SQL, cancellation and performance results were not independently verified.

@aptend

aptend commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Published the retained execution records requested by this review in an immutable runtime-evidence bundle, also linked from the PR body.

  • UNION: executed physical plans show four Group owners versus the serial feature-off control. All six count/sum results match an independent arithmetic oracle; all 65,536 supplementary tuples were rechecked. Q75's four complete outputs match and terminal resource ledgers are zero.
  • Window: actual Q51 stacks show 8 live Window instances in the timed run and 12 at cancellation, including processOrder. All four complete outputs match. Active-computation cancellation returned ERROR 1317 in 889 ms, the four ledgers returned to zero, and subsequent SELECT 1 passed.
  • INTERSECT/EXCEPT: both original SQL outputs match their serial controls. Q87's cancellation snapshot contains 16 Minus owners and four synchronous shuffle feeders. Cancel during the build-input wait exited in 4,772 ms; 27.3 GB of active memory charges retired, all ledgers returned to zero, and health passed.

The bundle contains actual output/stack/terminal records, original artifact SHA-256s, binary/source manifests, and 13 passing artifact rechecks. It explicitly distinguishes older executions from current-head tests. The UNION cancellation was synchronized to registration, not active Group computation; the membership cancellation snapshot is EXCEPT, not a separately captured INTERSECT run. No broader phase coverage is claimed.

Rebased onto latest main 87fe4e0c3a, now head fe9736f261. All four patches are unchanged; current-head compile, mergeorder and fileservice package tests passed. Existing owning/race/lifecycle logs are now inspectable as well. No benchmark rerun, execution-strategy change, or raw fixtures/logs were added to the implementation diff. Re-review is being requested through the review-request API.

@XuPeng-SH

XuPeng-SH commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: fe9736f2617e7c70a597ca97e1c5d83fe0ba9568

Review discussion changed before publication; a fresh contextual review is queued.

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

Design review: PASS for revision 1 (SHA-256 b9918c0abe9918ecbb1f2dc7950ac541936aa3d13acb34f7c37b2e7e00cc8bf7). I independently accept the bounded local-only topology: equality owners preserve the full kernel comparison, Window partitions remain indivisible, fanout is capped, and explicit thresholds are divided rather than treated as hard reservations. Automatic, prepared, and multi-CN paths remain unchanged.

Implementation review at fe9736f: read all changed hunks and traced compiler placement, feeder/receiver ownership, whole-partition Window consumption, canonical tuple hashing, scratch cleanup, vector metadata/admission and scalar fallback. No blocking issue found. I also checked the pinned runtime-evidence index: actual branch selection and result comparison are distinguished from graph-only tests, with the cancellation and measurement limitations stated accurately. Reused the reported package/race/runtime evidence and green exact-head CI; no new local test run.

@XuPeng-SH

XuPeng-SH commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: fe9736f2617e7c70a597ca97e1c5d83fe0ba9568

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: fe9736f2617e7c70a597ca97e1c5d83fe0ba9568

Assessment: approve

The reviewed design and inspectable runtime evidence resolve the earlier findings. Full assessment of the implementation and current discussion found no actionable defects.

Model: gpt-6-astra / xhigh

Session: 01a1869d-999c-7481-b340-ae4a63e8cee4 · slot 1 · generation 2

Validation:

  • Covered all 17 changed files and ten discussion entries, reusing review coverage verified against identical source.

  • Fresh audit passed: 56 payload hashes, seven source-hash claims, six UNION results against an independent arithmetic oracle, paired result manifests and terminal samples.

  • Reused pinned runtime, cancellation, package/race and integration-test records. Frozen CI reports 13 successful, 14 skipped and two neutral checks.

  • Discussion coverage, clean source and command/source/exit/log reconciliation passed; evidence is retained in the diagnostic directory.

Limitations:

  • No new Go tests or SQL benchmarks were run; retained executions were assessed through source correspondence and artifact provenance.

  • UNION cancellation covers registration only; no separate INTERSECT cancellation capture is supplied.

  • Large supplementary tuple/frame datasets remain manifest-backed author evidence; stack and budget excerpts were not verified as complete original files.

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

mergify Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request branch update failed

36 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Mon 2 Nov, 09:23 · rule main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue 09:58 · fe9736f

Reason

The pull request can't be updated

GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/ci-scope-check.yml without workflows permission
GitHub only lets Mergify write to .github/workflows/ with the workflows permission. An organization owner can accept Mergify's pending permissions at https://dashboard.mergify.com/orgs/matrixorigin/repositories.

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added dequeued and removed queued labels Nov 2, 2026

This branch was successfully deployed

No deployments
ci — 28ecdb7a Deployed Nov 2, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants