Skip to content

Commit 3f62ad0

Browse files
authored
feat: use SLL mode (#269)
* feat: use SLL(*) PredictionMode for better performance * feat: optimize mysql grammar to fit SLL mode * feat: optimize postgre grammmar to fit SLL mode * feat: optimize spark grammar to fit SLL mode * test: correct unit tests * feat: optimize pgsql grammar
1 parent a05f099 commit 3f62ad0

17 files changed

+28492
-28914
lines changed

src/grammar/mysql/MySqlParser.g4

+39-39
Original file line numberDiff line numberDiff line change
@@ -902,18 +902,27 @@ replaceStatement
902902
)? (('(' columnNames ')')? replaceStatementValuesOrSelectOrTable | setAssignmentList)
903903
;
904904

905-
// into clause within a given statement can appear only once
905+
// selectStatement
906+
// : querySpecification lockClause? # simpleSelect
907+
// | querySpecificationNointo lockClause? intoClause? # simpleSelect
908+
// | queryExpression lockClause? # parenthesisSelect
909+
// | querySpecificationNointo unionStatement+ (
910+
// KW_UNION unionType=(KW_ALL | KW_DISTINCT)? (querySpecification | queryExpression)
911+
// )? orderByClause? limitClause? lockClause? # unionSelect
912+
// | queryExpressionNointo unionParenthesis+ (
913+
// KW_UNION unionType=(KW_ALL | KW_DISTINCT)? queryExpression
914+
// )? orderByClause? limitClause? lockClause? # unionParenthesisSelect
915+
// | querySpecificationNointo (',' lateralStatement)+ # withLateralStatement
916+
// ;
917+
918+
// TODO: Simplify the rules to fit SLL(*) Mode
906919
selectStatement
907-
: querySpecification lockClause? # simpleSelect
908-
| querySpecificationNointo lockClause? intoClause? # simpleSelect
909-
| queryExpression lockClause? # parenthesisSelect
910-
| querySpecificationNointo unionStatement+ (
920+
: querySpecification unionStatement* (
911921
KW_UNION unionType=(KW_ALL | KW_DISTINCT)? (querySpecification | queryExpression)
912-
)? orderByClause? limitClause? lockClause? # unionSelect
913-
| queryExpressionNointo unionParenthesis+ (
922+
)? (',' lateralStatement)* orderByClause? limitClause? lockClause? intoClause? # unionAndLateralSelect
923+
| queryExpression unionStatement* (
914924
KW_UNION unionType=(KW_ALL | KW_DISTINCT)? queryExpression
915-
)? orderByClause? limitClause? lockClause? # unionParenthesisSelect
916-
| querySpecificationNointo (',' lateralStatement)+ # withLateralStatement
925+
)? orderByClause? limitClause? lockClause? # selectExpression
917926
;
918927

919928
// https://dev.mysql.com/doc/refman/8.0/en/set-operations.html
@@ -1106,34 +1115,24 @@ queryExpression
11061115
| '(' queryExpression ')'
11071116
;
11081117

1109-
queryExpressionNointo
1110-
: '(' querySpecificationNointo ')'
1111-
| '(' queryExpressionNointo ')'
1112-
;
1113-
1114-
// into clause within a given statement can appear only once
1118+
/**
1119+
* TODO: intoClause is allowed to appear multiple times,
1120+
* which is inconsistent with the actual syntax,
1121+
* but is currently unsolvable because the correct syntax cannot be handled by SLL(*) Mode
1122+
*/
11151123
querySpecification
1116-
: KW_SELECT selectSpec* selectElements intoClause? fromClause groupByClause? havingClause? windowClause? orderByClause? limitClause?
1117-
| KW_SELECT selectSpec* selectElements fromClause groupByClause? havingClause? windowClause? orderByClause? limitClause? intoClause?
1118-
;
1119-
1120-
querySpecificationNointo
1121-
: KW_SELECT selectSpec* selectElements fromClause groupByClause? havingClause? windowClause? orderByClause? limitClause?
1122-
;
1123-
1124-
unionParenthesis
1125-
: KW_UNION unionType=(KW_ALL | KW_DISTINCT)? queryExpressionNointo
1124+
: KW_SELECT selectSpec* selectElements intoClause? fromClause groupByClause? havingClause? windowClause? orderByClause? limitClause? intoClause?
11261125
;
11271126

11281127
unionStatement
1129-
: KW_UNION unionType=(KW_ALL | KW_DISTINCT)? (querySpecificationNointo | queryExpressionNointo)
1128+
: KW_UNION unionType=(KW_ALL | KW_DISTINCT)? (querySpecification | queryExpression)
11301129
;
11311130

11321131
lateralStatement
11331132
: KW_LATERAL (
1134-
querySpecificationNointo
1135-
| queryExpressionNointo
1136-
| ('(' (querySpecificationNointo | queryExpressionNointo) ')' (KW_AS? alias=uid)?)
1133+
querySpecification
1134+
| queryExpression
1135+
| ('(' (querySpecification | queryExpression) ')' (KW_AS? alias=uid)?)
11371136
)
11381137
;
11391138

@@ -1187,10 +1186,10 @@ selectElements
11871186
;
11881187

11891188
selectElement
1190-
: select_element=fullId '.' '*' # selectStarElement
1191-
| columnName (KW_AS? alias=uid)? # selectColumnElement
1189+
: (LOCAL_ID VAR_ASSIGN)? expression (KW_AS? alias=uid)? # selectExpressionElement
11921190
| functionCall (KW_AS? alias=uid)? # selectFunctionElement
1193-
| (LOCAL_ID VAR_ASSIGN)? expression (KW_AS? alias=uid)? # selectExpressionElement
1191+
| select_element=fullId '.' '*' # selectStarElement
1192+
| columnName (KW_AS? alias=uid)? # selectColumnElement
11941193
;
11951194

11961195
intoClause
@@ -1767,13 +1766,14 @@ userSpecification
17671766
;
17681767

17691768
alterUserAuthOption
1770-
: userName KW_IDENTIFIED KW_BY STRING_LITERAL authOptionClause
1771-
| userName KW_IDENTIFIED KW_BY KW_RANDOM KW_PASSWORD authOptionClause
1772-
| userName KW_IDENTIFIED KW_WITH authenticationRule
1773-
| userName KW_DISCARD KW_OLD KW_PASSWORD
1774-
| userName ((KW_ADD | KW_MODIFY | KW_DROP) factor factorAuthOption?)+
1775-
| userName registrationOption?
1776-
| userName
1769+
: userName (
1770+
KW_IDENTIFIED KW_BY STRING_LITERAL authOptionClause
1771+
| KW_IDENTIFIED KW_BY KW_RANDOM KW_PASSWORD authOptionClause
1772+
| KW_IDENTIFIED KW_WITH authenticationRule
1773+
| KW_DISCARD KW_OLD KW_PASSWORD
1774+
| ((KW_ADD | KW_MODIFY | KW_DROP) factor factorAuthOption?)+
1775+
| registrationOption
1776+
)?
17771777
;
17781778

17791779
// createUser auth_option, 2fa_auth_option, 3fa_auth_option

0 commit comments

Comments
 (0)