Skip to content

Commit

Permalink
Merge branch 'master' into ddl-event
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkingrei authored Dec 1, 2022
2 parents 3b4c598 + d1fc5b6 commit 57f2762
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
10 changes: 9 additions & 1 deletion br/pkg/streamhelper/spans/sorted.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,19 @@ func (f *ValuedFull) mergeWithOverlap(val Valued, overlapped []Valued, newItems

// overlapped inserts the overlapped ranges of the span into the `result` slice.
func (f *ValuedFull) overlapped(k Span, result *[]Valued) {
var first Span
var (
first Span
hasFirst bool
)
// Firstly, let's find whether there is a overlapped region with less start key.
f.inner.DescendLessOrEqual(Valued{Key: k}, func(item btree.Item) bool {
first = item.(Valued).Key
hasFirst = true
return false
})
if !hasFirst || !Overlaps(first, k) {
first = k
}

f.inner.AscendGreaterOrEqual(Valued{Key: first}, func(item btree.Item) bool {
r := item.(Valued)
Expand Down
37 changes: 37 additions & 0 deletions br/pkg/streamhelper/spans/sorted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,43 @@ func TestSubRange(t *testing.T) {
kv(s("0008", ""), 42),
},
},
{
Range: []spans.Span{
s("0001", "0004"),
s("0005", "0008"),
},
InputSequence: []spans.Valued{
kv(s("0001", "0002"), 42),
kv(s("0002", "0008"), 43),
kv(s("0004", "0007"), 45),
kv(s("0000", "00015"), 48),
},
Result: []spans.Valued{
kv(s("0001", "00015"), 48),
kv(s("00015", "0002"), 42),
kv(s("0002", "0004"), 43),
kv(s("0005", "0007"), 45),
kv(s("0007", "0008"), 43),
},
},
{
Range: []spans.Span{
s("0001", "0004"),
s("0005", "0008"),
},
InputSequence: []spans.Valued{
kv(s("0004", "0008"), 32),
kv(s("00041", "0007"), 33),
kv(s("0004", "00041"), 99999),
kv(s("0005", "0006"), 34),
},
Result: []spans.Valued{
kv(s("0001", "0004"), 0),
kv(s("0005", "0006"), 34),
kv(s("0006", "0007"), 33),
kv(s("0007", "0008"), 32),
},
},
}

for i, c := range cases {
Expand Down
5 changes: 5 additions & 0 deletions expression/expr_to_pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,11 @@ func TestExprPushDownToFlash(t *testing.T) {
require.NoError(t, err)
exprs = append(exprs, function)

// regexp_instr: supported
function, err = NewFunction(mock.NewContext(), ast.RegexpInStr, types.NewFieldType(mysql.TypeLonglong), stringColumn, stringColumn, intColumn, 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)
Expand Down
2 changes: 1 addition & 1 deletion expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ func scalarExprSupportedByFlash(function *ScalarFunction) bool {
return false
}
return true
case ast.Regexp, ast.RegexpLike:
case ast.Regexp, ast.RegexpLike, ast.RegexpInStr:
funcCharset, funcCollation := function.Function.CharsetAndCollation()
if funcCharset == charset.CharsetBin && funcCollation == charset.CollationBin {
return false
Expand Down
33 changes: 33 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7417,6 +7417,39 @@ func TestEltPushDownToTiFlash(t *testing.T) {
tk.MustQuery("explain select elt(a, b) from t;").CheckAt([]int{0, 2, 4}, rows)
}

func TestRegexpInstrPushDownToTiFlash(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, ret_op int, match_type varchar(30));")
tk.MustExec("insert into test.t values ('123', '12.', 1, 1, 0, ''), ('aBb', 'bb', 1, 1, 0, 'i'), ('ab\nabc', '^abc$', 1, 1, 0, '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_instr(test.t.expr, test.t.pattern, 1, 1, 0, test.t.match_type)->Column#8"},
{" └─TableFullScan_7", "mpp[tiflash]", "keep order:false, stats:pseudo"},
}
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 TestCastTimeAsDurationToTiFlash(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)
Expand Down

0 comments on commit 57f2762

Please sign in to comment.