Skip to content

Commit

Permalink
[MySql] Synchronize grammar and tests; remove Mariadb grammars
Browse files Browse the repository at this point in the history
  • Loading branch information
ani-sha committed Jan 9, 2025
1 parent 4a95d4d commit 66c8ab0
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 59 deletions.
9 changes: 5 additions & 4 deletions sql/mysql/Positive-Technologies/MySqlLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ COMMIT : 'COMMIT';
COMPACT : 'COMPACT';
COMPLETION : 'COMPLETION';
COMPRESSED : 'COMPRESSED';
COMPRESSION : 'COMPRESSION';
COMPRESSION : 'COMPRESSION' | QUOTE_SYMB? 'COMPRESSION' QUOTE_SYMB?;
CONCURRENT : 'CONCURRENT';
CONNECT : 'CONNECT';
CONNECTION : 'CONNECTION';
Expand Down Expand Up @@ -1169,6 +1169,7 @@ SUBSTRING_INDEX : 'SUBSTRING_INDEX';
SUBTIME : 'SUBTIME';
SYSTEM_USER : 'SYSTEM_USER';
TAN : 'TAN';
TELEMETRY_LOG_ADMIN : 'TELEMETRY_LOG_ADMIN';
TIMEDIFF : 'TIMEDIFF';
TIMESTAMPADD : 'TIMESTAMPADD';
TIMESTAMPDIFF : 'TIMESTAMPDIFF';
Expand Down Expand Up @@ -1272,9 +1273,9 @@ DECIMAL_LITERAL : DEC_DIGIT+;
HEXADECIMAL_LITERAL : 'X' '\'' (HEX_DIGIT HEX_DIGIT)+ '\'' | '0X' HEX_DIGIT+;

