Skip to content

Commit

Permalink
planner: fix the issue that MVIndex leads to "can't find plan" error (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
qw4990 authored Mar 25, 2024
1 parent 99ba63a commit 3475795
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/planner/core/casetest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ go_test(
],
data = glob(["testdata/**"]),
flaky = True,
shard_count = 21,
shard_count = 22,
deps = [
"//pkg/domain",
"//pkg/parser",
Expand Down
9 changes: 9 additions & 0 deletions pkg/planner/core/casetest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,15 @@ func TestFixControl45132(t *testing.T) {
tk.MustHavePlan(`select * from t where a=2`, `TableFullScan`)
}

func TestIssue49438(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec(`use test`)
tk.MustExec(`drop table if exists tx`)
tk.MustExec(`create table tx (a int, b json, key k(a, (cast(b as date array))))`)
tk.MustExec(`select 1 from tx where a in (1)`) // no error
}

func TestIssue52023(t *testing.T) {
store := testkit.CreateMockStore(t)

Expand Down
6 changes: 6 additions & 0 deletions pkg/planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,12 @@ func compareIndexBack(lhs, rhs *candidatePath) (int, bool) {
// compareCandidates is the core of skyline pruning, which is used to decide which candidate path is better.
// The return value is 1 if lhs is better, -1 if rhs is better, 0 if they are equivalent or not comparable.
func compareCandidates(sctx PlanContext, prop *property.PhysicalProperty, lhs, rhs *candidatePath) int {
// Due to #50125, full scan on MVIndex has been disabled, so MVIndex path might lead to 'can't find a proper plan' error at the end.
// Avoid MVIndex path to exclude all other paths and leading to 'can't find a proper plan' error, see #49438 for an example.
if isMVIndexPath(lhs.path) || isMVIndexPath(rhs.path) {
return 0
}

// This rule is empirical but not always correct.
// If x's range row count is significantly lower than y's, for example, 1000 times, we think x is better.
if lhs.path.CountAfterAccess > 100 && rhs.path.CountAfterAccess > 100 && // to prevent some extreme cases, e.g. 0.01 : 10
Expand Down

0 comments on commit 3475795

Please sign in to comment.