Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: make converge index merge path feel the prefer tiflash hint (#56227) #59072

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions executor/tiflashtest/tiflash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1377,3 +1377,35 @@ func TestIssue50358(t *testing.T) {
tk.MustQuery("select 8 from t join t1").Check(testkit.Rows("8", "8"))
}
}

func TestIndexMergeCarePreferTiflash(t *testing.T) {
store := testkit.CreateMockStore(t, withMockTiFlash(1))
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")

tk.MustExec("drop table if exists t")
tk.MustExec("CREATE TABLE `t` (" +
"`i` bigint(20) NOT NULL, " +
"`w` varchar(32) NOT NULL," +
"`l` varchar(32) NOT NULL," +
"`a` tinyint(4) NOT NULL DEFAULT '0'," +
"`m` int(11) NOT NULL DEFAULT '0'," +
"`s` int(11) NOT NULL DEFAULT '0'," +
"PRIMARY KEY (`i`) /*T![clustered_index] NONCLUSTERED */," +
"KEY `idx_win_user_site_code` (`w`,`m`)," +
"KEY `idx_lose_user_site_code` (`l`,`m`)," +
"KEY `idx_win_site_code_status` (`w`,`a`)," +
"KEY `idx_lose_site_code_status` (`l`,`a`)" +
")")
tk.MustExec("alter table t set tiflash replica 1")
tb := external.GetTableByName(t, tk, "test", "t")
err := domain.GetDomain(tk.Session()).DDL().UpdateTableReplicaInfo(tk.Session(), tb.Meta().ID, true)
require.NoError(t, err)
tk.MustQuery("explain format=\"brief\" SELECT" +
" /*+ 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(
testkit.Rows("TableReader 0.00 root data:ExchangeSender",
"└─ExchangeSender 0.00 mpp[tiflash] ExchangeType: PassThrough",
" └─Projection 0.00 mpp[tiflash] test.t.i",
" └─Selection 0.00 mpp[tiflash] eq(test.t.s, 0), 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\"))",
" └─TableFullScan 10000.00 mpp[tiflash] table:a keep order:false, stats:pseudo"))
}
4 changes: 4 additions & 0 deletions planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,10 @@ func (ds *DataSource) findBestTask(prop *property.PhysicalProperty, planCounter
for _, candidate := range candidates {
path := candidate.path
if path.PartialIndexPaths != nil {
// prefer tiflash, while current table path is tikv, skip it.
if ds.preferStoreType&preferTiFlash != 0 && path.StoreType == kv.TiKV {
continue
}
idxMergeTask, err := ds.convertToIndexMergeScan(prop, candidate, opt)
if err != nil {
return nil, 0, err
Expand Down