Bug #77047 Optimizer hint parser doesn't accept number-prefixed query block names after @
Submitted: 15 May 2015 7:56 Modified: 20 May 2015 16:44
Reporter: Gleb Shchepa Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Parser Severity:S3 (Non-critical)
Version:5.7 OS:Any
Assigned to: CPU Architecture:Any

[15 May 2015 7:56] Gleb Shchepa
Description:
Table and query block names in optimizer hints follow the same rules as identifiers in the MySQL syntax, including identifiers with numerical prefixes.

However, there is an exclusion: BQ_NAME(123a) is allowed, but t1@123a is not.

How to repeat:
mysql> EXPLAIN SELECT /*+ QB_NAME(1a) BKA(t1@1a) */ 1 FROM t1;
...
1 row in set, 2 warnings (0,01 sec)

# See the 1st warning:

mysql> SHOW WARNINGS\G
*************************** 1. row ***************************
  Level: Warning
   Code: 1064
Message: Optimizer hint syntax error near '1a) */ 1 FROM t1' at line 1
*************************** 2. row ***************************
  Level: Note
   Code: 1003
Message: /* select#1 */ select /*+ QB_NAME("1a") */ 1 AS "1" from "test"."t1"
2 rows in set (0,00 sec)

# But:

mysql> EXPLAIN SELECT /*+ QB_NAME(1a) */ 1 FROM t1;
...
1 row in set, 1 warning (0,00 sec)

mysql> SHOW WARNINGS\G
*************************** 1. row ***************************
  Level: Note
   Code: 1003
Message: /* select#1 */ select /*+ QB_NAME("1a") */ 1 AS "1" from "test"."t1"
1 row in set (0,00 sec)

Suggested fix:
Fix the hint parser to accept numeric prefixes in query block names in the "table@query_block_name" syntax.
[20 May 2015 16:44] Paul DuBois
Noted in 5.7.8, 5.8.0 changelogs.

Optimizer hint query block names are identifiers, but the parser did
not recognize valid identifer names such as 123a when used in
@query_block_name syntax.