Skip to content

Conversation

@hawkingrei
Copy link
Member

@hawkingrei hawkingrei commented Dec 25, 2025

What problem does this PR solve?

Issue Number: close #65335

Problem Summary:

What changed and how does it work?

checkCanPushDownToMPP will be called twice in the following code. The other problem is that if tables without tiflash replications are used in the query, we don't need to check the mpp task.

func getHashAggs(lp base.LogicalPlan, prop *property.PhysicalProperty) []base.PhysicalPlan {
la := lp.(*logicalop.LogicalAggregation)
if !prop.IsSortItemEmpty() {
return nil
}
if prop.TaskTp == property.MppTaskType && !checkCanPushDownToMPP(la) {
return nil
}
hashAggs := make([]base.PhysicalPlan, 0, len(prop.GetAllPossibleChildTaskTypes()))
taskTypes := []property.TaskType{property.CopSingleReadTaskType, property.CopMultiReadTaskType, property.RootTaskType}
// aggregation has a special case that it can be pushed down to TiKV which is indicated by the prop.NoCopPushDown
if prop.NoCopPushDown {
taskTypes = []property.TaskType{property.RootTaskType}
}
// lift the recursive check of canPushToCop(tiFlash)
canPushDownToMPP := la.SCtx().GetSessionVars().IsMPPAllowed() && checkCanPushDownToMPP(la)
if canPushDownToMPP {
taskTypes = append(taskTypes, property.MppTaskType)
} else {
hasMppHints := false
var errMsg string
if la.PreferAggType&h.PreferMPP1PhaseAgg > 0 {
errMsg = "The agg can not push down to the MPP side, the MPP_1PHASE_AGG() hint is invalid"
hasMppHints = true
}
if la.PreferAggType&h.PreferMPP2PhaseAgg > 0 {
errMsg = "The agg can not push down to the MPP side, the MPP_2PHASE_AGG() hint is invalid"
hasMppHints = true
}
if hasMppHints {
la.SCtx().GetSessionVars().StmtCtx.SetHintWarning(errMsg)
}
}
if prop.IsFlashProp() {
taskTypes = []property.TaskType{prop.TaskTp}
}
taskTypes = admitIndexJoinTypes(taskTypes, prop)
for _, taskTp := range taskTypes {
if taskTp == property.MppTaskType {
mppAggs := tryToGetMppHashAggs(la, prop)
if len(mppAggs) > 0 {
hashAggs = append(hashAggs, mppAggs...)
}
} else {
childProp := &property.PhysicalProperty{ExpectedCnt: math.MaxFloat64, TaskTp: taskTp, CTEProducerStatus: prop.CTEProducerStatus, NoCopPushDown: prop.NoCopPushDown}
// mainly to fill indexJoinProp to childProp.
childProp = admitIndexJoinProp(childProp, prop)
if childProp == nil {
continue
}
agg := NewPhysicalHashAgg(la, la.StatsInfo().ScaleByExpectCnt(la.SCtx().GetSessionVars(), prop.ExpectedCnt), childProp)
agg.SetSchema(la.Schema().Clone())
hashAggs = append(hashAggs, agg)
}
}
return hashAggs
}

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

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue do-not-merge/needs-tests-checked 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 and removed do-not-merge/needs-tests-checked labels Dec 25, 2025
@codecov
Copy link

codecov bot commented Dec 25, 2025

Codecov Report

❌ Patch coverage is 68.86228% with 52 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.5349%. Comparing base (6ff1adf) to head (d1e96df).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #65250         +/-   ##
=================================================
- Coverage   77.7600%   47.5349%   -30.2251%     
=================================================
  Files          2001       1780        -221     
  Lines        546165     464873      -81292     
=================================================
- Hits         424698     220977     -203721     
- Misses       119805     223075     +103270     
- Partials       1662      20821      +19159     
Flag Coverage Δ
integration 47.5349% <68.8622%> (-0.6518%) ⬇️
tiprow_ft ?
unit ?

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

