Skip to content

Commit

Permalink
*: support order_index and no_order_index hint for planner (#44111)
Browse files Browse the repository at this point in the history
close #39964
  • Loading branch information
xuyifangreeneyes authored May 29, 2023
1 parent 97ef067 commit 7bd4528
Show file tree
Hide file tree
Showing 14 changed files with 1,317 additions and 637 deletions.
6 changes: 6 additions & 0 deletions parser/ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ const (
HintUse IndexHintType = iota + 1
HintIgnore
HintForce
HintOrderIndex
HintNoOrderIndex
)

// IndexHintScope is the type for index hint for join, order by or group by.
Expand Down Expand Up @@ -386,6 +388,10 @@ func (n *IndexHint) Restore(ctx *format.RestoreCtx) error {
indexHintType = "IGNORE INDEX"
case HintForce:
indexHintType = "FORCE INDEX"
case HintOrderIndex:
indexHintType = "ORDER INDEX"
case HintNoOrderIndex:
indexHintType = "NO ORDER INDEX"
default: // Prevent accidents
return errors.New("IndexHintType has an error while matching")
}
Expand Down
2 changes: 1 addition & 1 deletion parser/ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3730,7 +3730,7 @@ func (n *TableOptimizerHint) Restore(ctx *format.RestoreCtx) error {
}
table.Restore(ctx)
}
case "use_index", "ignore_index", "use_index_merge", "force_index":
case "use_index", "ignore_index", "use_index_merge", "force_index", "order_index", "no_order_index":
n.Tables[0].Restore(ctx)
ctx.WritePlain(" ")
for i, index := range n.Indexes {
Expand Down
12 changes: 12 additions & 0 deletions parser/ast/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,18 @@ func TestTableOptimizerHintRestore(t *testing.T) {
{"IGNORE_INDEX(@sel_1 t1 c1)", "IGNORE_INDEX(@`sel_1` `t1` `c1`)"},
{"IGNORE_INDEX(t1@sel_1 c1)", "IGNORE_INDEX(`t1`@`sel_1` `c1`)"},
{"IGNORE_INDEX(t1@sel_1 partition(p0, p1) c1)", "IGNORE_INDEX(`t1`@`sel_1` PARTITION(`p0`, `p1`) `c1`)"},
{"ORDER_INDEX(t1 c1)", "ORDER_INDEX(`t1` `c1`)"},
{"ORDER_INDEX(test.t1 c1)", "ORDER_INDEX(`test`.`t1` `c1`)"},
{"ORDER_INDEX(@sel_1 t1 c1)", "ORDER_INDEX(@`sel_1` `t1` `c1`)"},
{"ORDER_INDEX(t1@sel_1 c1)", "ORDER_INDEX(`t1`@`sel_1` `c1`)"},
{"ORDER_INDEX(test.t1@sel_1 c1)", "ORDER_INDEX(`test`.`t1`@`sel_1` `c1`)"},
{"ORDER_INDEX(test.t1@sel_1 partition(p0) c1)", "ORDER_INDEX(`test`.`t1`@`sel_1` PARTITION(`p0`) `c1`)"},
{"NO_ORDER_INDEX(t1 c1)", "NO_ORDER_INDEX(`t1` `c1`)"},
{"NO_ORDER_INDEX(test.t1 c1)", "NO_ORDER_INDEX(`test`.`t1` `c1`)"},
{"NO_ORDER_INDEX(@sel_1 t1 c1)", "NO_ORDER_INDEX(@`sel_1` `t1` `c1`)"},
{"NO_ORDER_INDEX(t1@sel_1 c1)", "NO_ORDER_INDEX(`t1`@`sel_1` `c1`)"},
{"NO_ORDER_INDEX(test.t1@sel_1 c1)", "NO_ORDER_INDEX(`test`.`t1`@`sel_1` `c1`)"},
{"NO_ORDER_INDEX(test.t1@sel_1 partition(p0) c1)", "NO_ORDER_INDEX(`test`.`t1`@`sel_1` PARTITION(`p0`) `c1`)"},
{"TIDB_SMJ(`t1`)", "TIDB_SMJ(`t1`)"},
{"TIDB_SMJ(t1)", "TIDB_SMJ(`t1`)"},
{"TIDB_SMJ(t1,t2)", "TIDB_SMJ(`t1`, `t2`)"},
Expand Down
Loading

0 comments on commit 7bd4528

Please sign in to comment.