From e07d21cf2dae248713e837773a224ee318947bd2 Mon Sep 17 00:00:00 2001 From: AmoebaProtozoa <8039876+AmoebaProtozoa@users.noreply.github.com> Date: Mon, 11 Dec 2023 14:33:38 +0800 Subject: [PATCH 1/2] add basic test case Signed-off-by: AmoebaProtozoa <8039876+AmoebaProtozoa@users.noreply.github.com> --- pkg/expression/expression.go | 4 +++- pkg/expression/integration_test/integration_test.go | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) 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..cffe5952cd7af 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,6 +693,10 @@ 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])) + // CastTimeAsDuration not pushed to TiKV + rows = tk.MustQuery("explain format = 'brief' select * from test.t where hour(b) > 10").Rows() + 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("admin reload expr_pushdown_blacklist") From 72dccada4b10e0694a88d217f301dad74819df71 Mon Sep 17 00:00:00 2001 From: AmoebaProtozoa <8039876+AmoebaProtozoa@users.noreply.github.com> Date: Tue, 12 Dec 2023 10:40:56 +0800 Subject: [PATCH 2/2] better test case Signed-off-by: AmoebaProtozoa <8039876+AmoebaProtozoa@users.noreply.github.com> --- pkg/expression/integration_test/integration_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/expression/integration_test/integration_test.go b/pkg/expression/integration_test/integration_test.go index cffe5952cd7af..9b8c71da32505 100644 --- a/pkg/expression/integration_test/integration_test.go +++ b/pkg/expression/integration_test/integration_test.go @@ -693,12 +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])) - // CastTimeAsDuration not pushed to TiKV + // 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") }