From cc7f2308bbd94cadadefaa4a42974ecf896dabf5 Mon Sep 17 00:00:00 2001 From: foreyes Date: Thu, 22 Aug 2019 15:07:08 +0800 Subject: [PATCH 1/2] change memory quota hint --- ast/misc.go | 4 ++-- ast/misc_test.go | 4 ++-- parser.y | 15 +++++++-------- parser_test.go | 8 ++++---- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/ast/misc.go b/ast/misc.go index 97979bf9f..13648c84e 100755 --- a/ast/misc.go +++ b/ast/misc.go @@ -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 } @@ -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 diff --git a/ast/misc_test.go b/ast/misc_test.go index 03325c1d8..1d2f02cef 100644 --- a/ast/misc_test.go +++ b/ast/misc_test.go @@ -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()"}, diff --git a/parser.y b/parser.y index 8f615a259..8fe1be5dd 100644 --- a/parser.y +++ b/parser.y @@ -6550,7 +6550,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 ')' { @@ -6621,15 +6621,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 + 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) } } diff --git a/parser_test.go b/parser_test.go index e603f709e..587872bb5 100644 --- a/parser_test.go +++ b/parser_test.go @@ -2820,18 +2820,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", "", "") From 964f0b4f829a87142d7c832f838d19913031559a Mon Sep 17 00:00:00 2001 From: foreyes Date: Thu, 22 Aug 2019 15:07:44 +0800 Subject: [PATCH 2/2] update parser.go --- parser.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/parser.go b/parser.go index 96bb87248..cf8829cfb 100644 --- a/parser.go +++ b/parser.go @@ -13261,7 +13261,7 @@ yynewstate: } case 1223: { - parser.yyVAL.item = &ast.TableOptimizerHint{HintName: model.NewCIStr(yyS[yypt-4].ident), QBName: yyS[yypt-2].item.(model.CIStr), MemoryQuota: yyS[yypt-1].item.(uint64)} + parser.yyVAL.item = &ast.TableOptimizerHint{HintName: model.NewCIStr(yyS[yypt-4].ident), QBName: yyS[yypt-2].item.(model.CIStr), MemoryQuota: yyS[yypt-1].item.(int64)} } case 1224: { @@ -13321,15 +13321,14 @@ yynewstate: } case 1238: { - // May change into MB/MiB or GB/GiB switch model.NewCIStr(yyS[yypt-0].ident).L { - case "m": - parser.yyVAL.item = getUint64FromNUM(yyS[yypt-1].item) - case "g": - parser.yyVAL.item = getUint64FromNUM(yyS[yypt-1].item) * 1024 + case "mb": + parser.yyVAL.item = yyS[yypt-1].item.(int64) * 1024 * 1024 + case "gb": + parser.yyVAL.item = yyS[yypt-1].item.(int64) * 1024 * 1024 * 1024 default: - // Trigger warning in TiDB Planner - parser.yyVAL.item = uint64(0) + // Executor handle memory quota < 0 as no memory limit, here use it to trigger warning in TiDB. + parser.yyVAL.item = int64(-1) } } case 1239: