From d0ff896ee189c44e44af829177a48588c6b6f1ba Mon Sep 17 00:00:00 2001 From: "muyun.pan" Date: Fri, 10 Apr 2026 14:26:49 +0800 Subject: [PATCH 1/4] expression: pushdown trim to tikv --- pkg/expression/expr_to_pb_test.go | 34 ++ pkg/expression/infer_pushdown.go | 3 +- pkg/planner/core/integration_test.go | 144 +++++++ .../r/expression/builtin.result | 366 ++++++++++++++++++ .../integrationtest/t/expression/builtin.test | 266 ++++++++++++- tests/realtikvtest/pushdowntest/BUILD.bazel | 2 +- tests/realtikvtest/pushdowntest/expr_test.go | 161 ++++++++ 7 files changed, 973 insertions(+), 3 deletions(-) diff --git a/pkg/expression/expr_to_pb_test.go b/pkg/expression/expr_to_pb_test.go index 15b1ad4603a64..2c008867caf60 100644 --- a/pkg/expression/expr_to_pb_test.go +++ b/pkg/expression/expr_to_pb_test.go @@ -362,6 +362,40 @@ func TestDateFunc2Pb(t *testing.T) { require.Equal(t, "{\"tp\":10000,\"children\":[{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0,\"field_type\":{\"tp\":12,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":-63,\"charset\":\"binary\",\"array\":false},\"has_distinct\":false},{\"tp\":201,\"val\":\"gAAAAAAAAAI=\",\"sig\":0,\"field_type\":{\"tp\":254,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":-46,\"charset\":\"utf8mb4\",\"array\":false},\"has_distinct\":false}],\"sig\":6001,\"field_type\":{\"tp\":253,\"flag\":0,\"flen\":0,\"decimal\":-1,\"collate\":-46,\"charset\":\"utf8mb4\",\"array\":false},\"has_distinct\":false}", string(js)) } +func TestTrimFunc2Pb(t *testing.T) { + ctx := mock.NewContext() + client := new(mock.Client) + stringColumn := genColumn(mysql.TypeString, 1) + remstrColumn := genColumn(mysql.TypeString, 2) + direction := &Constant{ + Value: types.NewIntDatum(int64(ast.TrimLeading)), + RetType: types.NewFieldType(mysql.TypeLonglong), + } + + funcs := make([]Expression, 0, 3) + function, err := NewFunction(ctx, ast.Trim, types.NewFieldType(mysql.TypeString), stringColumn) + require.NoError(t, err) + require.Equal(t, tipb.ScalarFuncSig_Trim1Arg, function.(*ScalarFunction).Function.PbCode()) + funcs = append(funcs, function) + + function, err = NewFunction(ctx, ast.Trim, types.NewFieldType(mysql.TypeString), stringColumn, remstrColumn) + require.NoError(t, err) + require.Equal(t, tipb.ScalarFuncSig_Trim2Args, function.(*ScalarFunction).Function.PbCode()) + funcs = append(funcs, function) + + function, err = NewFunction(ctx, ast.Trim, types.NewFieldType(mysql.TypeString), stringColumn, remstrColumn, direction) + require.NoError(t, err) + require.Equal(t, tipb.ScalarFuncSig_Trim3Args, function.(*ScalarFunction).Function.PbCode()) + funcs = append(funcs, function) + + pbExprs, err := ExpressionsToPBList(ctx, funcs, client) + require.NoError(t, err) + require.Len(t, pbExprs, 3) + require.Equal(t, tipb.ScalarFuncSig_Trim1Arg, pbExprs[0].Sig) + require.Equal(t, tipb.ScalarFuncSig_Trim2Args, pbExprs[1].Sig) + require.Equal(t, tipb.ScalarFuncSig_Trim3Args, pbExprs[2].Sig) +} + func TestLogicalFunc2Pb(t *testing.T) { var logicalFuncs = make([]Expression, 0) ctx := mock.NewContext() diff --git a/pkg/expression/infer_pushdown.go b/pkg/expression/infer_pushdown.go index 6c6c35a208075..7909fee15b672 100644 --- a/pkg/expression/infer_pushdown.go +++ b/pkg/expression/infer_pushdown.go @@ -210,9 +210,10 @@ func scalarExprSupportedByTiKV(ctx EvalContext, sf *ScalarFunction) bool { // string functions. // ast.Bin, ast.Unhex, ast.Locate, ast.Ord, ast.Lpad, ast.Rpad, - // ast.Trim, ast.FromBase64, ast.ToBase64, ast.InsertFunc, + // ast.FromBase64, ast.ToBase64, ast.InsertFunc, // ast.MakeSet, ast.SubstringIndex, ast.Instr, ast.Quote, ast.Oct, // ast.FindInSet, ast.Repeat, + ast.Trim, ast.Upper, ast.Lower, ast.Length, ast.BitLength, ast.Concat, ast.ConcatWS, ast.Replace, ast.ASCII, ast.Hex, ast.Reverse, ast.LTrim, ast.RTrim, ast.Strcmp, ast.Space, ast.Elt, ast.Field, diff --git a/pkg/planner/core/integration_test.go b/pkg/planner/core/integration_test.go index 6434ad4096d84..9bba28c0165ad 100644 --- a/pkg/planner/core/integration_test.go +++ b/pkg/planner/core/integration_test.go @@ -430,6 +430,150 @@ func TestTimeScalarFunctionPushDownResult(t *testing.T) { tk.MustExec("admin reload expr_pushdown_blacklist;") } +func TestTrimPushDownToTiKV(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t;") + tk.MustExec(`create table t( + id int primary key, + c varchar(64) charset utf8mb4 collate utf8mb4_general_ci, + c_bin varchar(64) charset utf8mb4 collate utf8mb4_bin, + c_ascii varchar(64) charset ascii collate ascii_bin, + vb varbinary(64) + );`) + tk.MustExec(`insert into t values + (1, ' x ', ' x ', ' x ', x'207820'), + (2, 'xybarxy', 'xybarxy', 'xybarxy', x'20787920'), + (3, 'xyxybarxy', 'xyxybarxy', 'xyxybarxy', x'2078797820'), + (4, 'xybarxyxy', 'xybarxyxy', 'xybarxyxy', x'207879787920'), + (5, 'xyxybarxyxy', 'xyxybarxyxy', 'xyxybarxyxy', x'207879787920'), + (6, '', '', '', x''), + (7, null, null, null, null), + (8, ' ', ' ', ' ', x'202020'), + (9, '好好bar好好', '好好bar好好', null, x''), + (10, 'bar', 'bar', 'bar', x'626172'), + (11, 'x', 'x', 'x', x'78'), + (12, 'ff', 'ff', 'ff', x'20ff20'), + (13, null, null, null, x'20ff7820'), + (14, null, null, null, x'00207820');`) + + resetBlacklist := func() { + tk.MustExec("delete from mysql.expr_pushdown_blacklist where name != 'date_add'") + tk.MustExec("admin reload expr_pushdown_blacklist;") + } + t.Cleanup(resetBlacklist) + resetBlacklist() + + testcases := []struct { + name string + sql string + expected []string + }{ + { + name: "trim_1_arg", + sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(c) = 'x' order by id;", + expected: []string{"1", "11"}, + }, + { + name: "trim_2_args", + sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim('xy' from c) = 'bar' order by id;", + expected: []string{"2", "3", "4", "5", "10"}, + }, + { + name: "trim_leading", + sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(leading 'xy' from c) = 'barxy' order by id;", + expected: []string{"2", "3"}, + }, + { + name: "trim_trailing", + sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(trailing 'xy' from c) = 'xybar' order by id;", + expected: []string{"2", "4"}, + }, + { + name: "trim_both", + sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(both 'xy' from c) = 'bar' order by id;", + expected: []string{"2", "3", "4", "5", "10"}, + }, + { + name: "trim_null_input", + sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(c) is null order by id;", + expected: []string{"7", "13", "14"}, + }, + { + name: "trim_empty_string", + sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(c) = '' order by id;", + expected: []string{"6", "8"}, + }, + { + name: "trim_empty_pattern", + sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim('' from c) = 'bar' order by id;", + expected: []string{"10"}, + }, + { + name: "trim_pattern_longer_than_input", + sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim('xy' from c) = 'x' order by id;", + expected: []string{"11"}, + }, + { + name: "trim_2_args_null_input", + sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim('xy' from c) is null order by id;", + expected: []string{"7", "13", "14"}, + }, + { + name: "trim_multibyte_general_ci", + sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim('好' from c) = 'bar' and c like '%好%' order by id;", + expected: []string{"9"}, + }, + { + name: "trim_multibyte_bin", + sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim('好' from c_bin) = 'bar' and c_bin like '%好%' order by id;", + expected: []string{"9"}, + }, + { + name: "trim_ascii_charset", + sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(c_ascii) = 'x' order by id;", + expected: []string{"1", "11"}, + }, + { + name: "trim_binary_string", + sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(vb) = x'78' order by id;", + expected: []string{"1", "11"}, + }, + { + name: "trim_invalid_utf8_binary", + sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(vb) = x'ff' order by id;", + expected: []string{"12"}, + }, + { + name: "trim_binary_empty_result", + sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(vb) = x'' order by id;", + expected: []string{"6", "8", "9"}, + }, + { + name: "trim_binary_invalid_utf8_middle", + sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(vb) = x'ff78' order by id;", + expected: []string{"13"}, + }, + { + name: "trim_binary_with_nul", + sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(vb) = x'002078' order by id;", + expected: []string{"14"}, + }, + } + + for _, testcase := range testcases { + resetBlacklist() + r1 := tk.MustQuery(testcase.sql).Rows() + require.EqualValues(t, testkit.Rows(testcase.expected...), r1, testcase.name) + + tk.MustExec("insert into mysql.expr_pushdown_blacklist(name) values('trim');") + tk.MustExec("admin reload expr_pushdown_blacklist;") + r2 := tk.MustQuery(testcase.sql).Rows() + require.EqualValues(t, r1, r2, testcase.name) + } +} + func TestNumberFunctionPushDown(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) diff --git a/tests/integrationtest/r/expression/builtin.result b/tests/integrationtest/r/expression/builtin.result index a18f6a15495c5..3a4fe89162b8d 100644 --- a/tests/integrationtest/r/expression/builtin.result +++ b/tests/integrationtest/r/expression/builtin.result @@ -1931,6 +1931,372 @@ hex(trim('')) hex(trim('x' from '')) select hex(trim(null from 'bar')), hex(trim('x' from null)), hex(trim(null)), hex(trim(leading null from 'bar')); hex(trim(null from 'bar')) hex(trim('x' from null)) hex(trim(null)) hex(trim(leading null from 'bar')) NULL NULL NULL NULL +drop table if exists t_trim_pushdown; +create table t_trim_pushdown( +id int primary key, +c varchar(64) charset utf8mb4 collate utf8mb4_general_ci, +c_bin varchar(64) charset utf8mb4 collate utf8mb4_bin, +c_ascii varchar(64) charset ascii collate ascii_bin, +vb varbinary(64) +); +insert into t_trim_pushdown values +(1, ' x ', ' x ', ' x ', x'207820'), +(2, 'xybarxy', 'xybarxy', 'xybarxy', x'20787920'), +(3, 'xyxybarxy', 'xyxybarxy', 'xyxybarxy', x'2078797820'), +(4, 'xybarxyxy', 'xybarxyxy', 'xybarxyxy', x'207879787920'), +(5, 'xyxybarxyxy', 'xyxybarxyxy', 'xyxybarxyxy', x'207879787920'), +(6, '', '', '', x''), +(7, null, null, null, null), +(8, ' ', ' ', ' ', x'202020'), +(9, '好好bar好好', '好好bar好好', null, x''), +(10, 'bar', 'bar', 'bar', x'626172'), +(11, 'x', 'x', 'x', x'78'), +(12, 'ff', 'ff', 'ff', x'20ff20'), +(13, null, null, null, x'20ff7820'), +(14, null, null, null, x'00207820'); +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(c) = 'x' order by id; +id estRows task access object operator info +TableReader 8000.00 root data:Projection +└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id + └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c), "x") + └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim('xy' from c) = 'bar' order by id; +id estRows task access object operator info +TableReader 8000.00 root data:Projection +└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id + └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c, "xy"), "bar") + └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(leading 'xy' from c) = 'barxy' order by id; +id estRows task access object operator info +TableReader 8000.00 root data:Projection +└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id + └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c, "xy", 2), "barxy") + └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(trailing 'xy' from c) = 'xybar' order by id; +id estRows task access object operator info +TableReader 8000.00 root data:Projection +└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id + └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c, "xy", 3), "xybar") + └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(both 'xy' from c) = 'bar' order by id; +id estRows task access object operator info +TableReader 8000.00 root data:Projection +└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id + └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c, "xy", 1), "bar") + └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(c) is null order by id; +id estRows task access object operator info +TableReader 8000.00 root data:Projection +└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id + └─Selection 8000.00 cop[tikv] isnull(trim(expression__builtin.t_trim_pushdown.c)) + └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(c) = '' order by id; +id estRows task access object operator info +TableReader 8000.00 root data:Projection +└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id + └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c), "") + └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim('' from c) = 'bar' order by id; +id estRows task access object operator info +TableReader 8000.00 root data:Projection +└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id + └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c, ""), "bar") + └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim('xy' from c) = 'x' order by id; +id estRows task access object operator info +TableReader 8000.00 root data:Projection +└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id + └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c, "xy"), "x") + └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim('xy' from c) is null order by id; +id estRows task access object operator info +TableReader 8000.00 root data:Projection +└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id + └─Selection 8000.00 cop[tikv] isnull(trim(expression__builtin.t_trim_pushdown.c, "xy")) + └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(c_ascii) = 'x' order by id; +id estRows task access object operator info +TableReader 8000.00 root data:Projection +└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id + └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c_ascii), "x") + └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(vb) = x'' order by id; +id estRows task access object operator info +TableReader 8000.00 root data:Projection +└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id + └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.vb), "") + └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(vb) = x'ff78' order by id; +id estRows task access object operator info +TableReader 8000.00 root data:Projection +└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id + └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.vb), "0xff78") + └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(vb) = x'002078' order by id; +id estRows task access object operator info +TableReader 8000.00 root data:Projection +└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id + └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.vb), "0x002078") + └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(c) = 'x' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(c) = 'x' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, +ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, +ifnull((select group_concat(id order by id) from trim_push_on), '') = +ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +push_on push_off same +1,11 1,11 1 +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim('xy' from c) = 'bar' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim('xy' from c) = 'bar' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, +ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, +ifnull((select group_concat(id order by id) from trim_push_on), '') = +ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +push_on push_off same +2,3,4,5,10 2,3,4,5,10 1 +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(leading 'xy' from c) = 'barxy' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(leading 'xy' from c) = 'barxy' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, +ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, +ifnull((select group_concat(id order by id) from trim_push_on), '') = +ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +push_on push_off same +2,3 2,3 1 +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(trailing 'xy' from c) = 'xybar' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(trailing 'xy' from c) = 'xybar' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, +ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, +ifnull((select group_concat(id order by id) from trim_push_on), '') = +ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +push_on push_off same +2,4 2,4 1 +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(both 'xy' from c) = 'bar' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(both 'xy' from c) = 'bar' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, +ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, +ifnull((select group_concat(id order by id) from trim_push_on), '') = +ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +push_on push_off same +2,3,4,5,10 2,3,4,5,10 1 +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(c) is null order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(c) is null order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, +ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, +ifnull((select group_concat(id order by id) from trim_push_on), '') = +ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +push_on push_off same +7,13,14 7,13,14 1 +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(c) = '' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(c) = '' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, +ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, +ifnull((select group_concat(id order by id) from trim_push_on), '') = +ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +push_on push_off same +6,8 6,8 1 +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim('' from c) = 'bar' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim('' from c) = 'bar' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, +ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, +ifnull((select group_concat(id order by id) from trim_push_on), '') = +ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +push_on push_off same +10 10 1 +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim('xy' from c) = 'x' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim('xy' from c) = 'x' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, +ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, +ifnull((select group_concat(id order by id) from trim_push_on), '') = +ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +push_on push_off same +11 11 1 +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim('xy' from c) is null order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim('xy' from c) is null order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, +ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, +ifnull((select group_concat(id order by id) from trim_push_on), '') = +ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +push_on push_off same +7,13,14 7,13,14 1 +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(c_ascii) = 'x' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(c_ascii) = 'x' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, +ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, +ifnull((select group_concat(id order by id) from trim_push_on), '') = +ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +push_on push_off same +1,11 1,11 1 +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(vb) = x'' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(vb) = x'' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, +ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, +ifnull((select group_concat(id order by id) from trim_push_on), '') = +ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +push_on push_off same +6,8,9 6,8,9 1 +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim('好' from c_bin) = 'bar' and c_bin like '%好%' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim('好' from c_bin) = 'bar' and c_bin like '%好%' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, +ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, +ifnull((select group_concat(id order by id) from trim_push_on), '') = +ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +push_on push_off same +9 9 1 +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(vb) = x'ff' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(vb) = x'ff' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, +ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, +ifnull((select group_concat(id order by id) from trim_push_on), '') = +ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +push_on push_off same +12 12 1 +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(vb) = x'ff78' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(vb) = x'ff78' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, +ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, +ifnull((select group_concat(id order by id) from trim_push_on), '') = +ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +push_on push_off same +13 13 1 +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(vb) = x'002078' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(vb) = x'002078' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, +ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, +ifnull((select group_concat(id order by id) from trim_push_on), '') = +ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +push_on push_off same +14 14 1 +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +drop table if exists t_trim_pushdown; drop table if exists t; create table t(a char(20), b int, c double, d datetime, e time, f binary(5)); insert into t values('www.pingcap.com', 12345, 123.45, "2017-01-01 12:01:01", "12:01:01", "HelLo"); diff --git a/tests/integrationtest/t/expression/builtin.test b/tests/integrationtest/t/expression/builtin.test index 87600121dfda7..473771a5ea650 100644 --- a/tests/integrationtest/t/expression/builtin.test +++ b/tests/integrationtest/t/expression/builtin.test @@ -870,6 +870,270 @@ select hex(trim('\t bar\n ')), hex(trim(' \rbar \t')); select hex(trim(leading from ' bar')), hex(trim('x' from 'xxxbarxxx')), hex(trim('x' from 'bar')), hex(trim('' from ' bar ')); select hex(trim('')), hex(trim('x' from '')); select hex(trim(null from 'bar')), hex(trim('x' from null)), hex(trim(null)), hex(trim(leading null from 'bar')); +drop table if exists t_trim_pushdown; +create table t_trim_pushdown( + id int primary key, + c varchar(64) charset utf8mb4 collate utf8mb4_general_ci, + c_bin varchar(64) charset utf8mb4 collate utf8mb4_bin, + c_ascii varchar(64) charset ascii collate ascii_bin, + vb varbinary(64) +); +insert into t_trim_pushdown values + (1, ' x ', ' x ', ' x ', x'207820'), + (2, 'xybarxy', 'xybarxy', 'xybarxy', x'20787920'), + (3, 'xyxybarxy', 'xyxybarxy', 'xyxybarxy', x'2078797820'), + (4, 'xybarxyxy', 'xybarxyxy', 'xybarxyxy', x'207879787920'), + (5, 'xyxybarxyxy', 'xyxybarxyxy', 'xyxybarxyxy', x'207879787920'), + (6, '', '', '', x''), + (7, null, null, null, null), + (8, ' ', ' ', ' ', x'202020'), + (9, '好好bar好好', '好好bar好好', null, x''), + (10, 'bar', 'bar', 'bar', x'626172'), + (11, 'x', 'x', 'x', x'78'), + (12, 'ff', 'ff', 'ff', x'20ff20'), + (13, null, null, null, x'20ff7820'), + (14, null, null, null, x'00207820'); +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(c) = 'x' order by id; +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim('xy' from c) = 'bar' order by id; +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(leading 'xy' from c) = 'barxy' order by id; +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(trailing 'xy' from c) = 'xybar' order by id; +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(both 'xy' from c) = 'bar' order by id; +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(c) is null order by id; +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(c) = '' order by id; +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim('' from c) = 'bar' order by id; +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim('xy' from c) = 'x' order by id; +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim('xy' from c) is null order by id; +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(c_ascii) = 'x' order by id; +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(vb) = x'' order by id; +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(vb) = x'ff78' order by id; +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(vb) = x'002078' order by id; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(c) = 'x' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(c) = 'x' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, + ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, + ifnull((select group_concat(id order by id) from trim_push_on), '') = + ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim('xy' from c) = 'bar' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim('xy' from c) = 'bar' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, + ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, + ifnull((select group_concat(id order by id) from trim_push_on), '') = + ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(leading 'xy' from c) = 'barxy' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(leading 'xy' from c) = 'barxy' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, + ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, + ifnull((select group_concat(id order by id) from trim_push_on), '') = + ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(trailing 'xy' from c) = 'xybar' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(trailing 'xy' from c) = 'xybar' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, + ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, + ifnull((select group_concat(id order by id) from trim_push_on), '') = + ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(both 'xy' from c) = 'bar' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(both 'xy' from c) = 'bar' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, + ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, + ifnull((select group_concat(id order by id) from trim_push_on), '') = + ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(c) is null order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(c) is null order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, + ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, + ifnull((select group_concat(id order by id) from trim_push_on), '') = + ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(c) = '' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(c) = '' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, + ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, + ifnull((select group_concat(id order by id) from trim_push_on), '') = + ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim('' from c) = 'bar' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim('' from c) = 'bar' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, + ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, + ifnull((select group_concat(id order by id) from trim_push_on), '') = + ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim('xy' from c) = 'x' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim('xy' from c) = 'x' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, + ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, + ifnull((select group_concat(id order by id) from trim_push_on), '') = + ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim('xy' from c) is null order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim('xy' from c) is null order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, + ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, + ifnull((select group_concat(id order by id) from trim_push_on), '') = + ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(c_ascii) = 'x' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(c_ascii) = 'x' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, + ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, + ifnull((select group_concat(id order by id) from trim_push_on), '') = + ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(vb) = x'' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(vb) = x'' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, + ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, + ifnull((select group_concat(id order by id) from trim_push_on), '') = + ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim('好' from c_bin) = 'bar' and c_bin like '%好%' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim('好' from c_bin) = 'bar' and c_bin like '%好%' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, + ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, + ifnull((select group_concat(id order by id) from trim_push_on), '') = + ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(vb) = x'ff' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(vb) = x'ff' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, + ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, + ifnull((select group_concat(id order by id) from trim_push_on), '') = + ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(vb) = x'ff78' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(vb) = x'ff78' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, + ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, + ifnull((select group_concat(id order by id) from trim_push_on), '') = + ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +create temporary table trim_push_on(id int primary key); +insert into trim_push_on select id from t_trim_pushdown where trim(vb) = x'002078' order by id; +insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); +admin reload expr_pushdown_blacklist; +create temporary table trim_push_off(id int primary key); +insert into trim_push_off select id from t_trim_pushdown where trim(vb) = x'002078' order by id; +select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, + ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, + ifnull((select group_concat(id order by id) from trim_push_on), '') = + ifnull((select group_concat(id order by id) from trim_push_off), '') as same; +drop temporary table trim_push_on; +drop temporary table trim_push_off; +delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; +admin reload expr_pushdown_blacklist; +drop table if exists t_trim_pushdown; drop table if exists t; create table t(a char(20), b int, c double, d datetime, e time, f binary(5)); insert into t values('www.pingcap.com', 12345, 123.45, "2017-01-01 12:01:01", "12:01:01", "HelLo"); @@ -1672,4 +1936,4 @@ set sql_mode = default; # Issue 59420 SELECT GET_FORMAT(TIME, 'usa'), GET_FORMAT(TIME, 'USA'), GET_FORMAT(TIME, 'UsA'), GET_FORMAT(time, 'UsA'), GET_FORMAT(TIme, 'UsA'); -SELECT GET_FORMAT(DATE, 'jis'),GET_FORMAT(DATETIME, 'iso'),GET_FORMAT(TIMESTAMP, 'eur'),GET_FORMAT(TIME, 'internal'); \ No newline at end of file +SELECT GET_FORMAT(DATE, 'jis'),GET_FORMAT(DATETIME, 'iso'),GET_FORMAT(TIMESTAMP, 'eur'),GET_FORMAT(TIME, 'internal'); diff --git a/tests/realtikvtest/pushdowntest/BUILD.bazel b/tests/realtikvtest/pushdowntest/BUILD.bazel index 491a2f4fe02e3..b38a44bdc0aca 100644 --- a/tests/realtikvtest/pushdowntest/BUILD.bazel +++ b/tests/realtikvtest/pushdowntest/BUILD.bazel @@ -9,7 +9,7 @@ go_test( "main_test.go", ], flaky = True, - shard_count = 4, + shard_count = 5, deps = [ "//pkg/testkit", "//pkg/util/logutil", diff --git a/tests/realtikvtest/pushdowntest/expr_test.go b/tests/realtikvtest/pushdowntest/expr_test.go index 110d240b8da43..8583950ec49b0 100644 --- a/tests/realtikvtest/pushdowntest/expr_test.go +++ b/tests/realtikvtest/pushdowntest/expr_test.go @@ -15,6 +15,7 @@ package pushdowntest import ( + "strings" "testing" "github.com/pingcap/tidb/pkg/testkit" @@ -34,3 +35,163 @@ func TestBitCastInTiKV(t *testing.T) { err := tk.QueryToErr("select a from t1 where false not like convert(a, char)") require.EqualError(t, err, "[tikv:3854]Cannot convert string '\\xFF\\xFF\\xFF' from binary to utf8mb4") } + +func TestTrimPushDownToTiKV(t *testing.T) { + store := realtikvtest.CreateMockStoreAndSetup(t) + tk := testkit.NewTestKit(t, store) + resetTrimPushdownBlacklist := func() { + tk.MustExec("delete from mysql.expr_pushdown_blacklist where name='trim' and store_type='tikv' and reason='for trim realtikv test'") + tk.MustExec("admin reload expr_pushdown_blacklist") + } + checkTrimExplainPushed := func(sql string) { + rows := tk.MustQuery("explain analyze format='brief' " + sql).Rows() + found := false + for _, row := range rows { + op, ok := row[0].(string) + require.True(t, ok, sql) + task, ok := row[3].(string) + require.True(t, ok, sql) + info, ok := row[6].(string) + require.True(t, ok, sql) + if strings.Contains(op, "Selection") && task == "cop[tikv]" && strings.Contains(info, "trim(") { + found = true + break + } + } + require.True(t, found, sql) + } + checkTrimResultConsistency := func(sql string, expected []string) { + resetTrimPushdownBlacklist() + rowsOn := tk.MustQuery(sql).Rows() + require.EqualValues(t, testkit.Rows(expected...), rowsOn, sql) + + tk.MustExec("insert into mysql.expr_pushdown_blacklist values('trim', 'tikv', 'for trim realtikv test')") + tk.MustExec("admin reload expr_pushdown_blacklist") + + rowsOff := tk.MustQuery(sql).Rows() + require.EqualValues(t, rowsOn, rowsOff, sql) + } + + tk.MustExec("use test") + tk.MustExec("drop table if exists t_trim_pushdown") + t.Cleanup(func() { + resetTrimPushdownBlacklist() + tk.MustExec("drop table if exists t_trim_pushdown") + }) + + tk.MustExec(`create table t_trim_pushdown( + id int primary key, + c varchar(64) charset utf8mb4 collate utf8mb4_general_ci, + c_bin varchar(64) charset utf8mb4 collate utf8mb4_bin, + c_ascii varchar(64) charset ascii collate ascii_bin, + vb varbinary(64) + )`) + tk.MustExec(`insert into t_trim_pushdown values + (1, ' x ', ' x ', ' x ', x'207820'), + (2, 'xybarxy', 'xybarxy', 'xybarxy', x'20787920'), + (3, 'xyxybarxy', 'xyxybarxy', 'xyxybarxy', x'2078797820'), + (4, 'xybarxyxy', 'xybarxyxy', 'xybarxyxy', x'207879787920'), + (5, 'xyxybarxyxy', 'xyxybarxyxy', 'xyxybarxyxy', x'207879787920'), + (6, '', '', '', x''), + (7, null, null, null, null), + (8, ' ', ' ', ' ', x'202020'), + (9, '好好bar好好', '好好bar好好', null, x''), + (10, 'bar', 'bar', 'bar', x'626172'), + (11, 'x', 'x', 'x', x'78'), + (12, 'ff', 'ff', 'ff', x'20ff20'), + (13, null, null, null, x'20ff7820'), + (14, null, null, null, x'00207820')`) + + explainCases := []string{ + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(c) = 'x'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim('xy' from c) = 'bar'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(leading 'xy' from c) = 'barxy'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(trailing 'xy' from c) = 'xybar'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(both 'xy' from c) = 'bar'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(c) is null", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(c) = ''", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim('' from c) = 'bar'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim('xy' from c) = 'x'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim('xy' from c) is null", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(c_ascii) = 'x'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(vb) = x''", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(vb) = x'ff78'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(vb) = x'002078'", + } + for _, sql := range explainCases { + checkTrimExplainPushed(sql) + } + + resultCases := []struct { + sql string + expected []string + }{ + { + sql: "select id from t_trim_pushdown where trim(c) = 'x' order by id", + expected: []string{"1", "11"}, + }, + { + sql: "select id from t_trim_pushdown where trim('xy' from c) = 'bar' order by id", + expected: []string{"2", "3", "4", "5", "10"}, + }, + { + sql: "select id from t_trim_pushdown where trim(leading 'xy' from c) = 'barxy' order by id", + expected: []string{"2", "3"}, + }, + { + sql: "select id from t_trim_pushdown where trim(trailing 'xy' from c) = 'xybar' order by id", + expected: []string{"2", "4"}, + }, + { + sql: "select id from t_trim_pushdown where trim(both 'xy' from c) = 'bar' order by id", + expected: []string{"2", "3", "4", "5", "10"}, + }, + { + sql: "select id from t_trim_pushdown where trim(c) = '' order by id", + expected: []string{"6", "8"}, + }, + { + sql: "select id from t_trim_pushdown where trim('' from c) = 'bar' order by id", + expected: []string{"10"}, + }, + { + sql: "select id from t_trim_pushdown where trim('xy' from c) = 'x' order by id", + expected: []string{"11"}, + }, + { + sql: "select id from t_trim_pushdown where trim('xy' from c) is null order by id", + expected: []string{"7", "13", "14"}, + }, + { + sql: "select id from t_trim_pushdown where trim(c_ascii) = 'x' order by id", + expected: []string{"1", "11"}, + }, + { + sql: "select id from t_trim_pushdown where trim(vb) = x'' order by id", + expected: []string{"6", "8", "9"}, + }, + { + sql: "select id from t_trim_pushdown where trim('好' from c_bin) = 'bar' and c_bin like '%好%' order by id", + expected: []string{"9"}, + }, + { + sql: "select id from t_trim_pushdown where trim(vb) = x'ff' order by id", + expected: []string{"12"}, + }, + { + sql: "select id from t_trim_pushdown where trim(vb) = x'ff78' order by id", + expected: []string{"13"}, + }, + { + sql: "select id from t_trim_pushdown where trim(vb) = x'002078' order by id", + expected: []string{"14"}, + }, + { + sql: "select id from t_trim_pushdown where trim(c) is null order by id", + expected: []string{"7", "13", "14"}, + }, + } + for _, tc := range resultCases { + checkTrimResultConsistency(tc.sql, tc.expected) + } +} From ef9fcd11bec6f4e5d8d93dfed62e39e5f73fc7d6 Mon Sep 17 00:00:00 2001 From: "muyun.pan" Date: Fri, 10 Apr 2026 18:04:40 +0800 Subject: [PATCH 2/4] test: keep only TRIM overlap regression cases --- pkg/planner/core/integration_test.go | 144 -------- .../r/expression/builtin.result | 326 +----------------- .../integrationtest/t/expression/builtin.test | 233 +------------ tests/realtikvtest/pushdowntest/expr_test.go | 103 +----- 4 files changed, 45 insertions(+), 761 deletions(-) diff --git a/pkg/planner/core/integration_test.go b/pkg/planner/core/integration_test.go index 9bba28c0165ad..6434ad4096d84 100644 --- a/pkg/planner/core/integration_test.go +++ b/pkg/planner/core/integration_test.go @@ -430,150 +430,6 @@ func TestTimeScalarFunctionPushDownResult(t *testing.T) { tk.MustExec("admin reload expr_pushdown_blacklist;") } -func TestTrimPushDownToTiKV(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - tk.MustExec(`create table t( - id int primary key, - c varchar(64) charset utf8mb4 collate utf8mb4_general_ci, - c_bin varchar(64) charset utf8mb4 collate utf8mb4_bin, - c_ascii varchar(64) charset ascii collate ascii_bin, - vb varbinary(64) - );`) - tk.MustExec(`insert into t values - (1, ' x ', ' x ', ' x ', x'207820'), - (2, 'xybarxy', 'xybarxy', 'xybarxy', x'20787920'), - (3, 'xyxybarxy', 'xyxybarxy', 'xyxybarxy', x'2078797820'), - (4, 'xybarxyxy', 'xybarxyxy', 'xybarxyxy', x'207879787920'), - (5, 'xyxybarxyxy', 'xyxybarxyxy', 'xyxybarxyxy', x'207879787920'), - (6, '', '', '', x''), - (7, null, null, null, null), - (8, ' ', ' ', ' ', x'202020'), - (9, '好好bar好好', '好好bar好好', null, x''), - (10, 'bar', 'bar', 'bar', x'626172'), - (11, 'x', 'x', 'x', x'78'), - (12, 'ff', 'ff', 'ff', x'20ff20'), - (13, null, null, null, x'20ff7820'), - (14, null, null, null, x'00207820');`) - - resetBlacklist := func() { - tk.MustExec("delete from mysql.expr_pushdown_blacklist where name != 'date_add'") - tk.MustExec("admin reload expr_pushdown_blacklist;") - } - t.Cleanup(resetBlacklist) - resetBlacklist() - - testcases := []struct { - name string - sql string - expected []string - }{ - { - name: "trim_1_arg", - sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(c) = 'x' order by id;", - expected: []string{"1", "11"}, - }, - { - name: "trim_2_args", - sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim('xy' from c) = 'bar' order by id;", - expected: []string{"2", "3", "4", "5", "10"}, - }, - { - name: "trim_leading", - sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(leading 'xy' from c) = 'barxy' order by id;", - expected: []string{"2", "3"}, - }, - { - name: "trim_trailing", - sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(trailing 'xy' from c) = 'xybar' order by id;", - expected: []string{"2", "4"}, - }, - { - name: "trim_both", - sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(both 'xy' from c) = 'bar' order by id;", - expected: []string{"2", "3", "4", "5", "10"}, - }, - { - name: "trim_null_input", - sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(c) is null order by id;", - expected: []string{"7", "13", "14"}, - }, - { - name: "trim_empty_string", - sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(c) = '' order by id;", - expected: []string{"6", "8"}, - }, - { - name: "trim_empty_pattern", - sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim('' from c) = 'bar' order by id;", - expected: []string{"10"}, - }, - { - name: "trim_pattern_longer_than_input", - sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim('xy' from c) = 'x' order by id;", - expected: []string{"11"}, - }, - { - name: "trim_2_args_null_input", - sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim('xy' from c) is null order by id;", - expected: []string{"7", "13", "14"}, - }, - { - name: "trim_multibyte_general_ci", - sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim('好' from c) = 'bar' and c like '%好%' order by id;", - expected: []string{"9"}, - }, - { - name: "trim_multibyte_bin", - sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim('好' from c_bin) = 'bar' and c_bin like '%好%' order by id;", - expected: []string{"9"}, - }, - { - name: "trim_ascii_charset", - sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(c_ascii) = 'x' order by id;", - expected: []string{"1", "11"}, - }, - { - name: "trim_binary_string", - sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(vb) = x'78' order by id;", - expected: []string{"1", "11"}, - }, - { - name: "trim_invalid_utf8_binary", - sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(vb) = x'ff' order by id;", - expected: []string{"12"}, - }, - { - name: "trim_binary_empty_result", - sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(vb) = x'' order by id;", - expected: []string{"6", "8", "9"}, - }, - { - name: "trim_binary_invalid_utf8_middle", - sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(vb) = x'ff78' order by id;", - expected: []string{"13"}, - }, - { - name: "trim_binary_with_nul", - sql: "select /*+read_from_storage(tikv[t])*/ id from t where trim(vb) = x'002078' order by id;", - expected: []string{"14"}, - }, - } - - for _, testcase := range testcases { - resetBlacklist() - r1 := tk.MustQuery(testcase.sql).Rows() - require.EqualValues(t, testkit.Rows(testcase.expected...), r1, testcase.name) - - tk.MustExec("insert into mysql.expr_pushdown_blacklist(name) values('trim');") - tk.MustExec("admin reload expr_pushdown_blacklist;") - r2 := tk.MustQuery(testcase.sql).Rows() - require.EqualValues(t, r1, r2, testcase.name) - } -} - func TestNumberFunctionPushDown(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) diff --git a/tests/integrationtest/r/expression/builtin.result b/tests/integrationtest/r/expression/builtin.result index 3a4fe89162b8d..38fd29f37e0c2 100644 --- a/tests/integrationtest/r/expression/builtin.result +++ b/tests/integrationtest/r/expression/builtin.result @@ -1934,364 +1934,76 @@ NULL NULL NULL NULL drop table if exists t_trim_pushdown; create table t_trim_pushdown( id int primary key, -c varchar(64) charset utf8mb4 collate utf8mb4_general_ci, -c_bin varchar(64) charset utf8mb4 collate utf8mb4_bin, -c_ascii varchar(64) charset ascii collate ascii_bin, -vb varbinary(64) +c varchar(64) charset utf8mb4 collate utf8mb4_general_ci ); insert into t_trim_pushdown values -(1, ' x ', ' x ', ' x ', x'207820'), -(2, 'xybarxy', 'xybarxy', 'xybarxy', x'20787920'), -(3, 'xyxybarxy', 'xyxybarxy', 'xyxybarxy', x'2078797820'), -(4, 'xybarxyxy', 'xybarxyxy', 'xybarxyxy', x'207879787920'), -(5, 'xyxybarxyxy', 'xyxybarxyxy', 'xyxybarxyxy', x'207879787920'), -(6, '', '', '', x''), -(7, null, null, null, null), -(8, ' ', ' ', ' ', x'202020'), -(9, '好好bar好好', '好好bar好好', null, x''), -(10, 'bar', 'bar', 'bar', x'626172'), -(11, 'x', 'x', 'x', x'78'), -(12, 'ff', 'ff', 'ff', x'20ff20'), -(13, null, null, null, x'20ff7820'), -(14, null, null, null, x'00207820'); -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(c) = 'x' order by id; +(1, 'aaaaa'), +(2, 'ppp'), +(3, 'xyxyx'); +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim('aaa' from c) = 'aa' order by id; id estRows task access object operator info TableReader 8000.00 root data:Projection └─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id - └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c), "x") + └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c, "aaa"), "aa") └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim('xy' from c) = 'bar' order by id; +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(both 'pp' from c) = 'p' order by id; id estRows task access object operator info TableReader 8000.00 root data:Projection └─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id - └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c, "xy"), "bar") + └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c, "pp", 1), "p") └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(leading 'xy' from c) = 'barxy' order by id; +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(both 'xyx' from c) = 'yx' order by id; id estRows task access object operator info TableReader 8000.00 root data:Projection └─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id - └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c, "xy", 2), "barxy") + └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c, "xyx", 1), "yx") └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(trailing 'xy' from c) = 'xybar' order by id; -id estRows task access object operator info -TableReader 8000.00 root data:Projection -└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id - └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c, "xy", 3), "xybar") - └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(both 'xy' from c) = 'bar' order by id; -id estRows task access object operator info -TableReader 8000.00 root data:Projection -└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id - └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c, "xy", 1), "bar") - └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(c) is null order by id; -id estRows task access object operator info -TableReader 8000.00 root data:Projection -└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id - └─Selection 8000.00 cop[tikv] isnull(trim(expression__builtin.t_trim_pushdown.c)) - └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(c) = '' order by id; -id estRows task access object operator info -TableReader 8000.00 root data:Projection -└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id - └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c), "") - └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim('' from c) = 'bar' order by id; -id estRows task access object operator info -TableReader 8000.00 root data:Projection -└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id - └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c, ""), "bar") - └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim('xy' from c) = 'x' order by id; -id estRows task access object operator info -TableReader 8000.00 root data:Projection -└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id - └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c, "xy"), "x") - └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim('xy' from c) is null order by id; -id estRows task access object operator info -TableReader 8000.00 root data:Projection -└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id - └─Selection 8000.00 cop[tikv] isnull(trim(expression__builtin.t_trim_pushdown.c, "xy")) - └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(c_ascii) = 'x' order by id; -id estRows task access object operator info -TableReader 8000.00 root data:Projection -└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id - └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.c_ascii), "x") - └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(vb) = x'' order by id; -id estRows task access object operator info -TableReader 8000.00 root data:Projection -└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id - └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.vb), "") - └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(vb) = x'ff78' order by id; -id estRows task access object operator info -TableReader 8000.00 root data:Projection -└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id - └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.vb), "0xff78") - └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(vb) = x'002078' order by id; -id estRows task access object operator info -TableReader 8000.00 root data:Projection -└─Projection 8000.00 cop[tikv] expression__builtin.t_trim_pushdown.id - └─Selection 8000.00 cop[tikv] eq(trim(expression__builtin.t_trim_pushdown.vb), "0x002078") - └─TableFullScan 10000.00 cop[tikv] table:t_trim_pushdown keep order:true, stats:pseudo -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(c) = 'x' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(c) = 'x' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, -ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, -ifnull((select group_concat(id order by id) from trim_push_on), '') = -ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -push_on push_off same -1,11 1,11 1 -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim('xy' from c) = 'bar' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim('xy' from c) = 'bar' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, -ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, -ifnull((select group_concat(id order by id) from trim_push_on), '') = -ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -push_on push_off same -2,3,4,5,10 2,3,4,5,10 1 -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(leading 'xy' from c) = 'barxy' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(leading 'xy' from c) = 'barxy' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, -ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, -ifnull((select group_concat(id order by id) from trim_push_on), '') = -ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -push_on push_off same -2,3 2,3 1 -drop temporary table trim_push_on; -drop temporary table trim_push_off; delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; admin reload expr_pushdown_blacklist; create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(trailing 'xy' from c) = 'xybar' order by id; +insert into trim_push_on select id from t_trim_pushdown where trim('aaa' from c) = 'aa' order by id; insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); admin reload expr_pushdown_blacklist; create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(trailing 'xy' from c) = 'xybar' order by id; +insert into trim_push_off select id from t_trim_pushdown where trim('aaa' from c) = 'aa' order by id; select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, ifnull((select group_concat(id order by id) from trim_push_on), '') = ifnull((select group_concat(id order by id) from trim_push_off), '') as same; push_on push_off same -2,4 2,4 1 -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(both 'xy' from c) = 'bar' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(both 'xy' from c) = 'bar' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, -ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, -ifnull((select group_concat(id order by id) from trim_push_on), '') = -ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -push_on push_off same -2,3,4,5,10 2,3,4,5,10 1 -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(c) is null order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(c) is null order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, -ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, -ifnull((select group_concat(id order by id) from trim_push_on), '') = -ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -push_on push_off same -7,13,14 7,13,14 1 -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(c) = '' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(c) = '' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, -ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, -ifnull((select group_concat(id order by id) from trim_push_on), '') = -ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -push_on push_off same -6,8 6,8 1 -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim('' from c) = 'bar' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim('' from c) = 'bar' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, -ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, -ifnull((select group_concat(id order by id) from trim_push_on), '') = -ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -push_on push_off same -10 10 1 -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim('xy' from c) = 'x' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim('xy' from c) = 'x' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, -ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, -ifnull((select group_concat(id order by id) from trim_push_on), '') = -ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -push_on push_off same -11 11 1 -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim('xy' from c) is null order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim('xy' from c) is null order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, -ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, -ifnull((select group_concat(id order by id) from trim_push_on), '') = -ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -push_on push_off same -7,13,14 7,13,14 1 -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(c_ascii) = 'x' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(c_ascii) = 'x' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, -ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, -ifnull((select group_concat(id order by id) from trim_push_on), '') = -ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -push_on push_off same -1,11 1,11 1 -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(vb) = x'' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(vb) = x'' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, -ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, -ifnull((select group_concat(id order by id) from trim_push_on), '') = -ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -push_on push_off same -6,8,9 6,8,9 1 -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim('好' from c_bin) = 'bar' and c_bin like '%好%' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim('好' from c_bin) = 'bar' and c_bin like '%好%' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, -ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, -ifnull((select group_concat(id order by id) from trim_push_on), '') = -ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -push_on push_off same -9 9 1 -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(vb) = x'ff' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(vb) = x'ff' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, -ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, -ifnull((select group_concat(id order by id) from trim_push_on), '') = -ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -push_on push_off same -12 12 1 +1 1 1 drop temporary table trim_push_on; drop temporary table trim_push_off; delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; admin reload expr_pushdown_blacklist; create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(vb) = x'ff78' order by id; +insert into trim_push_on select id from t_trim_pushdown where trim(both 'pp' from c) = 'p' order by id; insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); admin reload expr_pushdown_blacklist; create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(vb) = x'ff78' order by id; +insert into trim_push_off select id from t_trim_pushdown where trim(both 'pp' from c) = 'p' order by id; select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, ifnull((select group_concat(id order by id) from trim_push_on), '') = ifnull((select group_concat(id order by id) from trim_push_off), '') as same; push_on push_off same -13 13 1 +2 2 1 drop temporary table trim_push_on; drop temporary table trim_push_off; delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; admin reload expr_pushdown_blacklist; create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(vb) = x'002078' order by id; +insert into trim_push_on select id from t_trim_pushdown where trim(both 'xyx' from c) = 'yx' order by id; insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); admin reload expr_pushdown_blacklist; create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(vb) = x'002078' order by id; +insert into trim_push_off select id from t_trim_pushdown where trim(both 'xyx' from c) = 'yx' order by id; select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, ifnull((select group_concat(id order by id) from trim_push_on), '') = ifnull((select group_concat(id order by id) from trim_push_off), '') as same; push_on push_off same -14 14 1 +3 3 1 drop temporary table trim_push_on; drop temporary table trim_push_off; delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; diff --git a/tests/integrationtest/t/expression/builtin.test b/tests/integrationtest/t/expression/builtin.test index 473771a5ea650..f6e566b01ea7f 100644 --- a/tests/integrationtest/t/expression/builtin.test +++ b/tests/integrationtest/t/expression/builtin.test @@ -873,48 +873,23 @@ select hex(trim(null from 'bar')), hex(trim('x' from null)), hex(trim(null)), he drop table if exists t_trim_pushdown; create table t_trim_pushdown( id int primary key, - c varchar(64) charset utf8mb4 collate utf8mb4_general_ci, - c_bin varchar(64) charset utf8mb4 collate utf8mb4_bin, - c_ascii varchar(64) charset ascii collate ascii_bin, - vb varbinary(64) + c varchar(64) charset utf8mb4 collate utf8mb4_general_ci ); insert into t_trim_pushdown values - (1, ' x ', ' x ', ' x ', x'207820'), - (2, 'xybarxy', 'xybarxy', 'xybarxy', x'20787920'), - (3, 'xyxybarxy', 'xyxybarxy', 'xyxybarxy', x'2078797820'), - (4, 'xybarxyxy', 'xybarxyxy', 'xybarxyxy', x'207879787920'), - (5, 'xyxybarxyxy', 'xyxybarxyxy', 'xyxybarxyxy', x'207879787920'), - (6, '', '', '', x''), - (7, null, null, null, null), - (8, ' ', ' ', ' ', x'202020'), - (9, '好好bar好好', '好好bar好好', null, x''), - (10, 'bar', 'bar', 'bar', x'626172'), - (11, 'x', 'x', 'x', x'78'), - (12, 'ff', 'ff', 'ff', x'20ff20'), - (13, null, null, null, x'20ff7820'), - (14, null, null, null, x'00207820'); -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(c) = 'x' order by id; -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim('xy' from c) = 'bar' order by id; -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(leading 'xy' from c) = 'barxy' order by id; -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(trailing 'xy' from c) = 'xybar' order by id; -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(both 'xy' from c) = 'bar' order by id; -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(c) is null order by id; -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(c) = '' order by id; -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim('' from c) = 'bar' order by id; -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim('xy' from c) = 'x' order by id; -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim('xy' from c) is null order by id; -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(c_ascii) = 'x' order by id; -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(vb) = x'' order by id; -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(vb) = x'ff78' order by id; -explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(vb) = x'002078' order by id; + (1, 'aaaaa'), + (2, 'ppp'), + (3, 'xyxyx'); +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim('aaa' from c) = 'aa' order by id; +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(both 'pp' from c) = 'p' order by id; +explain format = 'brief' select /*+ read_from_storage(tikv[t_trim_pushdown]) */ id from t_trim_pushdown where trim(both 'xyx' from c) = 'yx' order by id; delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; admin reload expr_pushdown_blacklist; create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(c) = 'x' order by id; +insert into trim_push_on select id from t_trim_pushdown where trim('aaa' from c) = 'aa' order by id; insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); admin reload expr_pushdown_blacklist; create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(c) = 'x' order by id; +insert into trim_push_off select id from t_trim_pushdown where trim('aaa' from c) = 'aa' order by id; select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, ifnull((select group_concat(id order by id) from trim_push_on), '') = @@ -924,11 +899,11 @@ drop temporary table trim_push_off; delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; admin reload expr_pushdown_blacklist; create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim('xy' from c) = 'bar' order by id; +insert into trim_push_on select id from t_trim_pushdown where trim(both 'pp' from c) = 'p' order by id; insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); admin reload expr_pushdown_blacklist; create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim('xy' from c) = 'bar' order by id; +insert into trim_push_off select id from t_trim_pushdown where trim(both 'pp' from c) = 'p' order by id; select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, ifnull((select group_concat(id order by id) from trim_push_on), '') = @@ -938,193 +913,11 @@ drop temporary table trim_push_off; delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; admin reload expr_pushdown_blacklist; create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(leading 'xy' from c) = 'barxy' order by id; +insert into trim_push_on select id from t_trim_pushdown where trim(both 'xyx' from c) = 'yx' order by id; insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); admin reload expr_pushdown_blacklist; create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(leading 'xy' from c) = 'barxy' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, - ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, - ifnull((select group_concat(id order by id) from trim_push_on), '') = - ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(trailing 'xy' from c) = 'xybar' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(trailing 'xy' from c) = 'xybar' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, - ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, - ifnull((select group_concat(id order by id) from trim_push_on), '') = - ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(both 'xy' from c) = 'bar' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(both 'xy' from c) = 'bar' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, - ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, - ifnull((select group_concat(id order by id) from trim_push_on), '') = - ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(c) is null order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(c) is null order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, - ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, - ifnull((select group_concat(id order by id) from trim_push_on), '') = - ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(c) = '' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(c) = '' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, - ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, - ifnull((select group_concat(id order by id) from trim_push_on), '') = - ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim('' from c) = 'bar' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim('' from c) = 'bar' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, - ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, - ifnull((select group_concat(id order by id) from trim_push_on), '') = - ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim('xy' from c) = 'x' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim('xy' from c) = 'x' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, - ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, - ifnull((select group_concat(id order by id) from trim_push_on), '') = - ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim('xy' from c) is null order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim('xy' from c) is null order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, - ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, - ifnull((select group_concat(id order by id) from trim_push_on), '') = - ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(c_ascii) = 'x' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(c_ascii) = 'x' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, - ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, - ifnull((select group_concat(id order by id) from trim_push_on), '') = - ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(vb) = x'' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(vb) = x'' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, - ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, - ifnull((select group_concat(id order by id) from trim_push_on), '') = - ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim('好' from c_bin) = 'bar' and c_bin like '%好%' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim('好' from c_bin) = 'bar' and c_bin like '%好%' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, - ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, - ifnull((select group_concat(id order by id) from trim_push_on), '') = - ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(vb) = x'ff' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(vb) = x'ff' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, - ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, - ifnull((select group_concat(id order by id) from trim_push_on), '') = - ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(vb) = x'ff78' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(vb) = x'ff78' order by id; -select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, - ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, - ifnull((select group_concat(id order by id) from trim_push_on), '') = - ifnull((select group_concat(id order by id) from trim_push_off), '') as same; -drop temporary table trim_push_on; -drop temporary table trim_push_off; -delete from mysql.expr_pushdown_blacklist where name = 'trim' and store_type = 'tikv,tiflash,tidb' and reason = 'for trim pushdown test'; -admin reload expr_pushdown_blacklist; -create temporary table trim_push_on(id int primary key); -insert into trim_push_on select id from t_trim_pushdown where trim(vb) = x'002078' order by id; -insert into mysql.expr_pushdown_blacklist values('trim', 'tikv,tiflash,tidb', 'for trim pushdown test'); -admin reload expr_pushdown_blacklist; -create temporary table trim_push_off(id int primary key); -insert into trim_push_off select id from t_trim_pushdown where trim(vb) = x'002078' order by id; +insert into trim_push_off select id from t_trim_pushdown where trim(both 'xyx' from c) = 'yx' order by id; select ifnull((select group_concat(id order by id) from trim_push_on), '') as push_on, ifnull((select group_concat(id order by id) from trim_push_off), '') as push_off, ifnull((select group_concat(id order by id) from trim_push_on), '') = diff --git a/tests/realtikvtest/pushdowntest/expr_test.go b/tests/realtikvtest/pushdowntest/expr_test.go index 8583950ec49b0..4632e0a9052c1 100644 --- a/tests/realtikvtest/pushdowntest/expr_test.go +++ b/tests/realtikvtest/pushdowntest/expr_test.go @@ -81,42 +81,17 @@ func TestTrimPushDownToTiKV(t *testing.T) { tk.MustExec(`create table t_trim_pushdown( id int primary key, - c varchar(64) charset utf8mb4 collate utf8mb4_general_ci, - c_bin varchar(64) charset utf8mb4 collate utf8mb4_bin, - c_ascii varchar(64) charset ascii collate ascii_bin, - vb varbinary(64) + c varchar(64) charset utf8mb4 collate utf8mb4_general_ci )`) tk.MustExec(`insert into t_trim_pushdown values - (1, ' x ', ' x ', ' x ', x'207820'), - (2, 'xybarxy', 'xybarxy', 'xybarxy', x'20787920'), - (3, 'xyxybarxy', 'xyxybarxy', 'xyxybarxy', x'2078797820'), - (4, 'xybarxyxy', 'xybarxyxy', 'xybarxyxy', x'207879787920'), - (5, 'xyxybarxyxy', 'xyxybarxyxy', 'xyxybarxyxy', x'207879787920'), - (6, '', '', '', x''), - (7, null, null, null, null), - (8, ' ', ' ', ' ', x'202020'), - (9, '好好bar好好', '好好bar好好', null, x''), - (10, 'bar', 'bar', 'bar', x'626172'), - (11, 'x', 'x', 'x', x'78'), - (12, 'ff', 'ff', 'ff', x'20ff20'), - (13, null, null, null, x'20ff7820'), - (14, null, null, null, x'00207820')`) + (1, 'aaaaa'), + (2, 'ppp'), + (3, 'xyxyx')`) explainCases := []string{ - "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(c) = 'x'", - "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim('xy' from c) = 'bar'", - "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(leading 'xy' from c) = 'barxy'", - "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(trailing 'xy' from c) = 'xybar'", - "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(both 'xy' from c) = 'bar'", - "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(c) is null", - "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(c) = ''", - "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim('' from c) = 'bar'", - "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim('xy' from c) = 'x'", - "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim('xy' from c) is null", - "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(c_ascii) = 'x'", - "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(vb) = x''", - "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(vb) = x'ff78'", - "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(vb) = x'002078'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim('aaa' from c) = 'aa'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(both 'pp' from c) = 'p'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(both 'xyx' from c) = 'yx'", } for _, sql := range explainCases { checkTrimExplainPushed(sql) @@ -127,68 +102,16 @@ func TestTrimPushDownToTiKV(t *testing.T) { expected []string }{ { - sql: "select id from t_trim_pushdown where trim(c) = 'x' order by id", - expected: []string{"1", "11"}, + sql: "select id from t_trim_pushdown where trim('aaa' from c) = 'aa' order by id", + expected: []string{"1"}, }, { - sql: "select id from t_trim_pushdown where trim('xy' from c) = 'bar' order by id", - expected: []string{"2", "3", "4", "5", "10"}, + sql: "select id from t_trim_pushdown where trim(both 'pp' from c) = 'p' order by id", + expected: []string{"2"}, }, { - sql: "select id from t_trim_pushdown where trim(leading 'xy' from c) = 'barxy' order by id", - expected: []string{"2", "3"}, - }, - { - sql: "select id from t_trim_pushdown where trim(trailing 'xy' from c) = 'xybar' order by id", - expected: []string{"2", "4"}, - }, - { - sql: "select id from t_trim_pushdown where trim(both 'xy' from c) = 'bar' order by id", - expected: []string{"2", "3", "4", "5", "10"}, - }, - { - sql: "select id from t_trim_pushdown where trim(c) = '' order by id", - expected: []string{"6", "8"}, - }, - { - sql: "select id from t_trim_pushdown where trim('' from c) = 'bar' order by id", - expected: []string{"10"}, - }, - { - sql: "select id from t_trim_pushdown where trim('xy' from c) = 'x' order by id", - expected: []string{"11"}, - }, - { - sql: "select id from t_trim_pushdown where trim('xy' from c) is null order by id", - expected: []string{"7", "13", "14"}, - }, - { - sql: "select id from t_trim_pushdown where trim(c_ascii) = 'x' order by id", - expected: []string{"1", "11"}, - }, - { - sql: "select id from t_trim_pushdown where trim(vb) = x'' order by id", - expected: []string{"6", "8", "9"}, - }, - { - sql: "select id from t_trim_pushdown where trim('好' from c_bin) = 'bar' and c_bin like '%好%' order by id", - expected: []string{"9"}, - }, - { - sql: "select id from t_trim_pushdown where trim(vb) = x'ff' order by id", - expected: []string{"12"}, - }, - { - sql: "select id from t_trim_pushdown where trim(vb) = x'ff78' order by id", - expected: []string{"13"}, - }, - { - sql: "select id from t_trim_pushdown where trim(vb) = x'002078' order by id", - expected: []string{"14"}, - }, - { - sql: "select id from t_trim_pushdown where trim(c) is null order by id", - expected: []string{"7", "13", "14"}, + sql: "select id from t_trim_pushdown where trim(both 'xyx' from c) = 'yx' order by id", + expected: []string{"3"}, }, } for _, tc := range resultCases { From 7a41366471364dee8e9a7c78e2fea57611a7905b Mon Sep 17 00:00:00 2001 From: "muyun.pan" Date: Tue, 14 Apr 2026 13:31:10 +0800 Subject: [PATCH 3/4] fix TestTrimPushDownToTiKV --- tests/realtikvtest/pushdowntest/expr_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/realtikvtest/pushdowntest/expr_test.go b/tests/realtikvtest/pushdowntest/expr_test.go index 4632e0a9052c1..2db4ae759c599 100644 --- a/tests/realtikvtest/pushdowntest/expr_test.go +++ b/tests/realtikvtest/pushdowntest/expr_test.go @@ -40,7 +40,7 @@ func TestTrimPushDownToTiKV(t *testing.T) { store := realtikvtest.CreateMockStoreAndSetup(t) tk := testkit.NewTestKit(t, store) resetTrimPushdownBlacklist := func() { - tk.MustExec("delete from mysql.expr_pushdown_blacklist where name='trim' and store_type='tikv' and reason='for trim realtikv test'") + tk.MustExec("delete from mysql.expr_pushdown_blacklist where name='trim'") tk.MustExec("admin reload expr_pushdown_blacklist") } checkTrimExplainPushed := func(sql string) { @@ -78,6 +78,7 @@ func TestTrimPushDownToTiKV(t *testing.T) { resetTrimPushdownBlacklist() tk.MustExec("drop table if exists t_trim_pushdown") }) + resetTrimPushdownBlacklist() tk.MustExec(`create table t_trim_pushdown( id int primary key, From b5382f2aa098ae8f2ad2783f8b887a4e32919a82 Mon Sep 17 00:00:00 2001 From: "muyun.pan" Date: Wed, 15 Apr 2026 16:26:26 +0800 Subject: [PATCH 4/4] add more test items --- tests/realtikvtest/pushdowntest/expr_test.go | 105 ++++++++++++++++++- 1 file changed, 101 insertions(+), 4 deletions(-) diff --git a/tests/realtikvtest/pushdowntest/expr_test.go b/tests/realtikvtest/pushdowntest/expr_test.go index 2db4ae759c599..664d76731faa5 100644 --- a/tests/realtikvtest/pushdowntest/expr_test.go +++ b/tests/realtikvtest/pushdowntest/expr_test.go @@ -82,17 +82,50 @@ func TestTrimPushDownToTiKV(t *testing.T) { tk.MustExec(`create table t_trim_pushdown( id int primary key, - c varchar(64) charset utf8mb4 collate utf8mb4_general_ci + c varchar(64) charset utf8mb4 collate utf8mb4_general_ci, + c_bin varchar(64) charset utf8mb4 collate utf8mb4_bin, + c_ascii varchar(64) charset ascii collate ascii_bin, + vb varbinary(64) )`) tk.MustExec(`insert into t_trim_pushdown values - (1, 'aaaaa'), - (2, 'ppp'), - (3, 'xyxyx')`) + (1, 'aaaaa', 'aaaaa', 'aaaaa', x'207820'), + (2, 'ppp', 'ppp', 'ppp', x'20707020'), + (3, 'xyxyx', 'xyxyx', 'xyxyx', x'2078797820'), + (4, ' x ', ' x ', ' x ', x'207820'), + (5, 'xybarxy', 'xybarxy', 'xybarxy', x'20787920'), + (6, 'xyxybarxy', 'xyxybarxy', 'xyxybarxy', x'2078797820'), + (7, 'xybarxyxy', 'xybarxyxy', 'xybarxyxy', x'207879787920'), + (8, 'xyxybarxyxy', 'xyxybarxyxy', 'xyxybarxyxy', x'207879787920'), + (9, '', '', '', x''), + (10, null, null, null, null), + (11, ' ', ' ', ' ', x'202020'), + (12, '好好bar好好', '好好bar好好', null, x''), + (13, 'bar', 'bar', 'bar', x'626172'), + (14, 'x', 'x', 'x', x'78'), + (15, 'ff', 'ff', 'ff', x'20ff20'), + (16, null, null, null, x'20ff7820'), + (17, null, null, null, x'00207820')`) explainCases := []string{ "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim('aaa' from c) = 'aa'", "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(both 'pp' from c) = 'p'", "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(both 'xyx' from c) = 'yx'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(c) = 'x'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim('xy' from c) = 'bar'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(leading 'xy' from c) = 'barxy'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(trailing 'xy' from c) = 'xybar'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(both 'xy' from c) = 'bar'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(c) is null", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(c) = ''", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim('' from c) = 'bar'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim('xy' from c) = 'x'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim('xy' from c) is null", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(c_ascii) = 'x'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(vb) = x''", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim('好' from c_bin) = 'bar' and c_bin like '%好%'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(vb) = x'ff'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(vb) = x'ff78'", + "select /*+ read_from_storage(tikv[t_trim_pushdown]) */ * from t_trim_pushdown where trim(vb) = x'002078'", } for _, sql := range explainCases { checkTrimExplainPushed(sql) @@ -114,6 +147,70 @@ func TestTrimPushDownToTiKV(t *testing.T) { sql: "select id from t_trim_pushdown where trim(both 'xyx' from c) = 'yx' order by id", expected: []string{"3"}, }, + { + sql: "select id from t_trim_pushdown where trim(c) = 'x' order by id", + expected: []string{"4", "14"}, + }, + { + sql: "select id from t_trim_pushdown where trim('xy' from c) = 'bar' order by id", + expected: []string{"5", "6", "7", "8", "13"}, + }, + { + sql: "select id from t_trim_pushdown where trim(leading 'xy' from c) = 'barxy' order by id", + expected: []string{"5", "6"}, + }, + { + sql: "select id from t_trim_pushdown where trim(trailing 'xy' from c) = 'xybar' order by id", + expected: []string{"5", "7"}, + }, + { + sql: "select id from t_trim_pushdown where trim(both 'xy' from c) = 'bar' order by id", + expected: []string{"5", "6", "7", "8", "13"}, + }, + { + sql: "select id from t_trim_pushdown where trim(c) = '' order by id", + expected: []string{"9", "11"}, + }, + { + sql: "select id from t_trim_pushdown where trim('' from c) = 'bar' order by id", + expected: []string{"13"}, + }, + { + sql: "select id from t_trim_pushdown where trim('xy' from c) = 'x' order by id", + expected: []string{"3", "14"}, + }, + { + sql: "select id from t_trim_pushdown where trim('xy' from c) is null order by id", + expected: []string{"10", "16", "17"}, + }, + { + sql: "select id from t_trim_pushdown where trim(c_ascii) = 'x' order by id", + expected: []string{"4", "14"}, + }, + { + sql: "select id from t_trim_pushdown where trim(vb) = x'' order by id", + expected: []string{"9", "11", "12"}, + }, + { + sql: "select id from t_trim_pushdown where trim('好' from c_bin) = 'bar' and c_bin like '%好%' order by id", + expected: []string{"12"}, + }, + { + sql: "select id from t_trim_pushdown where trim(vb) = x'ff' order by id", + expected: []string{"15"}, + }, + { + sql: "select id from t_trim_pushdown where trim(vb) = x'ff78' order by id", + expected: []string{"16"}, + }, + { + sql: "select id from t_trim_pushdown where trim(vb) = x'002078' order by id", + expected: []string{"17"}, + }, + { + sql: "select id from t_trim_pushdown where trim(c) is null order by id", + expected: []string{"10", "16", "17"}, + }, } for _, tc := range resultCases { checkTrimResultConsistency(tc.sql, tc.expected)