Skip to content

perf: share partition sorting across compatible value windows - #33658

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/27943-window-sharing
Dec 2, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/27943-window-sharing

Conversation

@iamlinjunhong

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 #27943

What this PR does / why we need it:

The planner built five Partition/Window pairs for LAG, LEAD, FIRST_VALUE, LAST_VALUE and NTH_VALUE even when they all used the same partition keys, ordering and ROWS frame. Each pair could spill the same input separately.

Extend the existing post-remap fusion rule to ordered value functions with safe column or literal arguments. Allow lossless integer source casts and integer modulo partition keys with a positive literal divisor. Keep dynamic offsets, fallible casts, different layouts, dependencies and intermediate filters on their existing paths. The retained Window uses one permutation for its rows and all arguments, and validates every LAG/LEAD slot before publishing a chunk. This uses the existing execution and distribution formats.

On the issue's 100,000-row SQL fixture (single CN, macOS arm64, GOMAXPROCS=4), the plan went from five Window and five Partition nodes to one each. At sort_spill_mem=1, Window spill rows went from 500,000 to 100,000 and reported Window spill size from about 22.9 MiB to 6.11 MiB. With one warm-up and five timed executions per setting, the median was 68.0 ms on main and 28.1 ms with this patch. At 64 MiB, medians were 35.9 ms and 23.8 ms. These are local SQL timings on a shared machine.

Both revisions returned (100000, 4798977, 4800545, 399995, 8700005, 1099995). Checked 100,000 nullable-source rows against an independent per-row oracle and verified chains for tied ordering at both spill thresholds. With analyzed low-NDV column keys, COST and HASH used Hash Partition and SORT used ordinary Partition, with the same five results. The two affected Go packages, scoped vet and incremental lint passed. The new SQL regression case was executed against the built service.

On a three-CN cluster with all CNs working and forced distributed scans, physical ANALYZE showed table scans on both remote peers. One Partition fed one Window, which consumed and emitted all 100,000 rows and spilled 100,000 rows (6,402,520 bytes). The aggregate query matched the independent checksum. In a separate experiment with the coordinator explicitly set to draining, physical ANALYZE exceeded the three-minute timeout on both clean main and the candidate; that configuration remains unverified.

The remaining issue-wide rollout and shuffle-topology criteria require separate validation.

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

Copy link
Copy Markdown
Contributor

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

@XuPeng-SH

XuPeng-SH commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 9cc0ad17a26e33e5d99048199cd7dac520572cf6

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: 9cc0ad17a26e33e5d99048199cd7dac520572cf6

Assessment: approve

No actionable defects found. The change extends the existing window-fusion and execution mechanisms, with guards for compatible layouts and safe arguments.

Model: gpt-6.1-terra / max

Session: 01a23504-137d-7f93-9b91-fd29f7f60fa2 · slot 1 · generation 42

Validation:

  • The focused planner and window tests passed, including spill/reset and later-slot offset validation.

  • A single-CN public SQL probe passed with nullable inputs at low and high spill thresholds. The low-threshold analyzed plan used one Window node and reported seven spilled rows.

  • An independent SQLite oracle matched the probe’s expected values and all seven changed SQL regression result rows.

  • A bounded 100,000-row, 512 MiB threshold comparison returned identical checksums; the candidate’s three measured runs were 25.342–25.874 ms versus 41.181–59.620 ms for the baseline control.

  • The isolation preflight, native input verification, gofmt check, and git diff --check passed.

Limitations:

  • The performance comparison used one shared single-CN host and does not establish performance for all workloads.

  • Full package suites, the BVT harness, race tests, and multi-CN execution were not independently run. The author reports a separate three-CN check; the draining-coordinator configuration remains unverified.

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

mergify Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request merged manually

2 h 20 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Wed 2 Dec, 10:44 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 13:04 · 0323f34

Reason

Pull request #33658 has been merged manually at 169ea91

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

@XuPeng-SH
XuPeng-SH merged commit 169ea91 into matrixorigin:main Dec 2, 2026
28 of 30 checks passed
@mergify mergify Bot removed the queued label Dec 2, 2026

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants