Skip to content

Commit

Permalink
planner/core: push selection operator to mpp task (#22343)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanfei1991 authored Jan 11, 2021
1 parent 6280016 commit dae6e49
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions planner/core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ func attachPlan2Task(p PhysicalPlan, t task) task {
case *rootTask:
p.SetChildren(v.p)
v.p = p
case *mppTask:
p.SetChildren(v.p)
v.p = p
}
return t
}
Expand Down Expand Up @@ -1085,6 +1088,12 @@ func (p *PhysicalUnionAll) attach2Task(tasks ...task) task {

func (sel *PhysicalSelection) attach2Task(tasks ...task) task {
sessVars := sel.ctx.GetSessionVars()
if mppTask, _ := tasks[0].(*mppTask); mppTask != nil { // always push to mpp task.
sc := sel.ctx.GetSessionVars().StmtCtx
if expression.CanExprsPushDown(sc, sel.Conditions, sel.ctx.GetClient(), kv.TiFlash) {
return attachPlan2Task(sel, mppTask.copy())
}
}
t := tasks[0].convertToRootTask(sel.ctx)
t.addCost(t.count() * sessVars.CPUFactor)
return attachPlan2Task(sel, t)
Expand Down
1 change: 1 addition & 0 deletions planner/core/testdata/integration_serial_suite_in.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"explain select count(*) from fact_t right join d1_t on fact_t.d1_k = d1_t.d1_k",
"explain select count(*) from fact_t join d1_t on fact_t.d1_k = d1_t.d1_k and fact_t.col1 > d1_t.value",
"explain select count(*) from fact_t left join d1_t on fact_t.d1_k = d1_t.d1_k and fact_t.col1 > 10",
"explain select count(*) from (select case when t1.col1 is null then t2.col1 + 5 else 10 end as col1, t2.d1_k as d1_k from fact_t t1 right join fact_t t2 on t1.d1_k = t2.d1_k) fact_t join d1_t on fact_t.d1_k = d1_t.d1_k and fact_t.col1 > 5",
"explain select count(*) from fact_t left join d1_t on fact_t.d1_k = d1_t.d1_k and fact_t.col2 > 10 and fact_t.col1 > d1_t.value",
"explain select count(*) from fact_t right join d1_t on fact_t.d1_k = d1_t.d1_k and d1_t.value > 10",
"explain select count(*) from fact_t right join d1_t on fact_t.d1_k = d1_t.d1_k and d1_t.value > 10 and fact_t.col1 > d1_t.value",
Expand Down
25 changes: 25 additions & 0 deletions planner/core/testdata/integration_serial_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,31 @@
" └─TableFullScan_14 16.00 cop[tiflash] table:fact_t keep order:false"
]
},
{
"SQL": "explain select count(*) from (select case when t1.col1 is null then t2.col1 + 5 else 10 end as col1, t2.d1_k as d1_k from fact_t t1 right join fact_t t2 on t1.d1_k = t2.d1_k) fact_t join d1_t on fact_t.d1_k = d1_t.d1_k and fact_t.col1 > 5",
"Plan": [
"HashAgg_37 1.00 root funcs:count(Column#22)->Column#19",
"└─TableReader_39 1.00 root data:ExchangeSender_38",
" └─ExchangeSender_38 1.00 cop[tiflash] ExchangeType: PassThrough",
" └─HashAgg_15 1.00 cop[tiflash] funcs:count(1)->Column#22",
" └─HashJoin_20 204.80 cop[tiflash] inner join, equal:[eq(test.d1_t.d1_k, test.fact_t.d1_k)]",
" ├─ExchangeReceiver_24(Build) 4.00 cop[tiflash] ",
" │ └─ExchangeSender_23 4.00 cop[tiflash] ExchangeType: HashPartition, Hash Cols: test.d1_t.d1_k",
" │ └─Selection_22 4.00 cop[tiflash] not(isnull(test.d1_t.d1_k))",
" │ └─TableFullScan_21 4.00 cop[tiflash] table:d1_t keep order:false",
" └─Projection_25(Probe) 102.40 cop[tiflash] test.fact_t.d1_k",
" └─Selection_27 102.40 cop[tiflash] gt(case(isnull(test.fact_t.col1), plus(test.fact_t.col1, 5), 10), 5)",
" └─HashJoin_28 128.00 cop[tiflash] right outer join, equal:[eq(test.fact_t.d1_k, test.fact_t.d1_k)]",
" ├─ExchangeReceiver_32(Build) 16.00 cop[tiflash] ",
" │ └─ExchangeSender_31 16.00 cop[tiflash] ExchangeType: HashPartition, Hash Cols: test.fact_t.d1_k",
" │ └─Selection_30 16.00 cop[tiflash] not(isnull(test.fact_t.d1_k))",
" │ └─TableFullScan_29 16.00 cop[tiflash] table:t1 keep order:false",
" └─ExchangeReceiver_36(Probe) 16.00 cop[tiflash] ",
" └─ExchangeSender_35 16.00 cop[tiflash] ExchangeType: HashPartition, Hash Cols: test.fact_t.d1_k",
" └─Selection_34 16.00 cop[tiflash] not(isnull(test.fact_t.d1_k))",
" └─TableFullScan_33 16.00 cop[tiflash] table:t2 keep order:false"
]
},
{
"SQL": "explain select count(*) from fact_t left join d1_t on fact_t.d1_k = d1_t.d1_k and fact_t.col2 > 10 and fact_t.col1 > d1_t.value",
"Plan": [
Expand Down

0 comments on commit dae6e49

Please sign in to comment.