Skip to content

Commit

Permalink
hint: avoid duplicate hints in QBHintHandler (#53921) (#53935)
Browse files Browse the repository at this point in the history
close #53767
  • Loading branch information
ti-chi-bot authored Jul 23, 2024
1 parent 6ed4dab commit d97c194
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
10 changes: 2 additions & 8 deletions planner/core/casetest/testdata/integration_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -7245,10 +7245,7 @@
" └─IndexRangeScan_148 19492.21 cop[tikv] table:t1, index:idx_a(a) range: decided by [eq(test.t1.a, test.t1.a)], keep order:false, stats:pseudo"
],
"Warn": [
"[planner:1815]We can only use one leading hint at most, when multiple leading hints are used, all leading hints will be invalid",
"[planner:1815]There are no matching table names for (t1) in optimizer hint /*+ INL_JOIN(t1, t1) */ or /*+ TIDB_INLJ(t1, t1) */. Maybe you can use the table alias name",
"[planner:1815]We can only use one leading hint at most, when multiple leading hints are used, all leading hints will be invalid",
"[planner:1815]There are no matching table names for (t1, t1) in optimizer hint /*+ INL_JOIN(t1, t1, t1) */ or /*+ TIDB_INLJ(t1, t1, t1) */. Maybe you can use the table alias name"
"[planner:1815]We can only use one leading hint at most, when multiple leading hints are used, all leading hints will be invalid"
]
},
{
Expand Down Expand Up @@ -7280,10 +7277,7 @@
" └─TableRowIDScan_69 9990.00 cop[tikv] table:t2 keep order:false, stats:pseudo"
],
"Warn": [
"[planner:1815]We can only use one leading hint at most, when multiple leading hints are used, all leading hints will be invalid",
"[planner:1815]There are no matching table names for (t2) in optimizer hint /*+ MERGE_JOIN(t2, t2) */ or /*+ TIDB_SMJ(t2, t2) */. Maybe you can use the table alias name",
"[planner:1815]We can only use one leading hint at most, when multiple leading hints are used, all leading hints will be invalid",
"[planner:1815]There are no matching table names for (t2, t2) in optimizer hint /*+ MERGE_JOIN(t2, t2, t2) */ or /*+ TIDB_SMJ(t2, t2, t2) */. Maybe you can use the table alias name"
"[planner:1815]We can only use one leading hint at most, when multiple leading hints are used, all leading hints will be invalid"
]
},
{
Expand Down
10 changes: 2 additions & 8 deletions planner/core/casetest/testdata/plan_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -839,10 +839,7 @@
" └─Selection 9990.00 mpp[tiflash] not(isnull(test.t.a))",
" └─TableFullScan 10000.00 mpp[tiflash] table:t1 pushed down filter:empty, keep order:false, stats:pseudo"
],
"Warn": [
"[planner:1815]There are no matching table names for (t1, t) in optimizer hint /*+ SHUFFLE_JOIN(t1, t, t1, t) */ or /*+ SHUFFLE_JOIN(t1, t, t1, t) */. Maybe you can use the table alias name",
"[planner:1815]There are no matching table names for (t1, t, t1, t) in optimizer hint /*+ SHUFFLE_JOIN(t1, t, t1, t, t1, t) */ or /*+ SHUFFLE_JOIN(t1, t, t1, t, t1, t) */. Maybe you can use the table alias name"
]
"Warn": null
},
{
"SQL": "WITH CTE AS (SELECT /*+ MERGE(), broadcast_join(t1, t) */ t.a, t.b FROM t join t t1 where t.a = t1.a) SELECT * FROM CTE WHERE CTE.a <18 union select * from cte where cte.b > 1;",
Expand Down Expand Up @@ -872,10 +869,7 @@
" └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.t.a))",
" └─TableFullScan 10000.00 mpp[tiflash] table:t1 pushed down filter:empty, keep order:false, stats:pseudo"
],
"Warn": [
"[planner:1815]There are no matching table names for (t1, t) in optimizer hint /*+ BROADCAST_JOIN(t1, t, t1, t) */ or /*+ TIDB_BCJ(t1, t, t1, t) */. Maybe you can use the table alias name",
"[planner:1815]There are no matching table names for (t1, t, t1, t) in optimizer hint /*+ BROADCAST_JOIN(t1, t, t1, t, t1, t) */ or /*+ TIDB_BCJ(t1, t, t1, t, t1, t) */. Maybe you can use the table alias name"
]
"Warn": null
},
{
"SQL": "select /*+ read_from_storage(tiflash[t1, t2]), broadcast_join(t1, t2), hash_join_build(t2) */ * from t t1 left join t t2 on t1.a=t2.a",
Expand Down
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

0 comments on commit d97c194

Please sign in to comment.