Skip to content

Commit

Permalink
planner: Do not pushdown unsupported function to tiflash in TopN oper…
Browse files Browse the repository at this point in the history
…ator (#19363)

Co-authored-by: ti-srebot <[email protected]>
  • Loading branch information
windtalker and ti-srebot authored Aug 25, 2020
1 parent 963b82a commit e52cb37
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
6 changes: 1 addition & 5 deletions planner/core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,11 +904,7 @@ func (p *PhysicalTopN) canPushDown(cop *copTask) bool {
for _, item := range p.ByItems {
exprs = append(exprs, item.Expr)
}
storeType := kv.TiKV
if tableScan, ok := cop.tablePlan.(*PhysicalTableScan); ok {
storeType = tableScan.StoreType
}
return expression.CanExprsPushDown(p.ctx.GetSessionVars().StmtCtx, exprs, p.ctx.GetClient(), storeType)
return expression.CanExprsPushDown(p.ctx.GetSessionVars().StmtCtx, exprs, p.ctx.GetClient(), cop.getStoreType())
}

func (p *PhysicalTopN) allColsFromSchema(schema *expression.Schema) bool {
Expand Down
4 changes: 3 additions & 1 deletion planner/core/testdata/integration_serial_suite_in.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"name": "TestSelPushDownTiFlash",
"cases": [
"explain select * from t where t.a > 1 and t.b = \"flash\" or t.a + 3 * t.a = 5",
"explain select * from t where cast(t.a as float) + 3 = 5.1"
"explain select * from t where cast(t.a as float) + 3 = 5.1",
"explain select * from t where b > 'a' order by convert(b, unsigned) limit 2",
"explain select * from t where b > 'a' order by b limit 2"
]
},
{
Expand Down
21 changes: 21 additions & 0 deletions planner/core/testdata/integration_serial_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,27 @@
"└─TableReader_6 10000.00 root data:TableFullScan_5",
" └─TableFullScan_5 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo"
]
},
{
"SQL": "explain select * from t where b > 'a' order by convert(b, unsigned) limit 2",
"Plan": [
"Projection_17 2.00 root test.t.a, test.t.b",
"└─TopN_8 2.00 root Column#3, offset:0, count:2",
" └─Projection_18 3333.33 root test.t.a, test.t.b, cast(test.t.b, bigint(22) UNSIGNED BINARY)->Column#3",
" └─TableReader_13 3333.33 root data:Selection_12",
" └─Selection_12 3333.33 cop[tiflash] gt(test.t.b, \"a\")",
" └─TableFullScan_11 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo"
]
},
{
"SQL": "explain select * from t where b > 'a' order by b limit 2",
"Plan": [
"TopN_8 2.00 root test.t.b, offset:0, count:2",
"└─TableReader_17 2.00 root data:TopN_16",
" └─TopN_16 2.00 cop[tiflash] test.t.b, offset:0, count:2",
" └─Selection_15 3333.33 cop[tiflash] gt(test.t.b, \"a\")",
" └─TableFullScan_14 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo"
]
}
]
},
Expand Down

0 comments on commit e52cb37

Please sign in to comment.