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

hint: avoid duplicate hints in QBHintHandler (#53921) #53935

Merged
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 1 addition & 1 deletion planner/core/issuetest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ go_test(
srcs = ["planner_issue_test.go"],
flaky = True,
race = "on",
shard_count = 12,
shard_count = 13,
deps = ["//testkit"],
)
12 changes: 12 additions & 0 deletions planner/core/issuetest/planner_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,15 @@ func TestIssue49109(t *testing.T) {

tk.MustQuery("SELECT t0.c0 FROM v0, t0 LEFT JOIN t1 ON t0.c0 WHERE ((INET_ATON('5V')) IS NULL);").Check(testkit.Rows("0", "0", "0", "0", "<nil>", "<nil>", "<nil>", "<nil>", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2"))
}

func TestQBHintHandlerDuplicateObjects(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("CREATE TABLE t_employees (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, fname VARCHAR(25) NOT NULL, lname VARCHAR(25) NOT NULL, store_id INT NOT NULL, department_id INT NOT NULL);")
tk.MustExec("ALTER TABLE t_employees ADD INDEX idx(department_id);")

// Explain statement
tk.MustQuery("EXPLAIN WITH t AS (SELECT /*+ inl_join(e) */ em.* FROM t_employees em JOIN t_employees e WHERE em.store_id = e.department_id) SELECT * FROM t;")
tk.MustQuery("show warnings").Check(testkit.Rows())
}
1 change: 1 addition & 0 deletions util/hint/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ go_library(
"//util/dbterror",
"//util/logutil",
"@com_github_pingcap_errors//:errors",
"@org_golang_x_exp//slices",
"@org_uber_go_zap//:zap",
],
)
5 changes: 4 additions & 1 deletion util/hint/hint_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/pingcap/tidb/util/dbterror"
"github.com/pingcap/tidb/util/logutil"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

var supportedHintNameForInsertStmt = map[string]struct{}{}
Expand Down Expand Up @@ -615,7 +616,9 @@ func (p *BlockHintProcessor) GetCurrentStmtHints(hints []*ast.TableOptimizerHint
}
continue
}
p.QbHints[offset] = append(p.QbHints[offset], hint)
if !slices.Contains(p.QbHints[offset], hint) {
p.QbHints[offset] = append(p.QbHints[offset], hint)
}
}
return p.QbHints[currentOffset]
}
Expand Down