Skip to content

Commit

Permalink
expression: Granular Control in mysql.expr_pushdown_blacklist Configu…
Browse files Browse the repository at this point in the history
…ration (pingcap#49324)

close pingcap#49126
  • Loading branch information
AmoebaProtozoa authored Dec 12, 2023
1 parent ce9e9ef commit 4b1cccb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pkg/expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 12 additions & 1 deletion pkg/expression/integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
Expand All @@ -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")
}

Expand Down

0 comments on commit 4b1cccb

Please sign in to comment.