Skip to content

Commit

Permalink
expression: Push down json_contains to tikv (#37840)
Browse files Browse the repository at this point in the history
close #37839
  • Loading branch information
lizhenhuan authored Oct 13, 2022
1 parent a5c7c03 commit a10bb9e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ func scalarExprSupportedByTiKV(sf *ScalarFunction) bool {
ast.JSONType, ast.JSONExtract, ast.JSONObject, ast.JSONArray, ast.JSONMerge, ast.JSONSet,
ast.JSONInsert /*ast.JSONReplace,*/, ast.JSONRemove, ast.JSONLength,
// FIXME: JSONUnquote is incompatible with Coprocessor
ast.JSONUnquote,
ast.JSONUnquote, ast.JSONContains,

// date functions.
ast.Date, ast.Week /* ast.YearWeek, ast.ToSeconds */, ast.DateDiff,
Expand Down
6 changes: 5 additions & 1 deletion planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3065,7 +3065,7 @@ func TestScalarFunctionPushDown(t *testing.T) {
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t(id int signed, id2 int unsigned, c varchar(11), d datetime, b double, e bit(10))")
tk.MustExec("insert into t(id, id2, c, d) values (-1, 1, 'abc', '2021-12-12')")
tk.MustExec("insert into t(id, id2, c, d) values (-1, 1, '{\"a\":1}', '2021-12-12')")
rows := [][]interface{}{
{"TableReader_7", "root", "data:Selection_6"},
{"└─Selection_6", "cop[tikv]", "right(test.t.c, 1)"},
Expand Down Expand Up @@ -3178,6 +3178,10 @@ func TestScalarFunctionPushDown(t *testing.T) {
rows[1][2] = "ascii(cast(test.t.e, var_string(2)))"
tk.MustQuery("explain analyze select /*+read_from_storage(tikv[t])*/ * from t where ascii(e);").
CheckAt([]int{0, 3, 6}, rows)

rows[1][2] = "json_contains(cast(test.t.c, json BINARY), cast(\"1\", json BINARY))"
tk.MustQuery("explain analyze select /*+read_from_storage(tikv[t])*/ * from t where json_contains(c, '1');").
CheckAt([]int{0, 3, 6}, rows)
}

func TestDistinctScalarFunctionPushDown(t *testing.T) {
Expand Down

0 comments on commit a10bb9e

Please sign in to comment.