Skip to content

planner: fix TPCDS Q64 regression under the new join algorithm#69637

Merged
ti-chi-bot[bot] merged 2 commits into
pingcap:masterfrom
qw4990:fix-69600-master
Jul 3, 2026
Merged

planner: fix TPCDS Q64 regression under the new join algorithm#69637
ti-chi-bot[bot] merged 2 commits into
pingcap:masterfrom
qw4990:fix-69600-master

Conversation

@qw4990

@qw4990 qw4990 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: ref #69600

Problem Summary: planner: fix TPCDS Q64 regression under the new CD-C join algorithm

What changed and how does it work?

In TPCDS Q64, ib1 and ib2 have the same row count, but the old join-order implementation is using SortStableFunc while the new one is using SortFunc, which leads to this join order change.

This PR update the new join-order implementation to also use SortStableFunc to keep the prior behavior.

image image

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

Summary by CodeRabbit

  • Bug Fixes
    • Improved stability in join-order planning by preserving the relative order of candidate nodes when they have equal estimated cost, avoiding inconsistent tie-breaking.
  • Tests
    • Updated TPC-DS Q64 expected plan outputs to reflect revised physical plan structure under exchanges and hash join subtree nesting.

@ti-chi-bot ti-chi-bot Bot added release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. sig/planner SIG: Planner labels Jul 3, 2026
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 329b67b1-17a0-4f88-9aa8-cbf41456ef26

📥 Commits

Reviewing files that changed from the base of the PR and between b4e21c2 and 478d198.

📒 Files selected for processing (2)
  • pkg/planner/core/casetest/tpcds/testdata/tpcds_suite_out.json
  • pkg/planner/core/casetest/tpcds/testdata/tpcds_suite_xut.json

📝 Walkthrough

Walkthrough

The greedy join-order optimizer now uses a stable sort for equal-cost candidates, and the TPCDS Q64 expected plan outputs were updated to match the resulting join and exchange ordering.

Changes

Join Order Sort Stability and Q64 Plan Expectations

Layer / File(s) Summary
Stable sort for node ordering
pkg/planner/core/joinorder/join_order.go
joinOrderGreedy.optimize now uses slices.SortStableFunc instead of slices.SortFunc when ordering nodes by cumCost.
Updated Q64 expected plan trees
pkg/planner/core/casetest/tpcds/testdata/tpcds_suite_out.json, pkg/planner/core/casetest/tpcds/testdata/tpcds_suite_xut.json
The stored TestTPCDSQ64 plan outputs are rewritten to reflect the new exchange, projection, and hash-join subtree layout.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Possibly related PRs

  • pingcap/tidb#68340: Modifies joinOrderGreedy.optimize in the same join-order area and interacts with the candidate-node ordering logic.

Suggested labels: approved, lgtm

Suggested reviewers: AilinKid, windtalker

Poem

I sorted the nodes, then gave them a spin,
But ties stayed in step from the first one to win.
🐇 The Q64 plans now hop in place,
With stable little footprints all over the trace.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing the TPCDS Q64 regression under the new join algorithm.
Description check ✅ Passed The description matches the template well, including problem summary, issue reference, changes, test checklist, and release note.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.1110%. Comparing base (8be4bd0) to head (478d198).

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #69637        +/-   ##
================================================
- Coverage   76.3268%   74.1110%   -2.2159%     
================================================
  Files          2041       2050         +9     
  Lines        560589     576524     +15935     
================================================
- Hits         427880     427268       -612     
- Misses       131808     149049     +17241     
+ Partials        901        207       -694     
Flag Coverage Δ
integration 40.7041% <100.0000%> (+0.9989%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 60.4471% <ø> (ø)
parser ∅ <ø> (∅)
br 47.4650% <ø> (-15.2563%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ti-chi-bot ti-chi-bot Bot added needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 3, 2026
@ti-chi-bot ti-chi-bot Bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 3, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AilinKid, winoros

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 3, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-07-03 08:59:16.98660315 +0000 UTC m=+375498.686982562: ☑️ agreed by winoros.
  • 2026-07-03 09:13:22.624763627 +0000 UTC m=+376344.325143040: ☑️ agreed by AilinKid.

@ti-chi-bot ti-chi-bot Bot merged commit 8b7e209 into pingcap:master Jul 3, 2026
34 checks passed
@ti-chi-bot

Copy link
Copy Markdown
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #69654.

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

Labels

approved lgtm needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants