Skip to content

Commit 0fd8ced

Browse files
committed
planner: fix tidb_enforce_mpp cannot work
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
1 parent 69fe7f9 commit 0fd8ced

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

pkg/planner/core/logical_plan_builder.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ func setPreferredStoreType(ds *logicalop.DataSource, hintInfo *h.PlanHints) {
522522
ds.SCtx().GetSessionVars().RaiseWarningWhenMPPEnforced("MPP mode may be blocked because you have set a hint to read table `" + hintTbl.TblName.O + "` from TiKV.")
523523
}
524524
}
525-
if hintTbl := hintInfo.IfPreferTiFlash(alias); hintTbl != nil || ds.SCtx().GetSessionVars().IsMPPEnforced() {
525+
if hintTbl := hintInfo.IfPreferTiFlash(alias); hintTbl != nil {
526526
// `ds.PreferStoreType != 0`, which means there's a hint hit the both TiKV value and TiFlash value for table.
527527
// We can't support read a table from two different storages, even partition table.
528528
if ds.PreferStoreType != 0 {
@@ -535,9 +535,7 @@ func setPreferredStoreType(ds *logicalop.DataSource, hintInfo *h.PlanHints) {
535535
for _, path := range ds.AllPossibleAccessPaths {
536536
if path.StoreType == kv.TiFlash {
537537
ds.PreferStoreType |= h.PreferTiFlash
538-
if hintTbl != nil {
539-
ds.PreferPartitions[h.PreferTiFlash] = hintTbl.Partitions
540-
}
538+
ds.PreferPartitions[h.PreferTiFlash] = hintTbl.Partitions
541539
break
542540
}
543541
}

pkg/planner/core/plan_cost_ver2.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,13 +724,18 @@ func getPlanCostVer24PhysicalHashJoin(pp base.PhysicalPlan, taskType property.Ta
724724
if taskType == property.MppTaskType { // BCast or Shuffle Join, use mppConcurrency
725725
p.PlanCostVer2 = costusage.SumCostVer2(buildChildCost, probeChildCost,
726726
costusage.DivCostVer2(costusage.SumCostVer2(buildHashCost, buildFilterCost, probeHashCost, probeFilterCost), mppConcurrency))
727+
if p.SCtx().GetSessionVars().IsMPPEnforced() &&
728+
!hasCostFlag(option.CostFlag, costusage.CostFlagRecalculate) { // show the real cost in explain-statements
729+
p.PlanCostVer2 = costusage.DivCostVer2(p.PlanCostVer2, 1000000000)
730+
}
727731
} else { // TiDB HashJoin
728732
startCost := costusage.NewCostVer2(option, cpuFactor,
729733
10*3*cpuFactor.Value, // 10rows * 3func * cpuFactor
730734
func() string { return fmt.Sprintf("cpu(10*3*%v)", cpuFactor) })
731735
p.PlanCostVer2 = costusage.SumCostVer2(startCost, buildChildCost, probeChildCost, buildHashCost, buildFilterCost,
732736
costusage.DivCostVer2(costusage.SumCostVer2(probeFilterCost, probeHashCost), tidbConcurrency))
733737
}
738+
734739
p.PlanCostInit = true
735740
// Multiply by cost factor - defaults to 1, but can be increased/decreased to influence the cost model
736741
p.PlanCostVer2 = costusage.MulCostVer2(p.PlanCostVer2, p.SCtx().GetSessionVars().HashJoinCostFactor)

0 commit comments

Comments
 (0)