Skip to content

Commit 8df0062

Browse files
authored
planner: make converge index merge path feel the prefer tiflash hint (#56227)
close #56217
1 parent 75483d8 commit 8df0062

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

pkg/executor/test/tiflashtest/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ go_test(
99
],
1010
flaky = True,
1111
race = "on",
12-
shard_count = 44,
12+
shard_count = 45,
1313
deps = [
1414
"//pkg/config",
1515
"//pkg/domain",

pkg/executor/test/tiflashtest/tiflash_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,3 +2117,35 @@ func TestMppTableReaderCacheForSingleSQL(t *testing.T) {
21172117
require.Equal(t, tc.expectMissNum, missNum.Load())
21182118
}
21192119
}
2120+
2121+
func TestIndexMergeCarePreferTiflash(t *testing.T) {
2122+
store := testkit.CreateMockStore(t, withMockTiFlash(1))
2123+
tk := testkit.NewTestKit(t, store)
2124+
tk.MustExec("use test")
2125+
2126+
tk.MustExec("drop table if exists t")
2127+
tk.MustExec("CREATE TABLE `t` (" +
2128+
"`i` bigint(20) NOT NULL, " +
2129+
"`w` varchar(32) NOT NULL," +
2130+
"`l` varchar(32) NOT NULL," +
2131+
"`a` tinyint(4) NOT NULL DEFAULT '0'," +
2132+
"`m` int(11) NOT NULL DEFAULT '0'," +
2133+
"`s` int(11) NOT NULL DEFAULT '0'," +
2134+
"PRIMARY KEY (`i`) /*T![clustered_index] NONCLUSTERED */," +
2135+
"KEY `idx_win_user_site_code` (`w`,`m`)," +
2136+
"KEY `idx_lose_user_site_code` (`l`,`m`)," +
2137+
"KEY `idx_win_site_code_status` (`w`,`a`)," +
2138+
"KEY `idx_lose_site_code_status` (`l`,`a`)" +
2139+
")")
2140+
tk.MustExec("alter table t set tiflash replica 1")
2141+
tb := external.GetTableByName(t, tk, "test", "t")
2142+
err := domain.GetDomain(tk.Session()).DDLExecutor().UpdateTableReplicaInfo(tk.Session(), tb.Meta().ID, true)
2143+
require.NoError(t, err)
2144+
tk.MustQuery("explain format=\"brief\" SELECT" +
2145+
" /*+ read_from_storage(tiflash[a]) */ a.i FROM t a WHERE a.s = 0 AND a.a NOT IN (-1, 0) AND m >= 1726910326 AND m <= 1726910391 AND ( a.w IN ('1123') OR a.l IN ('1123'))").Check(
2146+
testkit.Rows("TableReader 0.00 root MppVersion: 2, data:ExchangeSender",
2147+
"└─ExchangeSender 0.00 mpp[tiflash] ExchangeType: PassThrough",
2148+
" └─Projection 0.00 mpp[tiflash] test.t.i",
2149+
" └─Selection 0.00 mpp[tiflash] ge(test.t.m, 1726910326), le(test.t.m, 1726910391), not(in(test.t.a, -1, 0)), or(eq(test.t.w, \"1123\"), eq(test.t.l, \"1123\"))",
2150+
" └─TableFullScan 10.00 mpp[tiflash] table:a pushed down filter:eq(test.t.s, 0), keep order:false, stats:pseudo"))
2151+
}

pkg/planner/core/casetest/physicalplantest/testdata/plan_suite_out.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,11 @@
406406
"└─ExchangeSender 4439.11 mpp[tiflash] ExchangeType: PassThrough",
407407
" └─Projection 4439.11 mpp[tiflash] test.t.a, Column#5",
408408
" └─Projection 4439.11 mpp[tiflash] Column#5, test.t.a",
409-
" └─HashAgg 4439.11 mpp[tiflash] group by:test.t.a, test.t.c, funcs:sum(Column#14)->Column#5, funcs:firstrow(test.t.a)->test.t.a",
409+
" └─HashAgg 4439.11 mpp[tiflash] group by:test.t.a, test.t.c, funcs:sum(Column#8)->Column#5, funcs:firstrow(test.t.a)->test.t.a",
410410
" └─ExchangeReceiver 4439.11 mpp[tiflash] ",
411411
" └─ExchangeSender 4439.11 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.t.a, collate: binary], [name: test.t.c, collate: binary]",
412-
" └─HashAgg 4439.11 mpp[tiflash] group by:Column#17, Column#18, funcs:sum(Column#16)->Column#14",
413-
" └─Projection 5548.89 mpp[tiflash] cast(test.t.b, decimal(10,0) BINARY)->Column#16, test.t.a->Column#17, test.t.c->Column#18",
412+
" └─HashAgg 4439.11 mpp[tiflash] group by:Column#11, Column#12, funcs:sum(Column#10)->Column#8",
413+
" └─Projection 5548.89 mpp[tiflash] cast(test.t.b, decimal(10,0) BINARY)->Column#10, test.t.a->Column#11, test.t.c->Column#12",
414414
" └─Selection 5548.89 mpp[tiflash] or(lt(test.t.b, 2), gt(test.t.a, 2))",
415415
" └─TableFullScan 10000.00 mpp[tiflash] table:t pushed down filter:empty, keep order:false, stats:pseudo"
416416
],

pkg/planner/core/find_best_task.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,10 @@ func findBestTask4DS(ds *DataSource, prop *property.PhysicalProperty, planCounte
13771377
for _, candidate := range candidates {
13781378
path := candidate.path
13791379
if path.PartialIndexPaths != nil {
1380+
// prefer tiflash, while current table path is tikv, skip it.
1381+
if ds.PreferStoreType&h.PreferTiFlash != 0 && path.StoreType == kv.TiKV {
1382+
continue
1383+
}
13801384
idxMergeTask, err := convertToIndexMergeScan(ds, prop, candidate, opt)
13811385
if err != nil {
13821386
return nil, 0, err
@@ -1512,9 +1516,11 @@ func findBestTask4DS(ds *DataSource, prop *property.PhysicalProperty, planCounte
15121516
}
15131517
}
15141518
if path.IsTablePath() {
1519+
// prefer tiflash, while current table path is tikv, skip it.
15151520
if ds.PreferStoreType&h.PreferTiFlash != 0 && path.StoreType == kv.TiKV {
15161521
continue
15171522
}
1523+
// prefer tikv, while current table path is tiflash, skip it.
15181524
if ds.PreferStoreType&h.PreferTiKV != 0 && path.StoreType == kv.TiFlash {
15191525
continue
15201526
}

0 commit comments

Comments
 (0)