Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: Granular Control in mysql.expr_pushdown_blacklist Configuration #49324

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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