Skip to content

Commit e9e7439

Browse files
qw4990YangKeao
authored andcommitted
use_index to support tiflash
Signed-off-by: Yang Keao <[email protected]>
1 parent de42cbc commit e9e7439

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
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 = 46,
12+
shard_count = 47,
1313
deps = [
1414
"//pkg/config",
1515
"//pkg/domain",

pkg/executor/test/tiflashtest/tiflash_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,23 @@ func TestPartitionTable(t *testing.T) {
549549
failpoint.Disable("github.com/pingcap/tidb/pkg/executor/checkUseMPP")
550550
}
551551

552+
func TestUseIndexTiFlash(t *testing.T) {
553+
store := testkit.CreateMockStore(t, withMockTiFlash(2))
554+
tk := testkit.NewTestKit(t, store)
555+
tk.MustExec("use test")
556+
tk.MustExec(`create table t (id int primary key, a int, b int, c int, key(a), key(b), key(c))`)
557+
tk.MustExec(`alter table t set tiflash replica 1`)
558+
tb := external.GetTableByName(t, tk, "test", "t")
559+
err := domain.GetDomain(tk.Session()).DDLExecutor().UpdateTableReplicaInfo(tk.Session(), tb.Meta().ID, true)
560+
require.NoError(t, err)
561+
562+
tk.MustUseIndex(`select /*+ use_index(t, a, b, c, tiflash) */ 1 from t where a=1`, "a")
563+
tk.MustUseIndex(`select /*+ use_index(t, a, b, c, tiflash) */ 1 from t where b=1`, "b")
564+
tk.MustUseIndex(`select /*+ use_index(t, a, b, c, tiflash) */ 1 from t where b=1`, "b")
565+
plan := tk.MustQuery(`explain select /*+ use_index(t, a, b, c, tiflash) */ 1 from t`).Rows()
566+
require.Equal(t, plan[len(plan)-1][2], "mpp[tiflash]")
567+
}
568+
552569
func TestMppEnum(t *testing.T) {
553570
store := testkit.CreateMockStore(t, withMockTiFlash(2))
554571
tk := testkit.NewTestKit(t, store)

pkg/planner/core/planbuilder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,9 @@ func getPathByIndexName(paths []*util.AccessPath, idxName pmodel.CIStr, tblInfo
10831083
if path.IsTiKVTablePath() && isPrimaryIndex(idxName) && tblInfo.HasClusteredIndex() {
10841084
return path
10851085
}
1086+
if path.StoreType == kv.TiFlash && idxName.L == "tiflash" {
1087+
return path
1088+
}
10861089
// If it's not a tikv table path and the index is nil, it could not be any index path.
10871090
if path.Index == nil {
10881091
continue

0 commit comments

Comments
 (0)