Skip to content

Commit

Permalink
parser: support join order hint (#34337)
Browse files Browse the repository at this point in the history
ref #29932
  • Loading branch information
Reminiscent authored May 5, 2022
1 parent ad6d620 commit 3e13ef3
Show file tree
Hide file tree
Showing 6 changed files with 599 additions and 534 deletions.
4 changes: 2 additions & 2 deletions parser/ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3417,7 +3417,7 @@ func (n *TableOptimizerHint) Restore(ctx *format.RestoreCtx) error {
}
// Hints without args except query block.
switch n.HintName.L {
case "hash_agg", "stream_agg", "agg_to_cop", "read_consistent_replica", "no_index_merge", "qb_name", "ignore_plan_cache", "limit_to_cop":
case "hash_agg", "stream_agg", "agg_to_cop", "read_consistent_replica", "no_index_merge", "qb_name", "ignore_plan_cache", "limit_to_cop", "straight_join":
ctx.WritePlain(")")
return nil
}
Expand All @@ -3430,7 +3430,7 @@ func (n *TableOptimizerHint) Restore(ctx *format.RestoreCtx) error {
ctx.WritePlainf("%d", n.HintData.(uint64))
case "nth_plan":
ctx.WritePlainf("%d", n.HintData.(int64))
case "tidb_hj", "tidb_smj", "tidb_inlj", "hash_join", "merge_join", "inl_join", "broadcast_join", "inl_hash_join", "inl_merge_join":
case "tidb_hj", "tidb_smj", "tidb_inlj", "hash_join", "merge_join", "inl_join", "broadcast_join", "inl_hash_join", "inl_merge_join", "leading":
for i, table := range n.Tables {
if i != 0 {
ctx.WritePlain(", ")
Expand Down
10 changes: 10 additions & 0 deletions parser/ast/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ func TestTableOptimizerHintRestore(t *testing.T) {
{"INL_MERGE_JOIN(t1,t2)", "INL_MERGE_JOIN(`t1`, `t2`)"},
{"INL_JOIN(t1,t2)", "INL_JOIN(`t1`, `t2`)"},
{"HASH_JOIN(t1,t2)", "HASH_JOIN(`t1`, `t2`)"},
{"LEADING(t1)", "LEADING(`t1`)"},
{"LEADING(t1, c1)", "LEADING(`t1`, `c1`)"},
{"LEADING(t1, c1, t2)", "LEADING(`t1`, `c1`, `t2`)"},
{"LEADING(@sel1 t1, c1)", "LEADING(@`sel1` `t1`, `c1`)"},
{"LEADING(@sel1 t1)", "LEADING(@`sel1` `t1`)"},
{"LEADING(@sel1 t1, c1, t2)", "LEADING(@`sel1` `t1`, `c1`, `t2`)"},
{"LEADING(t1@sel1)", "LEADING(`t1`@`sel1`)"},
{"LEADING(t1@sel1, c1)", "LEADING(`t1`@`sel1`, `c1`)"},
{"LEADING(t1@sel1, c1, t2)", "LEADING(`t1`@`sel1`, `c1`, `t2`)"},
{"MAX_EXECUTION_TIME(3000)", "MAX_EXECUTION_TIME(3000)"},
{"MAX_EXECUTION_TIME(@sel1 3000)", "MAX_EXECUTION_TIME(@`sel1` 3000)"},
{"USE_INDEX_MERGE(t1 c1)", "USE_INDEX_MERGE(`t1` `c1`)"},
Expand All @@ -265,6 +274,7 @@ func TestTableOptimizerHintRestore(t *testing.T) {
{"AGG_TO_COP()", "AGG_TO_COP()"},
{"AGG_TO_COP(@sel_1)", "AGG_TO_COP(@`sel_1`)"},
{"LIMIT_TO_COP()", "LIMIT_TO_COP()"},
{"STRAIGHT_JOIN()", "STRAIGHT_JOIN()"},
{"NO_INDEX_MERGE()", "NO_INDEX_MERGE()"},
{"NO_INDEX_MERGE(@sel1)", "NO_INDEX_MERGE(@`sel1`)"},
{"READ_CONSISTENT_REPLICA()", "READ_CONSISTENT_REPLICA()"},
Expand Down
Loading

0 comments on commit 3e13ef3

Please sign in to comment.