REAL_LITERAL:
DEC_DIGIT* '.' DEC_DIGIT+
(DEC_DIGIT+)? '.' DEC_DIGIT*
| DEC_DIGIT+ '.' EXPONENT_NUM_PART
| DEC_DIGIT* '.' (DEC_DIGIT+ EXPONENT_NUM_PART)
| (DEC_DIGIT+)? '.' (DEC_DIGIT+ EXPONENT_NUM_PART)
| DEC_DIGIT+ EXPONENT_NUM_PART
;
NULL_SPEC_LITERAL : '\\' 'N';
Expand Down Expand Up @@ -1354,4 +1355,4 @@ fragment IP_ADDRESS : [0-9]+ '.' [0-9.]+ | [0-9A-F]* ':' [0-9A-F]* ':' [0

// Last tokens must generate Errors

ERROR_RECONGNIGION: . -> channel(ERRORCHANNEL);
ERROR_RECONGNIGION: . -> channel(ERRORCHANNEL);
74 changes: 41 additions & 33 deletions sql/mysql/Positive-Technologies/MySqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ createLogfileGroup
;

createProcedure
: CREATE ownerStatement? PROCEDURE fullId '(' procedureParameter? (',' procedureParameter)* ')' routineOption* routineBody
: CREATE ownerStatement? PROCEDURE ifNotExists? fullId '(' procedureParameter? (',' procedureParameter)* ')' routineOption* routineBody
;

createFunction
Expand Down Expand Up @@ -286,11 +286,12 @@ createTablespaceNdb
;

createTrigger
: CREATE ownerStatement? TRIGGER ifNotExists? thisTrigger = fullId triggerTime = (BEFORE | AFTER) triggerEvent = (
INSERT
| UPDATE
| DELETE
) ON tableName FOR EACH ROW (triggerPlace = (FOLLOWS | PRECEDES) otherTrigger = fullId)? routineBody
: CREATE ownerStatement? TRIGGER ifNotExists? thisTrigger = fullId triggerTime = (
BEFORE
| AFTER
) triggerEvent = (INSERT | UPDATE | DELETE) ON tableName FOR EACH ROW (
triggerPlace = (FOLLOWS | PRECEDES) otherTrigger = fullId
)? routineBody
;

withClause
Expand Down Expand Up @@ -632,7 +633,7 @@ alterServer
;

alterTable
: ALTER intimeAction = (ONLINE | OFFLINE)? IGNORE? TABLE tableName waitNowaitClause? (
: ALTER intimeAction = (ONLINE | OFFLINE)? IGNORE? TABLE tableName (
alterSpecification (',' alterSpecification)*
)? partitionDefinitions?
;
Expand Down Expand Up @@ -685,7 +686,7 @@ alterSpecification
| DROP DEFAULT
) # alterByAlterColumnDefault
| ALTER INDEX uid (VISIBLE | INVISIBLE) # alterByAlterIndexVisibility
| DROP FOREIGN KEY uid # alterByDropForeignKey
| DROP FOREIGN KEY uid dottedId? # alterByDropForeignKey
| DISABLE KEYS # alterByDisableKeys
| ENABLE KEYS # alterByEnableKeys
| RENAME renameFormat = (TO | AS)? (uid | fullId) # alterByRename
Expand Down Expand Up @@ -1011,12 +1012,12 @@ queryExpressionNointo
;

querySpecification
: SELECT selectSpec* selectElements selectIntoExpression? fromClause groupByClause? havingClause? windowClause? orderByClause? limitClause?
| SELECT selectSpec* selectElements fromClause groupByClause? havingClause? windowClause? orderByClause? limitClause? selectIntoExpression?
: SELECT selectSpec* selectElements selectIntoExpression? fromClause? groupByClause? havingClause? windowClause? orderByClause? limitClause?
| SELECT selectSpec* selectElements fromClause? groupByClause? havingClause? windowClause? orderByClause? limitClause? selectIntoExpression?
;

querySpecificationNointo
: SELECT selectSpec* selectElements fromClause groupByClause? havingClause? windowClause? orderByClause? limitClause? unionStatement?
: SELECT selectSpec* selectElements fromClause? groupByClause? havingClause? windowClause? orderByClause? limitClause? unionStatement?
;

unionParenthesis
Expand All @@ -1039,7 +1040,7 @@ lateralStatement

// https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
jsonTable
: JSON_TABLE '(' STRING_LITERAL ',' STRING_LITERAL COLUMNS '(' jsonColumnList ')' ')' (AS? uid)?
: JSON_TABLE '(' expression ',' STRING_LITERAL COLUMNS '(' jsonColumnList ')' ')' (AS? uid)?
;

jsonColumnList
Expand Down Expand Up @@ -1171,7 +1172,7 @@ releaseStatement
;

lockTables
: LOCK (TABLE | TABLES) lockTableElement (',' lockTableElement)* waitNowaitClause?
: LOCK (TABLE | TABLES) lockTableElement (',' lockTableElement)*
;

unlockTables
Expand Down Expand Up @@ -1541,16 +1542,17 @@ renameUser
;

revokeStatement
: REVOKE ifExists? (privelegeClause | uid) (',' privelegeClause | uid)*
ON
privilegeObject=(TABLE | FUNCTION | PROCEDURE)?
privilegeLevel
FROM userName (',' userName)* (IGNORE UNKNOWN USER)? #detailRevoke
| REVOKE ifExists? ALL PRIVILEGES? ',' GRANT OPTION
FROM userName (',' userName)* (IGNORE UNKNOWN USER)? #shortRevoke
| REVOKE ifExists? (userName | uid) (',' (userName | uid))*
FROM (userName | uid) (',' (userName | uid))*
(IGNORE UNKNOWN USER)? #roleRevoke
: REVOKE ifExists? (privelegeClause | uid) (',' privelegeClause | uid)* ON privilegeObject = (
TABLE
| FUNCTION
| PROCEDURE
)? privilegeLevel FROM userName (',' userName)* (IGNORE UNKNOWN USER)? # detailRevoke
| REVOKE ifExists? ALL PRIVILEGES? ',' GRANT OPTION FROM userName (',' userName)* (
IGNORE UNKNOWN USER
)? # shortRevoke
| REVOKE ifExists? (userName | uid) (',' (userName | uid))* FROM (userName | uid) (
',' (userName | uid)
)* (IGNORE UNKNOWN USER)? # roleRevoke
;

revokeProxy
Expand Down Expand Up @@ -1681,6 +1683,7 @@ privilege
| SYSTEM_USER
| SYSTEM_VARIABLES_ADMIN
| TABLE_ENCRYPTION_ADMIN
| TELEMETRY_LOG_ADMIN
| TP_CONNECTION_ADMIN
| VERSION_TOKEN_ADMIN
| XA_RECOVER_ADMIN
Expand Down Expand Up @@ -2222,10 +2225,10 @@ dataType
SIGNED
| UNSIGNED
| ZEROFILL
)* # dimensionDataType
| typeName = (DATE | TINYBLOB | MEDIUMBLOB | LONGBLOB | BOOL | BOOLEAN | SERIAL) # simpleDataType
)* # dimensionDataType
| typeName = (DATE | TINYBLOB | MEDIUMBLOB | LONGBLOB | BOOL | BOOLEAN | SERIAL) # simpleDataType
| typeName = (BIT | TIME | TIMESTAMP | DATETIME | BINARY | VARBINARY | BLOB | YEAR | VECTOR) lengthOneDimension? # dimensionDataType
| typeName = (ENUM | SET) collectionOptions BINARY? (charSet charsetName)? # collectionDataType
| typeName = (ENUM | SET) collectionOptions BINARY? (charSet charsetName)? # collectionDataType
| typeName = (
GEOMETRYCOLLECTION
| GEOMCOLLECTION
Expand Down Expand Up @@ -2341,11 +2344,6 @@ orReplace
: OR REPLACE
;

waitNowaitClause
: WAIT decimalLiteral
| NOWAIT
;

// Functions

functionCall
Expand Down Expand Up @@ -2439,7 +2437,7 @@ nonAggregateWindowedFunction
;

overClause
: OVER ('(' windowSpec ')' | windowName)
: OVER ('(' windowSpec? ')' | windowName)
;

windowSpec
Expand Down Expand Up @@ -2715,6 +2713,7 @@ keywordsCanBeId
| AGGREGATE
| ALGORITHM
| ANY
| APPLICATION_PASSWORD_ADMIN
| ARRAY
| AT
| AUDIT_ADMIN
Expand Down Expand Up @@ -2838,11 +2837,16 @@ keywordsCanBeId
| FIRST
| FIXED
| FLUSH
| FLUSH_OPTIMIZER_COSTS
| FLUSH_STATUS
| FLUSH_TABLES
| FLUSH_USER_RESOURCES
| FOLLOWS
| FOUND
| FULL
| FUNCTION
| GENERAL
| GEOMETRY
| GLOBAL
| GRANTS
| GROUP
Expand All @@ -2862,6 +2866,7 @@ keywordsCanBeId
| INDEXES
| INITIAL_SIZE
| INNODB_REDO_LOG_ARCHIVE
| INNODB_REDO_LOG_ENABLE
| INPLACE
| INSERT_METHOD
| INSTALL
Expand Down Expand Up @@ -2934,6 +2939,7 @@ keywordsCanBeId
| MYSQL_ERRNO
| NAME
| NAMES
| NATIONAL
| NCHAR
| NDB_STORED_USER
| NESTED
Expand Down Expand Up @@ -3082,10 +3088,12 @@ keywordsCanBeId
| SWAPS
| SWITCHES
| SYSTEM_VARIABLES_ADMIN
| SYSTEM_USER
| TABLE_NAME
| TABLESPACE
| TABLE_ENCRYPTION_ADMIN
| TABLE_TYPE
| TELEMETRY_LOG_ADMIN
| TEMPORARY
| TEMPTABLE
| THAN
Expand Down Expand Up @@ -3497,4 +3505,4 @@ functionNameBase
| JSON_ARRAYAGG
| JSON_OBJECTAGG
| STATEMENT
;
;
39 changes: 34 additions & 5 deletions sql/mysql/Positive-Technologies/examples/ddl_alter.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#begin
-- Alter Table
alter table ship_class add column ship_spec varchar(150) first, add somecol int after start_build;
alter table ship_class add column ship_spec varchar(150) first, add somecol int after start_build, algorithm=instant;
alter table t3 add column (c2 decimal(10, 2) comment 'comment`' null, c3 enum('abc', 'cba', 'aaa')), add index t3_i1 using btree (c2) comment 'some index';
alter table t3 add column (c4 decimal(10, 2) comment 'comment`' null), add index t3_i2 using btree (c4) comment 'some index';
alter table t3 add column (c2 decimal(10, 2), c3 int);
ALTER TABLE `deals` ADD INDEX `idx_custom_field_30c4f4a7c529ccf0825b2fac732bebfd843ed764` ((cast(json_unquote(json_extract(`custom_fields`,_utf8mb4'$."30c4f4a7c529ccf0825b2fac732bebfd843ed764".value')) as DOUBLE)));
ALTER TABLE `deals` ADD INDEX `idx_custom_field_30c4f4a7c529ccf0825b2fac732bebfd843ed764` ((cast(json_unquote(json_extract(`custom_fields`,_utf8mb4'$."30c4f4a7c529ccf0825b2fac732bebfd843ed764".value')) as FLOAT)));
Expand Down Expand Up @@ -30,7 +31,7 @@ alter table with_check add check (c1 in (1, 2, 3, 4));
alter table with_partition add partition (partition p201901 values less than (737425) engine = InnoDB);
alter table with_partition add partition (partition p1 values less than (837425) engine = InnoDB, partition p2 values less than (MAXVALUE) engine = InnoDB);
alter table t1 stats_auto_recalc=default stats_sample_pages=50;
alter table t1 stats_auto_recalc=default, stats_sample_pages=50;
alter table t1 stats_auto_recalc=default, stats_sample_pages=50.0;
alter table t1 stats_auto_recalc=default, stats_sample_pages=default;
alter table t1 modify column c1 enum('abc','cba','aaa') character set 'utf8' collate 'utf8_unicode_ci' not null default 'abc';
alter table table1 add primary key (id);
Expand All @@ -42,7 +43,10 @@ alter table table1 drop constraint cons;
alter table table1 add column yes varchar(255) default '' null;
alter table add_test add column col1 int not null;
alter table `some_table` add (primary key `id` (`id`),`k_id` int unsigned not null,`another_field` smallint not null,index `k_id` (`k_id`));
alter table `some_table` add column (unique key `another_field` (`another_field`));
alter table add_test add column optional bool default 0 null;
alter table add_test add column empty varchar(255);
alter table add_test add column geometry int;
alter table add_test drop foreign key fk;
alter table default.task add column xxxx varchar(200) comment 'cdc test';
ALTER TABLE `hcore`.comments COLLATE='utf8mb4_general_ci', CONVERT TO CHARSET UTF8MB4;
ALTER TABLE T1 ADD FOREIGN KEY ( I ) REFERENCES TT ( I ) ON DELETE SET DEFAULT;
Expand Down Expand Up @@ -101,9 +105,34 @@ alter tablespace tblsp_2 drop datafile 'deletedfilename' wait engine ndb;
alter view my_view1 as select 1 union select 2 limit 0,5;
alter algorithm = merge view my_view2(col1, col2) as select * from t2 with check option;
alter definer = 'ivan'@'%' view my_view3 as select count(*) from t3;
alter definer = current_user sql security invoker view my_view4(c1, 1c, _, c1_2)
alter definer = current_user sql security invoker view my_view4(c1, 1c, _, c1_2)
as select * from (t1 as tt1, t2 as tt2) inner join t1 on t1.col1 = tt1.col1;
#end
#begin
-- Alter user
alter user 'user'@'%' identified with 'mysql_native_password' as '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19'
require none password expire default account unlock password history default;
alter user 'user'@'%' identified with 'mysql_native_password' as '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19'
require none password expire default account unlock password history 90;
alter user 'user'@'%' identified with 'mysql_native_password' as '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19'
require none password expire default account unlock password reuse interval default;
alter user 'user'@'%' identified with 'mysql_native_password' as '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19'
require none password expire default account unlock password reuse interval 360 DAY;
alter user 'user'@'%' identified with 'mysql_native_password' as '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19'
require none password expire default account unlock password require current;
alter user 'user'@'%' identified with 'mysql_native_password' as '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19'
require none password expire default account unlock password require current optional;
alter user 'user'@'%' identified with 'mysql_native_password' as '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19'
require none password expire default account unlock password require current default;
alter user 'user'@'%' identified with 'mysql_native_password' as '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19'
require none password expire default account unlock failed_login_attempts 5;
alter user 'user'@'%' identified with 'mysql_native_password' as '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19'
require none password expire default account unlock password_lock_time 2;
alter user 'user'@'%' identified with 'mysql_native_password' as '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19'
require none password expire default account unlock password_lock_time unbounded;
alter user 'user'@'%' identified by 'newpassword' retain current password;
alter user if exists 'user'@'%' identified with 'mysql_native_password' as '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19'
require none password expire default account unlock password history default;
ALTER USER 'mattias.hultman' DEFAULT ROLE `prod-spain-mysql-read-only`@`%`;
rename user user1@100.200.1.1 to user2@100.200.1.2;
rename user user1@100.200.1.1 to user2@2001:0db8:85a3:0000:0000:8a2e:0370:7334;
Expand All @@ -116,4 +145,4 @@ ALTER USER 'test_dual_pass'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*247
ALTER USER 'test_dual_pass'@'%' IDENTIFIED WITH 'mysql_native_password' AS 'REDACTED' RETAIN CURRENT PASSWORD;
ALTER USER 'test_dual_pass'@'%' IDENTIFIED WITH 'mysql_native_password' BY '2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' REPLACE 'current_auth_string' RETAIN CURRENT PASSWORD;
ALTER USER 'test_dual_pass'@'%' IDENTIFIED WITH 'mysql_native_password' BY RANDOM PASSWORD REPLACE 'current_auth_string' RETAIN CURRENT PASSWORD;
#end
#end
Loading

0 comments on commit 66c8ab0

Please sign in to comment.