Skip to content

Commit

Permalink
parser: ignore schema name if WithoutSchemaNameFlag is set when resto…
Browse files Browse the repository at this point in the history
…ring hints (#49587) (#53433)

ref #48875, close #52813
  • Loading branch information
ti-chi-bot authored May 28, 2024
1 parent 040dc01 commit e5a8ea0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/bindinfo/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ go_test(
],
flaky = True,
race = "on",
shard_count = 28,
shard_count = 29,
deps = [
"//pkg/bindinfo",
"//pkg/bindinfo/internal",
Expand Down
16 changes: 16 additions & 0 deletions pkg/bindinfo/tests/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ func TestBindingInListOperation(t *testing.T) {
require.Equal(t, "enabled", tk.MustQuery(`show global bindings`).Rows()[0][3].(string))
}

func TestIssue52813(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec(`use test`)
tk.MustExec(`create table a(id int key);`)
tk.MustExec(`create table b(id int key)`)
tk.MustExec(`create binding for select * from a, b where a.id=b.id using select /*+ no_merge_join(a,b) */ * from a, b where a.id=b.id;`)
tk.MustQuery(`explain select * from a, b where a.id=b.id`).Check(testkit.Rows(
`HashJoin_27 12500.00 root inner join, equal:[eq(test.a.id, test.b.id)]`,
`├─TableReader_32(Build) 10000.00 root data:TableFullScan_31`,
`│ └─TableFullScan_31 10000.00 cop[tikv] table:b keep order:false, stats:pseudo`,
`└─TableReader_30(Probe) 10000.00 root data:TableFullScan_29`,
` └─TableFullScan_29 10000.00 cop[tikv] table:a keep order:false, stats:pseudo`))
tk.MustQuery(`show warnings`).Check(testkit.Rows()) // no warning, the binding can work correctly
}

func TestPrepareCacheWithBinding(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down
12 changes: 8 additions & 4 deletions pkg/parser/ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3684,9 +3684,11 @@ type HintTable struct {
}

func (ht *HintTable) Restore(ctx *format.RestoreCtx) {
if ht.DBName.L != "" {
ctx.WriteName(ht.DBName.String())
ctx.WriteKeyWord(".")
if !ctx.Flags.HasWithoutSchemaNameFlag() {
if ht.DBName.L != "" {
ctx.WriteName(ht.DBName.String())
ctx.WriteKeyWord(".")
}
}
ctx.WriteName(ht.TableName.String())
if ht.QBName.L != "" {
Expand Down Expand Up @@ -3737,7 +3739,9 @@ func (n *TableOptimizerHint) Restore(ctx *format.RestoreCtx) error {
ctx.WriteName(n.HintData.(string))
case "nth_plan":
ctx.WritePlainf("%d", n.HintData.(int64))
case "tidb_hj", "tidb_smj", "tidb_inlj", "hash_join", "hash_join_build", "hash_join_probe", "merge_join", "inl_join", "broadcast_join", "shuffle_join", "inl_hash_join", "inl_merge_join", "leading":
case "tidb_hj", "tidb_smj", "tidb_inlj", "hash_join", "hash_join_build", "hash_join_probe", "merge_join", "inl_join",
"broadcast_join", "shuffle_join", "inl_hash_join", "inl_merge_join", "leading", "no_hash_join", "no_merge_join",
"no_index_join", "no_index_hash_join", "no_index_merge_join":
for i, table := range n.Tables {
if i != 0 {
ctx.WritePlain(", ")
Expand Down

0 comments on commit e5a8ea0

Please sign in to comment.