Skip to content

perf(sql): reduce analytical join and aggregation overhead - #31761

Merged
mergify[bot] merged 7 commits into
matrixorigin:mainfrom
aptend:perf/tpcds-30min-20261025
Oct 31, 2026
Merged

mergify[bot] merged 7 commits into
matrixorigin:mainfrom
aptend:perf/tpcds-30min-20261025

Conversation

@aptend

@aptend aptend commented Oct 29, 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:

Reduce repeated analytical join/aggregation work with general optimizations, without query-specific rules or increasing DOP.

Design: analytic-execution-v1, revision c45ec08a42. Addresses the design-amendment review; amendment approval is pending in this PR, with the design decision recorded before implementation approval.

TPC-DS 1T measurements on host 129:

Query file Main baseline (s) Optimized (s) Less time
Q14 (both statements) 476.075 84.320 82.3%
Q23 (both statements) 363.418 329.196 9.4%
Q51 442.758 341.376 22.9%
Q64 491.112 80.123 83.7%
Q67 495.040 220.983 55.4%

These five query files total 2,268.403 -> 1,055.998 seconds: 53.4% less time, saving 20 minutes 12 seconds. Outputs match retained references; Q64 passed six post-fix reference comparisons.

Measurement sources: main 553bf39dbb and retained pre-rebase integration checkpoints. Both use aggregation 4 GiB / automatic join / sort 512 MiB, automatic DOP, GOGC=200, merge OFF and a 232 GiB cgroup. These are instrumented per-query measurements.

General changes:

  • Preserve current-input HashOnPK proofs, concatenated-batch ordering metadata, final shuffle draining and set-operation spill settings.
  • Batch hash encoding, vector/join projection, grouping, COUNT, scalar MIN/MAX and NULL-ELSE CASE; use stable heap selection for supported sorted Partition merges.
  • Reduce duplicate-insensitive joins to existence checks and move proven-total expressions before fanout/fan-in. Admit deeper exact runtime filters only with proven logical dependencies and complete local publishers; otherwise remove both physical endpoints safely.

TPC-H regression validation:

  • Earlier same-machine 100G ABBA controls (Q1/3/6/9/13/21) showed no reproducible slowdown: the sum of per-query means was 97.136 -> 96.595 seconds (-0.56%).
  • TKE auto-test, source 64de090862: all 22 golden-result checks passed at both 100G and 1T; formal average times were 85.496 s / 876.094 s.

Post-rebase validation passes for all 14 affected packages and vector/hashjoin/Partition/shuffle/compiler under race.

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

Copy link
Copy Markdown
Contributor

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

Commit: 0d244477f6daa17edfc574cbfbec525018680b5e

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: 0d244477f6daa17edfc574cbfbec525018680b5e

Assessment: request_changes

The complete delta was read. A mandatory design amendment is missing for the new optimizer and execution capabilities.

Model: gpt-6-astra / xhigh

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

  • P2 pkg/sql/plan/query_builder.go:4480: The PR introduces set-membership reduction, grouping-expression motion, deep ordinary runtime filters and parallel UNION ALL projection across planner/compiler boundaries. These additions exceed the repository’s feature-design size and complexity triggers.
    Impact: Implementation approval requires a reviewed design covering their composition, evaluation-domain safety, publisher startup/completeness and resource costs. Amend the existing analytic RFC, including the RIGHT-join batching extension, and link the reviewed revision and decision from this PR.
    Evidence: .agents/skills/mo-dev/references/feature-design-review.md:22-89 requires this gate. The existing analytic RFC covers scalar runtime filters at docs/rfcs/00000000_stats_independent_analytic_plan_rewrites.md:446 and explicitly excludes outer/unmatched-output joins from batching at line 488. No amendment covering the new scope appears in the frozen delta or supplied discussion.

Validation:

  • Read all 62 changed files and supplied discussion/linked-issue context; saved review-plan.md and discussion-assessment.json.

  • Artifact/source-integrity check passed: checks/1793329162663464731-2.json, exit 0, matching review-artifact-check.log. Verified frozen head, clean source, patch equivalence, diff whitespace and complete discussion coverage.

  • Frozen CI snapshot reports successful build, unit tests, SCA and multi-CN BVT.

Limitations:

  • Downstream implementation approval and local execution testing were deferred at the mandatory design gate; no demonstrated runtime defect is claimed.

  • Author-reported performance and race results were not independently verified from retained execution logs.

Preserve distinct-set aggregation spill and key contracts; keep disabled runtime filters disabled; bound string-cast recovery reservations; invalidate stale hash-key proofs; drain stopped shuffle producers; clear inherited sorted metadata when inputs are combined.
Batch canonical CHAR and fixed-composite hash keys, streamline integer probes, copy inline varlena selections in batches, and reduce per-row selection metadata work.
Use stable heap selection for sorted partitions; batch grouping markers, join probe/finalization projections and fixed-width CASE null runs; avoid unnecessary scalar min/max scratch and saturated COUNT cache probes.
Reduce duplicate-insensitive joins to set membership after join ordering, preproject pure UNION ALL branches before fan-in, and evaluate total grouping expressions below build-side fanout.
Admit deep runtime filters only on proven local execution trees and preserve totality guards while allowing bounded text widening.
@XuPeng-SH

XuPeng-SH commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: e0369d5078b7c5b444364c76422a52e84d1a1ed7

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

Assessment: approve

Completed the 63-file review and relevant consumer traces. The design amendment resolves the previous review concern; no actionable defects or unmet required contracts remain.

Model: gpt-6-astra / xhigh

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

Validation:

  • Reviewed semantic guards, runtime-filter publication and cleanup, operator lifecycle, memory ownership, and regression-test oracles.

  • Reused frozen-head CI evidence reporting successful build, UT, SCA, coverage and multi-CN BVT checks.

  • Source/artifact audit passed: exact HEAD, clean source, complete delta coverage and all five discussion keys assessed. Receipt: checks/1793436492061726382-3.json; output: review-audit.log.

  • Saved review-plan.md, review-evidence.md and discussion-assessment.json.

Limitations:

  • No fresh local product tests or benchmarks were run.

  • Raw CI and author validation logs were unavailable; author-reported race tests and historical performance results were not independently reproduced.

  • Skipped CI jobs were not counted as passes.

@mergify mergify Bot added the queued label Oct 31, 2026
@mergify

mergify Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as 6e5f2ce at 09:30 UTC

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

So far

  • ✅ Entered the queue Sat 31 Oct, 08:49 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged 09:30 · 6e5f2ce · 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

@mergify
mergify Bot merged commit 6e5f2ce into matrixorigin:main Oct 31, 2026
@mergify mergify Bot removed the queued label Oct 31, 2026

This branch was previously deployed

1 inactive deployment
ci — e0369d50 Deployed Oct 31, 2026 by aptend
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/documentation Improvements or additions to documentation 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.

3 participants