Skip to content
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
4 changes: 2 additions & 2 deletions ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2033,7 +2033,7 @@ type TableOptimizerHint struct {
// Statement Execution Time Optimizer Hints
// See https://dev.mysql.com/doc/refman/5.7/en/optimizer-hints.html#optimizer-hints-execution-time
MaxExecutionTime uint64
MemoryQuota uint64
MemoryQuota int64
QueryType model.CIStr
HintFlag bool
}
Expand Down Expand Up @@ -2100,7 +2100,7 @@ func (n *TableOptimizerHint) Restore(ctx *RestoreCtx) error {
case "query_type":
ctx.WriteKeyWord(n.QueryType.String())
case "memory_quota":
ctx.WritePlainf("%d M", n.MemoryQuota)
ctx.WritePlainf("%d MB", n.MemoryQuota/1024/1024)
}
ctx.WritePlain(")")
return nil
Expand Down
4 changes: 2 additions & 2 deletions ast/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ func (ts *testMiscSuite) TestTableOptimizerHintRestore(c *C) {
{"QUERY_TYPE(OLAP)", "QUERY_TYPE(OLAP)"},
{"QUERY_TYPE(OLTP)", "QUERY_TYPE(OLTP)"},
{"QUERY_TYPE(@sel1 OLTP)", "QUERY_TYPE(@`sel1` OLTP)"},
{"MEMORY_QUOTA(1 G)", "MEMORY_QUOTA(1024 M)"},
{"MEMORY_QUOTA(@sel1 1 G)", "MEMORY_QUOTA(@`sel1` 1024 M)"},
{"MEMORY_QUOTA(1 GB)", "MEMORY_QUOTA(1024 MB)"},
{"MEMORY_QUOTA(@sel1 1 GB)", "MEMORY_QUOTA(@`sel1` 1024 MB)"},
{"HASH_AGG()", "HASH_AGG()"},
{"HASH_AGG(@sel1)", "HASH_AGG(@`sel1`)"},
{"STREAM_AGG()", "STREAM_AGG()"},
Expand Down
15 changes: 7 additions & 8 deletions parser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -6548,7 +6548,7 @@ TableOptimizerHintOpt:
}
| hintMemoryQuota '(' QueryBlockOpt HintMemoryQuota ')'
{
$$ = &ast.TableOptimizerHint{HintName: model.NewCIStr($1), QBName: $3.(model.CIStr), MemoryQuota: $4.(uint64)}
$$ = &ast.TableOptimizerHint{HintName: model.NewCIStr($1), QBName: $3.(model.CIStr), MemoryQuota: $4.(int64)}
}
| hintHASHAGG '(' QueryBlockOpt ')'
{
Expand Down Expand Up @@ -6619,15 +6619,14 @@ HintQueryType:
HintMemoryQuota:
NUM Identifier
{
// May change into MB/MiB or GB/GiB
switch model.NewCIStr($2).L {
case "m":
$$ = getUint64FromNUM($1)
case "g":
$$ = getUint64FromNUM($1) * 1024
case "mb":
$$ = $1.(int64) * 1024 * 1024
Comment thread
lzmhhh123 marked this conversation as resolved.
case "gb":
$$ = $1.(int64) * 1024 * 1024 * 1024
default:
// Trigger warning in TiDB Planner
$$ = uint64(0)
// Executor handle memory quota < 0 as no memory limit, here use it to trigger warning in TiDB.
$$ = int64(-1)
}
}

Expand Down
8 changes: 4 additions & 4 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2835,18 +2835,18 @@ func (s *testParserSuite) TestOptimizerHints(c *C) {
c.Assert(hints[1].QueryType.L, Equals, "oltp")

// Test MEMORY_QUOTA
stmt, _, err = parser.Parse("select /*+ MEMORY_QUOTA(1 M), memory_quota(1 G), memory_quota(1 MG) */ c1, c2 from t1, t2 where t1.c1 = t2.c1", "", "")
stmt, _, err = parser.Parse("select /*+ MEMORY_QUOTA(1 MB), memory_quota(1 GB), memory_quota(1 NO_SUCH_UNIT) */ c1, c2 from t1, t2 where t1.c1 = t2.c1", "", "")
c.Assert(err, IsNil)
selectStmt = stmt[0].(*ast.SelectStmt)

hints = selectStmt.TableHints
c.Assert(hints, HasLen, 3)
c.Assert(hints[0].HintName.L, Equals, "memory_quota")
c.Assert(hints[0].MemoryQuota, Equals, uint64(1))
c.Assert(hints[0].MemoryQuota, Equals, int64(1024*1024))
c.Assert(hints[1].HintName.L, Equals, "memory_quota")
c.Assert(hints[1].MemoryQuota, Equals, uint64(1024))
c.Assert(hints[1].MemoryQuota, Equals, int64(1024*1024*1024))
c.Assert(hints[2].HintName.L, Equals, "memory_quota")
c.Assert(hints[2].MemoryQuota, Equals, uint64(0))
c.Assert(hints[2].MemoryQuota, Equals, int64(-1))

// Test HASH_AGG
stmt, _, err = parser.Parse("select /*+ HASH_AGG(), hash_agg() */ c1, c2 from t1, t2 where t1.c1 = t2.c1", "", "")
Expand Down