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

Merged
merged 6 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 pkg/planner/core/casetest/hint/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ go_test(
],
data = glob(["testdata/**"]),
flaky = True,
shard_count = 7,
shard_count = 8,
deps = [
"//pkg/config",
"//pkg/domain",
Expand Down
12 changes: 12 additions & 0 deletions pkg/planner/core/casetest/hint/hint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,15 @@ func TestHints(t *testing.T) {
tk.MustQuery("show warnings").Check(testkit.Rows(output[i].Warn...))
}
}

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())
}
5 changes: 4 additions & 1 deletion pkg/util/hint/hint_query_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package hint

import (
"fmt"
"slices"
"strconv"
"strings"

Expand Down Expand Up @@ -295,7 +296,9 @@ func (p *QBHintHandler) GetCurrentStmtHints(hints []*ast.TableOptimizerHint, cur
}
continue
}
p.QBOffsetToHints[offset] = append(p.QBOffsetToHints[offset], hint)
if !slices.Contains(p.QBOffsetToHints[offset], hint) {
p.QBOffsetToHints[offset] = append(p.QBOffsetToHints[offset], hint)
}
}
return p.QBOffsetToHints[currentOffset]
}
Expand Down