Skip to content

Commit

Permalink
Fix "EXPLAIN FORMAT=..." by reordering grammar rules
Browse files Browse the repository at this point in the history
  • Loading branch information
JanJakes committed Sep 27, 2024
1 parent 135f29f commit 27524dd
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 1,102 deletions.
40 changes: 20 additions & 20 deletions custom-parser/grammar-factoring/MySQLParser-factored.json
Original file line number Diff line number Diff line change
Expand Up @@ -11535,26 +11535,6 @@
]
]
},
{
"name": "utilityStatement",
"bnf": [
[
"describeStatement"
],
[
"explainStatement"
],
[
"helpCommand"
],
[
"useCommand"
],
[
"restartServer"
]
]
},
{
"name": "%describeStatement684",
"bnf": [
Expand Down Expand Up @@ -22200,6 +22180,26 @@
]
]
},
{
"name": "utilityStatement",
"bnf": [
[
"explainStatement"
],
[
"describeStatement"
],
[
"helpCommand"
],
[
"useCommand"
],
[
"restartServer"
]
]
},
{
"name": "expr",
"bnf": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ alterResourceGroup ::= ALTER_SYMBOL RESOURCE_SYMBOL GROUP_SYMBOL resourceGroupRe
setResourceGroup ::= SET_SYMBOL RESOURCE_SYMBOL GROUP_SYMBOL identifier (FOR_SYMBOL threadIdList)?
threadIdList ::= real_ulong_number (COMMA_SYMBOL? real_ulong_number)*
dropResourceGroup ::= DROP_SYMBOL RESOURCE_SYMBOL GROUP_SYMBOL resourceGroupRef FORCE_SYMBOL?
utilityStatement ::= describeStatement | explainStatement | helpCommand | useCommand | restartServer
/* utilityStatement ::= describeStatement | explainStatement | helpCommand | useCommand | restartServer */
describeStatement ::= (EXPLAIN_SYMBOL | DESCRIBE_SYMBOL | DESC_SYMBOL) tableRef (textString | columnRef)?
explainStatement ::= (EXPLAIN_SYMBOL | DESCRIBE_SYMBOL | DESC_SYMBOL) (EXTENDED_SYMBOL | PARTITIONS_SYMBOL | (FORMAT_SYMBOL EQUAL_OPERATOR textOrIdentifier) | ANALYZE_SYMBOL | (ANALYZE_SYMBOL FORMAT_SYMBOL EQUAL_OPERATOR textOrIdentifier))? explainableStatement
explainableStatement ::= selectStatement | (deleteStatement | insertStatement | replaceStatement | updateStatement) | (FOR_SYMBOL CONNECTION_SYMBOL real_ulong_number)
Expand Down Expand Up @@ -636,6 +636,18 @@ createUser ::= CREATE_SYMBOL USER_SYMBOL ifNotExists? createUserList defaultRole
*/
castType ::= (BINARY_SYMBOL fieldLength?) | (CHAR_SYMBOL fieldLength? charsetWithOptBinary?) | (nchar fieldLength?) | (SIGNED_SYMBOL INT_SYMBOL?) | (UNSIGNED_SYMBOL INT_SYMBOL?) | DATE_SYMBOL | (TIME_SYMBOL typeDatetimePrecision?) | (DATETIME_SYMBOL typeDatetimePrecision?) | (DECIMAL_SYMBOL floatOptions?) | JSON_SYMBOL | realType | (FLOAT_SYMBOL standardFloatOptions?) | YEAR_SYMBOL

/*
* Reorder "explainStatement" and "describeStatement".
* EXPLAIN can be followed by an identifier (matching a "describeStatement"),
* but identifiers can never take precedence over keywords in the grammar.
*
* E.g., in "EXPLAIN FORMAT=JSON ...", the "FORMAT" token needs to match as a keyword
* in the "explainStatement" rather than as an identifier in the "describeStatement".
* At the same time, "EXPLAIN FORMAT" is a valid "describeStatement" with the "FORMAT"
* token as an identifier.
*/
utilityStatement ::= explainStatement | describeStatement | helpCommand | useCommand | restartServer

/* Factor left recursion. */
expr ::= %expr_simple %expr_rr*
%expr_simple ::= (boolPri (IS_SYMBOL notRule? (TRUE_SYMBOL | FALSE_SYMBOL | UNKNOWN_SYMBOL))?) | (NOT_SYMBOL expr)
Expand Down
40 changes: 20 additions & 20 deletions custom-parser/grammar-factoring/MySQLParser-manually-factored.json
Original file line number Diff line number Diff line change
Expand Up @@ -12219,26 +12219,6 @@
]
]
},
{
"name": "utilityStatement",
"bnf": [
[
"describeStatement"
],
[
"explainStatement"
],
[
"helpCommand"
],
[
"useCommand"
],
[
"restartServer"
]
]
},
{
"name": "%describeStatement684",
"bnf": [
Expand Down Expand Up @@ -23323,6 +23303,26 @@
]
]
},
{
"name": "utilityStatement",
"bnf": [
[
"explainStatement"
],
[
"describeStatement"
],
[
"helpCommand"
],
[
"useCommand"
],
[
"restartServer"
]
]
},
{
"name": "expr",
"bnf": [
Expand Down
2 changes: 1 addition & 1 deletion custom-parser/parser/grammar.php

Large diffs are not rendered by default.

Loading

0 comments on commit 27524dd

Please sign in to comment.