Skip to content
20 changes: 17 additions & 3 deletions ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2027,9 +2027,10 @@ type TableOptimizerHint struct {
// It allows only table name or alias (if table has an alias)
HintName model.CIStr
// QBName is the default effective query block of this hint.
QBName model.CIStr
Tables []HintTable
Indexes []model.CIStr
QBName model.CIStr
Tables []HintTable
Indexes []model.CIStr
StoreType model.CIStr
// Statement Execution Time Optimizer Hints
// See https://dev.mysql.com/doc/refman/5.7/en/optimizer-hints.html#optimizer-hints-execution-time
MaxExecutionTime uint64
Expand Down Expand Up @@ -2101,6 +2102,19 @@ func (n *TableOptimizerHint) Restore(ctx *RestoreCtx) error {
ctx.WriteKeyWord(n.QueryType.String())
case "memory_quota":
ctx.WritePlainf("%d MB", n.MemoryQuota/1024/1024)
case "read_from_storage":
ctx.WriteKeyWord(n.StoreType.String())
for i, table := range n.Tables {
if i == 0 {
ctx.WritePlain("[")
}
table.Restore(ctx)
if i == len(n.Tables)-1 {
ctx.WritePlain("]")
} else {
ctx.WritePlain(", ")
}
}
}
ctx.WritePlain(")")
return nil
Expand Down
1 change: 1 addition & 0 deletions ast/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ func (ts *testMiscSuite) TestTableOptimizerHintRestore(c *C) {
{"READ_CONSISTENT_REPLICA()", "READ_CONSISTENT_REPLICA()"},
{"READ_CONSISTENT_REPLICA(@sel1)", "READ_CONSISTENT_REPLICA(@`sel1`)"},
{"QB_NAME(sel1)", "QB_NAME(`sel1`)"},
{"READ_FROM_STORAGE(@sel TIFLASH[t1, t2])", "READ_FROM_STORAGE(@`sel` TIFLASH[`t1`, `t2`])"},
}
extractNodeFunc := func(node Node) Node {
return node.(*SelectStmt).TableHints[0]
Expand Down
5 changes: 5 additions & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func init() {
initTokenByte('<', int('<'))
initTokenByte('(', int('('))
initTokenByte(')', int(')'))
initTokenByte('[', int('['))
initTokenByte(']', int(']'))
Comment thread
alivxxx marked this conversation as resolved.
initTokenByte(';', int(';'))
initTokenByte(',', int(','))
initTokenByte('&', int('&'))
Expand Down Expand Up @@ -457,6 +459,7 @@ var tokenMap = map[string]int{
"REBUILD": rebuild,
"READ": read,
"READ_CONSISTENT_REPLICA": hintReadConsistentReplica,
"READ_FROM_STORAGE": hintReadFromStorage,
"REAL": realType,
"RECENT": recent,
"REDUNDANT": redundant,
Expand Down Expand Up @@ -576,6 +579,8 @@ var tokenMap = map[string]int{
"TIDB_HJ": hintHJ,
"TIDB_INLJ": hintINLJ,
"TIDB_SMJ": hintSMJ,
"TIKV": hintTiKV,
"TIFLASH": hintTiFlash,
"TIME": timeType,
"TIMESTAMP": timestampType,
"TIMESTAMPADD": timestampAdd,
Expand Down
Loading