From 850dd8c05ba1e96b992ecffbc6234c62036d2404 Mon Sep 17 00:00:00 2001 From: xzhangxian1008 Date: Thu, 1 Dec 2022 14:34:48 +0800 Subject: [PATCH] init --- expression/expr_to_pb_test.go | 5 +++++ expression/expression.go | 2 +- planner/core/integration_test.go | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/expression/expr_to_pb_test.go b/expression/expr_to_pb_test.go index 5b5a90ed966be..4850c9f41bf42 100644 --- a/expression/expr_to_pb_test.go +++ b/expression/expr_to_pb_test.go @@ -1083,6 +1083,11 @@ func TestExprPushDownToFlash(t *testing.T) { require.NoError(t, err) exprs = append(exprs, function) + // regexp_substr: supported + function, err = NewFunction(mock.NewContext(), ast.RegexpSubstr, types.NewFieldType(mysql.TypeString), stringColumn, stringColumn, intColumn, intColumn, stringColumn) + require.NoError(t, err) + exprs = append(exprs, function) + // greatest function, err = NewFunction(mock.NewContext(), ast.Greatest, types.NewFieldType(mysql.TypeLonglong), int32Column, intColumn) require.NoError(t, err) diff --git a/expression/expression.go b/expression/expression.go index c7e50764910f9..d755f25fd29a4 100644 --- a/expression/expression.go +++ b/expression/expression.go @@ -1165,7 +1165,7 @@ func scalarExprSupportedByFlash(function *ScalarFunction) bool { return false } return true - case ast.Regexp, ast.RegexpLike, ast.RegexpInStr: + case ast.Regexp, ast.RegexpLike, ast.RegexpInStr, ast.RegexpSubstr: funcCharset, funcCollation := function.Function.CharsetAndCollation() if funcCharset == charset.CharsetBin && funcCollation == charset.CollationBin { return false diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index c5e91a6a2eda1..f9c58ace525f8 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -7450,6 +7450,39 @@ func TestRegexpInstrPushDownToTiFlash(t *testing.T) { tk.MustQuery("explain select regexp_instr(expr, pattern, 1, 1, 0, match_type) as res from test.t;").CheckAt([]int{0, 2, 4}, rows) } +func TestRegexpSubstrPushDownToTiFlash(t *testing.T) { + store, dom := testkit.CreateMockStoreAndDomain(t) + tk := testkit.NewTestKit(t, store) + + tk.MustExec("use test") + tk.MustExec("drop table if exists test.t;") + tk.MustExec("create table test.t (expr varchar(30), pattern varchar(30), pos int, occur int, match_type varchar(30));") + tk.MustExec("insert into test.t values ('123', '12.', 1, 1, ''), ('aBb', 'bb', 1, 1, 'i'), ('ab\nabc', '^abc$', 1, 1, 'm');") + tk.MustExec("set @@tidb_allow_mpp=1; set @@tidb_enforce_mpp=1") + tk.MustExec("set @@tidb_isolation_read_engines = 'tiflash'") + + // Create virtual tiflash replica info. + is := dom.InfoSchema() + db, exists := is.SchemaByName(model.NewCIStr("test")) + require.True(t, exists) + for _, tblInfo := range db.Tables { + if tblInfo.Name.L == "t" { + tblInfo.TiFlashReplica = &model.TiFlashReplicaInfo{ + Count: 1, + Available: true, + } + } + } + + rows := [][]interface{}{ + {"TableReader_9", "root", "data:ExchangeSender_8"}, + {"└─ExchangeSender_8", "mpp[tiflash]", "ExchangeType: PassThrough"}, + {" └─Projection_4", "mpp[tiflash]", "regexp_substr(test.t.expr, test.t.pattern, 1, 1, test.t.match_type)->Column#7"}, + {" └─TableFullScan_7", "mpp[tiflash]", "keep order:false, stats:pseudo"}, + } + tk.MustQuery("explain select regexp_substr(expr, pattern, 1, 1, match_type) as res from test.t;").CheckAt([]int{0, 2, 4}, rows) +} + func TestCastTimeAsDurationToTiFlash(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) tk := testkit.NewTestKit(t, store)