diff --git a/pkg/expression/expression.go b/pkg/expression/expression.go index a4216d1a6e213..3db2799f5bf0f 100644 --- a/pkg/expression/expression.go +++ b/pkg/expression/expression.go @@ -1331,7 +1331,9 @@ func canFuncBePushed(sf *ScalarFunction, storeType kv.StoreType) bool { } if ret { - ret = IsPushDownEnabled(sf.FuncName.L, storeType) + funcFullName := fmt.Sprintf("%s.%s", sf.FuncName.L, strings.ToLower(sf.Function.PbCode().String())) + // Aside from checking function name, also check the pb name in case only the specific push down is disabled. + ret = IsPushDownEnabled(sf.FuncName.L, storeType) && IsPushDownEnabled(funcFullName, storeType) } return ret } diff --git a/pkg/expression/integration_test/integration_test.go b/pkg/expression/integration_test/integration_test.go index 54dbcb557ad05..9b8c71da32505 100644 --- a/pkg/expression/integration_test/integration_test.go +++ b/pkg/expression/integration_test/integration_test.go @@ -673,7 +673,8 @@ func TestExprPushdownBlacklist(t *testing.T) { } tk.MustExec("insert into mysql.expr_pushdown_blacklist " + - "values('<', 'tikv,tiflash,tidb', 'for test'),('cast', 'tiflash', 'for test'),('date_format', 'tikv', 'for test')") + "values('<', 'tikv,tiflash,tidb', 'for test'),('cast', 'tiflash', 'for test'),('date_format', 'tikv', 'for test')," + + "('Cast.CastTimeAsDuration', 'tikv', 'for test')") tk.MustExec("admin reload expr_pushdown_blacklist") tk.MustExec("set @@session.tidb_isolation_read_engines = 'tiflash'") @@ -692,8 +693,18 @@ func TestExprPushdownBlacklist(t *testing.T) { require.Equal(t, "eq(date_format(test.t.b, \"%m\"), \"11\"), lt(test.t.b, 1994-01-01)", fmt.Sprintf("%v", rows[0][4])) require.Equal(t, "gt(cast(test.t.a, decimal(10,2) BINARY), 10.10), gt(test.t.b, 1988-01-01)", fmt.Sprintf("%v", rows[2][4])) + // CastTimeAsString pushed to TiKV but CastTimeAsDuration not pushed + rows = tk.MustQuery("explain format = 'brief' SELECT * FROM t WHERE CAST(b AS CHAR) = '10:00:00';").Rows() + require.Equal(t, "cop[tikv]", fmt.Sprintf("%v", rows[1][2])) + require.Equal(t, "eq(cast(test.t.b, var_string(5)), \"10:00:00\")", fmt.Sprintf("%v", rows[1][4])) + + rows = tk.MustQuery("explain format = 'brief' select * from test.t where hour(b) > 10").Rows() + require.Equal(t, "root", fmt.Sprintf("%v", rows[0][2])) + require.Equal(t, "gt(hour(cast(test.t.b, time)), 10)", fmt.Sprintf("%v", rows[0][4])) + tk.MustExec("delete from mysql.expr_pushdown_blacklist where name = '<' and store_type = 'tikv,tiflash,tidb' and reason = 'for test'") tk.MustExec("delete from mysql.expr_pushdown_blacklist where name = 'date_format' and store_type = 'tikv' and reason = 'for test'") + tk.MustExec("delete from mysql.expr_pushdown_blacklist where name = 'Cast.CastTimeAsDuration' and store_type = 'tikv' and reason = 'for test'") tk.MustExec("admin reload expr_pushdown_blacklist") }