parser: support the hash_build and hash_probe hints (#36615)
ref pingcap/tidb#35439
This commit is contained in:
@ -3566,7 +3566,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", "ordered_hash_join", "merge_join", "inl_join", "broadcast_join", "inl_hash_join", "inl_merge_join", "leading":
|
||||
case "tidb_hj", "tidb_smj", "tidb_inlj", "hash_join", "hash_build", "hash_probe", "merge_join", "inl_join", "broadcast_join", "inl_hash_join", "inl_merge_join", "leading":
|
||||
for i, table := range n.Tables {
|
||||
if i != 0 {
|
||||
ctx.WritePlain(", ")
|
||||
|
||||
@ -241,7 +241,8 @@ 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`)"},
|
||||
{"ORDERED_HASH_JOIN(t1,t2)", "ORDERED_HASH_JOIN(`t1`, `t2`)"},
|
||||
{"HASH_BUILD(t1)", "HASH_BUILD(`t1`)"},
|
||||
{"HASH_PROBE(t1)", "HASH_PROBE(`t1`)"},
|
||||
{"LEADING(t1)", "LEADING(`t1`)"},
|
||||
{"LEADING(t1, c1)", "LEADING(`t1`, `c1`)"},
|
||||
{"LEADING(t1, c1, t2)", "LEADING(`t1`, `c1`, `t2`)"},
|
||||
|
||||
1219
parser/hintparser.go
1219
parser/hintparser.go
File diff suppressed because it is too large
Load Diff
@ -61,7 +61,8 @@ import (
|
||||
hintBNL "BNL"
|
||||
hintNoBNL "NO_BNL"
|
||||
hintHashJoin "HASH_JOIN"
|
||||
hintOrderedHashJoin "ORDERED_HASH_JOIN"
|
||||
hintHashBuild "HASH_BUILD"
|
||||
hintHashProbe "HASH_PROBE"
|
||||
hintNoHashJoin "NO_HASH_JOIN"
|
||||
hintMerge "MERGE"
|
||||
hintNoMerge "NO_MERGE"
|
||||
@ -543,7 +544,8 @@ SupportedTableLevelOptimizerHintName:
|
||||
| "NO_SWAP_JOIN_INPUTS"
|
||||
| "INL_MERGE_JOIN"
|
||||
| "HASH_JOIN"
|
||||
| "ORDERED_HASH_JOIN"
|
||||
| "HASH_BUILD"
|
||||
| "HASH_PROBE"
|
||||
| "LEADING"
|
||||
|
||||
UnsupportedIndexLevelOptimizerHintName:
|
||||
@ -608,7 +610,8 @@ Identifier:
|
||||
| "BNL"
|
||||
| "NO_BNL"
|
||||
| "HASH_JOIN"
|
||||
| "ORDERED_HASH_JOIN"
|
||||
| "HASH_BUILD"
|
||||
| "HASH_PROBE"
|
||||
| "NO_HASH_JOIN"
|
||||
| "MERGE"
|
||||
| "NO_MERGE"
|
||||
|
||||
@ -895,7 +895,8 @@ var hintTokenMap = map[string]int{
|
||||
"BNL": hintBNL,
|
||||
"NO_BNL": hintNoBNL,
|
||||
"HASH_JOIN": hintHashJoin,
|
||||
"ORDERED_HASH_JOIN": hintOrderedHashJoin,
|
||||
"HASH_BUILD": hintHashBuild,
|
||||
"HASH_PROBE": hintHashProbe,
|
||||
"NO_HASH_JOIN": hintNoHashJoin,
|
||||
"MERGE": hintMerge,
|
||||
"NO_MERGE": hintNoMerge,
|
||||
|
||||
@ -3963,22 +3963,20 @@ func TestOptimizerHints(t *testing.T) {
|
||||
require.Equal(t, "t3", hints[1].Tables[0].TableName.L)
|
||||
require.Equal(t, "t4", hints[1].Tables[1].TableName.L)
|
||||
|
||||
// Test ORDERED_HASH_JOIN
|
||||
stmt, _, err = p.Parse("select /*+ ORDERED_HASH_JOIN(t1, T2), ordered_hash_join(t3, t4) */ c1, c2 from t1, t2 where t1.c1 = t2.c1", "", "")
|
||||
// Test HASH_BUILD and HASH_PROBE
|
||||
stmt, _, err = p.Parse("select /*+ hash_build(t1), hash_probe(t4) */ c1, c2 from t1, t2 where t1.c1 = t2.c1", "", "")
|
||||
require.NoError(t, err)
|
||||
selectStmt = stmt[0].(*ast.SelectStmt)
|
||||
|
||||
hints = selectStmt.TableHints
|
||||
require.Len(t, hints, 2)
|
||||
require.Equal(t, "ordered_hash_join", hints[0].HintName.L)
|
||||
require.Len(t, hints[0].Tables, 2)
|
||||
require.Equal(t, "hash_build", hints[0].HintName.L)
|
||||
require.Len(t, hints[0].Tables, 1)
|
||||
require.Equal(t, "t1", hints[0].Tables[0].TableName.L)
|
||||
require.Equal(t, "t2", hints[0].Tables[1].TableName.L)
|
||||
|
||||
require.Equal(t, "ordered_hash_join", hints[1].HintName.L)
|
||||
require.Len(t, hints[1].Tables, 2)
|
||||
require.Equal(t, "t3", hints[1].Tables[0].TableName.L)
|
||||
require.Equal(t, "t4", hints[1].Tables[1].TableName.L)
|
||||
require.Equal(t, "hash_probe", hints[1].HintName.L)
|
||||
require.Len(t, hints[1].Tables, 1)
|
||||
require.Equal(t, "t4", hints[1].Tables[0].TableName.L)
|
||||
|
||||
// Test HASH_JOIN with SWAP_JOIN_INPUTS/NO_SWAP_JOIN_INPUTS
|
||||
// t1 for build, t4 for probe
|
||||
|
||||
Reference in New Issue
Block a user