From 915f05127a4269f38a741e6f495b4217bb3789c6 Mon Sep 17 00:00:00 2001 From: qw4990 Date: Sat, 28 Jan 2023 18:29:09 +0800 Subject: [PATCH 1/2] fixup --- planner/core/find_best_task.go | 3 +++ planner/core/indexmerge_path_test.go | 24 ++++++++++++++++++++++++ planner/core/point_get_plan.go | 4 ++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/planner/core/find_best_task.go b/planner/core/find_best_task.go index c2d3e1a62d7bc..6c5d2c49fddf0 100644 --- a/planner/core/find_best_task.go +++ b/planner/core/find_best_task.go @@ -944,6 +944,9 @@ func (ds *DataSource) findBestTask(prop *property.PhysicalProperty, planCounter if canConvertPointGet && expression.MaybeOverOptimized4PlanCache(ds.ctx, path.AccessConds) { canConvertPointGet = ds.canConvertToPointGetForPlanCache(path) } + if canConvertPointGet && path.Index != nil && path.Index.MVIndex { + canConvertPointGet = false // cannot use PointGet upon MVIndex + } if canConvertPointGet && !path.IsIntHandlePath { // We simply do not build [batch] point get for prefix indexes. This can be optimized. diff --git a/planner/core/indexmerge_path_test.go b/planner/core/indexmerge_path_test.go index 1119cfb5c666e..ab507a3e98606 100644 --- a/planner/core/indexmerge_path_test.go +++ b/planner/core/indexmerge_path_test.go @@ -15,6 +15,8 @@ package core_test import ( + "github.com/stretchr/testify/require" + "strings" "testing" "github.com/pingcap/tidb/planner/core" @@ -149,3 +151,25 @@ func TestMVIndexIndexMergePlanCache(t *testing.T) { tk.MustExec("execute st") tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) } + +func TestMVIndexPointGet(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec(`create table t(j json, unique kj((cast(j as signed array))))`) + + for _, sql := range []string{ + "select j from t where j=1", + "select j from t where j=1 or j=2", + "select j from t where j in (1, 2)", + } { + plan := tk.MustQuery("explain " + sql).Rows() + hasPointGet := false + for _, line := range plan { + if strings.Contains(strings.ToLower(line[0].(string)), "point") { + hasPointGet = true + } + } + require.True(t, !hasPointGet) // no point-get plan + } +} diff --git a/planner/core/point_get_plan.go b/planner/core/point_get_plan.go index 0453d29c59842..1b285a83a1596 100644 --- a/planner/core/point_get_plan.go +++ b/planner/core/point_get_plan.go @@ -731,7 +731,7 @@ func newBatchPointGetPlan( } } for _, idxInfo := range tbl.Indices { - if !idxInfo.Unique || idxInfo.State != model.StatePublic || idxInfo.Invisible || + if !idxInfo.Unique || idxInfo.State != model.StatePublic || idxInfo.Invisible || idxInfo.MVIndex || !indexIsAvailableByHints(idxInfo, indexHints) { continue } @@ -1099,7 +1099,7 @@ func tryPointGetPlan(ctx sessionctx.Context, selStmt *ast.SelectStmt, check bool var err error for _, idxInfo := range tbl.Indices { - if !idxInfo.Unique || idxInfo.State != model.StatePublic || idxInfo.Invisible || + if !idxInfo.Unique || idxInfo.State != model.StatePublic || idxInfo.Invisible || idxInfo.MVIndex || !indexIsAvailableByHints(idxInfo, tblName.IndexHints) { continue } From b2ac655ed581a30259bf43d3f10459d12d871d90 Mon Sep 17 00:00:00 2001 From: qw4990 Date: Sat, 28 Jan 2023 18:55:00 +0800 Subject: [PATCH 2/2] fixup --- planner/core/indexmerge_path_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planner/core/indexmerge_path_test.go b/planner/core/indexmerge_path_test.go index ab507a3e98606..430171f5bcff7 100644 --- a/planner/core/indexmerge_path_test.go +++ b/planner/core/indexmerge_path_test.go @@ -15,13 +15,13 @@ package core_test import ( - "github.com/stretchr/testify/require" "strings" "testing" "github.com/pingcap/tidb/planner/core" "github.com/pingcap/tidb/testkit" "github.com/pingcap/tidb/testkit/testdata" + "github.com/stretchr/testify/require" ) func TestIndexMergeJSONMemberOf(t *testing.T) {