Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser,ast: parse statement execution time optimizer hints #7012

Merged
merged 4 commits into from
Jul 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,9 @@ type TableOptimizerHint struct {
// It allows only table name or alias (if table has an alias)
HintName model.CIStr
Tables []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
}

// Accept implements Node Accept interface.
Expand Down
1 change: 1 addition & 0 deletions parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ var tokenMap = map[string]int{
"MASTER": master,
"MAX": max,
"MAX_CONNECTIONS_PER_HOUR": maxConnectionsPerHour,
"MAX_EXECUTION_TIME": maxExecutionTime,
"MAX_QUERIES_PER_HOUR": maxQueriesPerHour,
"MAX_ROWS": maxRows,
"MAX_UPDATES_PER_HOUR": maxUpdatesPerHour,
Expand Down
55 changes: 30 additions & 25 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -403,30 +403,31 @@ import (
yearType "YEAR"

/* The following tokens belong to NotKeywordToken. */
addDate "ADDDATE"
bitAnd "BIT_AND"
bitOr "BIT_OR"
bitXor "BIT_XOR"
cast "CAST"
copyKwd "COPY"
count "COUNT"
curTime "CURTIME"
dateAdd "DATE_ADD"
dateSub "DATE_SUB"
extract "EXTRACT"
getFormat "GET_FORMAT"
groupConcat "GROUP_CONCAT"
inplace "INPLACE"
min "MIN"
max "MAX"
now "NOW"
position "POSITION"
subDate "SUBDATE"
sum "SUM"
substring "SUBSTRING"
timestampAdd "TIMESTAMPADD"
timestampDiff "TIMESTAMPDIFF"
trim "TRIM"
addDate "ADDDATE"
bitAnd "BIT_AND"
bitOr "BIT_OR"
bitXor "BIT_XOR"
cast "CAST"
copyKwd "COPY"
count "COUNT"
curTime "CURTIME"
dateAdd "DATE_ADD"
dateSub "DATE_SUB"
extract "EXTRACT"
getFormat "GET_FORMAT"
groupConcat "GROUP_CONCAT"
inplace "INPLACE"
min "MIN"
max "MAX"
maxExecutionTime "MAX_EXECUTION_TIME"
now "NOW"
position "POSITION"
subDate "SUBDATE"
sum "SUM"
substring "SUBSTRING"
timestampAdd "TIMESTAMPADD"
timestampDiff "TIMESTAMPDIFF"
trim "TRIM"

/* The following tokens belong to TiDBKeyword. */
admin "ADMIN"
Expand Down Expand Up @@ -2760,7 +2761,7 @@ TiDBKeyword:

NotKeywordToken:
"ADDDATE" | "BIT_AND" | "BIT_OR" | "BIT_XOR" | "CAST" | "COPY" | "COUNT" | "CURTIME" | "DATE_ADD" | "DATE_SUB" | "EXTRACT" | "GET_FORMAT" | "GROUP_CONCAT"
| "INPLACE" |"MIN" | "MAX" | "NOW" | "POSITION" | "SUBDATE" | "SUBSTRING" | "SUM" | "TIMESTAMPADD" | "TIMESTAMPDIFF" | "TRIM"
| "INPLACE" |"MIN" | "MAX" | "MAX_EXECUTION_TIME" | "NOW" | "POSITION" | "SUBDATE" | "SUBSTRING" | "SUM" | "TIMESTAMPADD" | "TIMESTAMPDIFF" | "TRIM"

/************************************************************************************
*
Expand Down Expand Up @@ -4598,6 +4599,10 @@ TableOptimizerHintOpt:
{
$$ = &ast.TableOptimizerHint{HintName: model.NewCIStr($1), Tables: $3.([]model.CIStr)}
}
| maxExecutionTime '(' NUM ')'
{
$$ = &ast.TableOptimizerHint{HintName: model.NewCIStr($1), MaxExecutionTime: getUint64FromNUM($3)}
}

SelectStmtCalcFoundRows:
{
Expand Down
8 changes: 8 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1756,6 +1756,14 @@ func (s *testParserSuite) TestOptimizerHints(c *C) {
c.Assert(hints[1].HintName.L, Equals, "tidb_hj")
c.Assert(hints[1].Tables[0].L, Equals, "t3")
c.Assert(hints[1].Tables[1].L, Equals, "t4")

stmt, err = parser.Parse("SELECT /*+ MAX_EXECUTION_TIME(1000) */ * FROM t1 INNER JOIN t2 where t1.c1 = t2.c1", "", "")
c.Assert(err, IsNil)
selectStmt = stmt[0].(*ast.SelectStmt)
hints = selectStmt.TableHints
c.Assert(len(hints), Equals, 1)
c.Assert(hints[0].HintName.L, Equals, "max_execution_time")
c.Assert(hints[0].MaxExecutionTime, Equals, uint64(1000))
}

func (s *testParserSuite) TestType(c *C) {
Expand Down