diff --git a/planner/core/task.go b/planner/core/task.go index b38bc98de3d78..1b82b443f3f4a 100644 --- a/planner/core/task.go +++ b/planner/core/task.go @@ -813,11 +813,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 { diff --git a/planner/core/testdata/integration_serial_suite_in.json b/planner/core/testdata/integration_serial_suite_in.json index dd62c3b372578..b867c70b3e24f 100644 --- a/planner/core/testdata/integration_serial_suite_in.json +++ b/planner/core/testdata/integration_serial_suite_in.json @@ -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" ] }, { diff --git a/planner/core/testdata/integration_serial_suite_out.json b/planner/core/testdata/integration_serial_suite_out.json index f3ce566e30d0e..c5d3d51f5762d 100644 --- a/planner/core/testdata/integration_serial_suite_out.json +++ b/planner/core/testdata/integration_serial_suite_out.json @@ -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" + ] } ] },