Components Coverage Δ
dumpling ∅ <ø> (∅)
parser ∅ <ø> (∅)
br 47.0720% <ø> (-13.8998%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ti-chi-bot ti-chi-bot bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 25, 2025
@hawkingrei hawkingrei force-pushed the cannot_call_checkCanPushDownToMPP_twice branch from 4728a02 to e3b9c98 Compare December 30, 2025 05:02
@hawkingrei
Copy link
Member Author

/retest

@hawkingrei
Copy link
Member Author

/retest

@hawkingrei hawkingrei changed the title planner: cannot call checkCanPushDownToMPP twice planner: cannot call checkCanPushDownToMPP twice | tidb-test=pr/2660 Dec 30, 2025
@hawkingrei
Copy link
Member Author

/retest

1 similar comment
@hawkingrei
Copy link
Member Author

/retest

@hawkingrei hawkingrei changed the title planner: cannot call checkCanPushDownToMPP twice | tidb-test=pr/2660 planner: don't call checkCanPushDownToMPP twice | tidb-test=pr/2660 Dec 30, 2025
@hawkingrei hawkingrei changed the title planner: don't call checkCanPushDownToMPP twice | tidb-test=pr/2660 planner: improve checkCanPushDownToMPP | tidb-test=pr/2660 Dec 30, 2025
@hawkingrei hawkingrei force-pushed the cannot_call_checkCanPushDownToMPP_twice branch from b114bb3 to e949bd4 Compare December 30, 2025 14:20
@hawkingrei
Copy link
Member Author

/retest

@hawkingrei hawkingrei force-pushed the cannot_call_checkCanPushDownToMPP_twice branch from 78144ef to 9b4552a Compare December 30, 2025 15:39
@hawkingrei hawkingrei changed the title planner: improve checkCanPushDownToMPP | tidb-test=pr/2660 planner: improve getHashAggs | tidb-test=pr/2660 Dec 30, 2025
@hawkingrei
Copy link
Member Author

/retest

return nil, err
}
tableInfo := tbl.Meta()
sessionVars.StmtCtx.HasTiflash = sessionVars.StmtCtx.HasTiflash || b.ctx.GetSessionVars().IsMPPAllowed() &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to add this together in this pr.
Current physical optimization needs to generate the mpp task type first because we don't know whether its children can be converted to mpp plan.
If we want to do the pruning completely, we'll need to change the physical opt framework itself.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But under the current circumstances, most users actually won't have TiFlash replicas. So when building the data source, it can quickly determine whether it contains TiFlash based on the table metadata.

@hawkingrei hawkingrei changed the title planner: improve getHashAggs | tidb-test=pr/2660 planner: add HasTiflash to avoid generating unnecessary mpp task | tidb-test=pr/2660 Dec 30, 2025
@hawkingrei
Copy link
Member Author

/retest

hawkingrei and others added 25 commits February 4, 2026 10:20
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
@hawkingrei hawkingrei force-pushed the cannot_call_checkCanPushDownToMPP_twice branch from 2fc565f to d1e96df Compare February 4, 2026 02:21
@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 4, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign d3hunter, time-and-fate, windtalker for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found 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
Copy link

ti-chi-bot bot commented Feb 4, 2026

@hawkingrei: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
idc-jenkins-ci-tidb/unit-test d1e96df link true /test unit-test
pull-unit-test-next-gen d1e96df link true /test pull-unit-test-next-gen
pull-integration-realcluster-test-next-gen d1e96df link true /test pull-integration-realcluster-test-next-gen
pull-mysql-client-test-next-gen e80b918 link true /test pull-mysql-client-test-next-gen
idc-jenkins-ci-tidb/mysql-test e80b918 link true /test mysql-test

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@tiprow
Copy link

tiprow bot commented Feb 4, 2026

@hawkingrei: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
fast_test_tiprow e80b918 link true /test fast_test_tiprow

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

component/statistics ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wrongly generate the intermediate results for MPP in the optimizor

2 participants