From 1bf3b3a913b07ef025826c30d60d3392a8e667a1 Mon Sep 17 00:00:00 2001 From: qw4990 Date: Fri, 15 Jul 2022 17:22:08 +0800 Subject: [PATCH] fixup --- planner/core/physical_plans.go | 5 +++++ planner/core/plan_cost.go | 3 +++ planner/core/task.go | 1 + 3 files changed, 9 insertions(+) diff --git a/planner/core/physical_plans.go b/planner/core/physical_plans.go index 3e04dea447572..e1b43e6bf0975 100644 --- a/planner/core/physical_plans.go +++ b/planner/core/physical_plans.go @@ -1295,6 +1295,11 @@ type PhysicalSelection struct { basePhysicalPlan Conditions []expression.Expression + + // The flag indicates whether this Selection is from a DataSource. + // The flag is only used by cost model for compatibility and will be removed later. + // Please see https://github.com/pingcap/tidb/issues/36243 for more details. + fromDataSource bool } // Clone implements PhysicalPlan interface. diff --git a/planner/core/plan_cost.go b/planner/core/plan_cost.go index 73758b562536a..6dc4132fa2ba2 100644 --- a/planner/core/plan_cost.go +++ b/planner/core/plan_cost.go @@ -81,6 +81,9 @@ func (p *PhysicalSelection) GetPlanCost(taskType property.TaskType, costFlag uin return 0, errors.Errorf("unknown task type %v", taskType) } selfCost = getCardinality(p.children[0], costFlag) * cpuFactor + if p.fromDataSource { + selfCost = 0 // for compatibility, see https://github.com/pingcap/tidb/issues/36243 + } case modelVer2: // selection cost: rows * num-filters * cpu-factor var cpuFactor float64 switch taskType { diff --git a/planner/core/task.go b/planner/core/task.go index 7d88aac896812..8181f985cc61f 100644 --- a/planner/core/task.go +++ b/planner/core/task.go @@ -809,6 +809,7 @@ func (t *copTask) handleRootTaskConds(ctx sessionctx.Context, newTask *rootTask) selectivity = SelectionFactor } sel := PhysicalSelection{Conditions: t.rootTaskConds}.Init(ctx, newTask.p.statsInfo().Scale(selectivity), newTask.p.SelectBlockOffset()) + sel.fromDataSource = true sel.SetChildren(newTask.p) newTask.p = sel sel.cost = newTask.cost()