DBZ-2219 Expanding support for MariaDB IF EXISTS/IF NOT EXISTS support on ALTER TABLE ddl

This commit is contained in:
Justin Hiza 2020-06-17 11:34:41 -04:00 committed by Gunnar Morling
parent 99a8a984fa
commit 5bf573633f
3 changed files with 22 additions and 10 deletions

View File

@ -591,13 +591,13 @@ alterView
alterSpecification
: tableOption (','? tableOption)* #alterByTableOption
| ADD COLUMN? uid columnDefinition (FIRST | AFTER uid)? #alterByAddColumn
| ADD COLUMN? ifNotExists? uid columnDefinition (FIRST | AFTER uid)? #alterByAddColumn // ifNotExists is MariaDB-specific
| ADD COLUMN?
'('
uid columnDefinition ( ',' uid columnDefinition)*
')' #alterByAddColumns
| ADD indexFormat=(INDEX | KEY) uid? indexType?
indexColumnNames indexOption* #alterByAddIndex
| ADD indexFormat=(INDEX | KEY) ifNotExists? uid? indexType?
indexColumnNames indexOption* #alterByAddIndex // ifNotExists is MariaDB-specific
| ADD (CONSTRAINT name=uid?)? PRIMARY KEY index=uid?
indexType? indexColumnNames indexOption* #alterByAddPrimaryKey
| ADD (CONSTRAINT name=uid?)? UNIQUE
@ -606,20 +606,20 @@ alterSpecification
| ADD keyType=(FULLTEXT | SPATIAL)
indexFormat=(INDEX | KEY)? uid?
indexColumnNames indexOption* #alterByAddSpecialIndex
| ADD (CONSTRAINT name=uid?)? FOREIGN KEY
indexName=uid? indexColumnNames referenceDefinition #alterByAddForeignKey
| ADD (CONSTRAINT name=uid?)? FOREIGN KEY ifNotExists?
indexName=uid? indexColumnNames referenceDefinition #alterByAddForeignKey // ifNotExists is MariaDB-specific
| ADD (CONSTRAINT name=uid?)? CHECK '(' expression ')' #alterByAddCheckTableConstraint
| ALGORITHM '='? algType=(DEFAULT | INSTANT | INPLACE | COPY) #alterBySetAlgorithm
| ALTER COLUMN? uid
(SET DEFAULT defaultValue | DROP DEFAULT) #alterByChangeDefault
| CHANGE COLUMN? oldColumn=uid
| CHANGE COLUMN? ifExists? oldColumn=uid
newColumn=uid columnDefinition
(FIRST | AFTER afterColumn=uid)? #alterByChangeColumn
(FIRST | AFTER afterColumn=uid)? #alterByChangeColumn // ifExists is MariaDB-specific
| RENAME COLUMN oldColumn=uid TO newColumn=uid #alterByRenameColumn
| LOCK '='? lockType=(DEFAULT | NONE | SHARED | EXCLUSIVE) #alterByLock
| MODIFY COLUMN?
uid columnDefinition (FIRST | AFTER uid)? #alterByModifyColumn
| DROP COLUMN? uid RESTRICT? #alterByDropColumn
| MODIFY COLUMN? ifExists?
uid columnDefinition (FIRST | AFTER uid)? #alterByModifyColumn // ifExists is MariaDB-specific
| DROP COLUMN? ifExists? uid RESTRICT? #alterByDropColumn // ifExists is MariaDB-specific
| DROP PRIMARY KEY #alterByDropPrimaryKey
| DROP indexFormat=(INDEX | KEY) ifExists? uid #alterByDropIndex
| RENAME indexFormat=(INDEX | KEY) uid TO uid #alterByRenameIndex

View File

@ -17,6 +17,16 @@ alter table table1 add primary key (id);
alter table table1 add primary key table_pk (id);
alter table table1 add primary key `table_pk` (id);
alter table table1 add primary key `table_pk` (`id`);
alter table add_test add column if not exists col1 varchar(255);
alter table add_test add column if not exists col4 varchar(255);
alter table add_test add index if not exists ix_add_test_col1 using btree (col1) comment 'test index';
alter table add_test add index if not exists ix_add_test_col4 using btree (col4) comment 'test index';
alter table add_test change column if exists col8 col9 tinyint;
alter table add_test change column if exists col3 col5 tinyint;
alter table add_test modify column if exists col9 tinyint;
alter table add_test modify column if exists col5 varchar(255);
alter table add_test drop column if exists col99;
alter table add_test drop column if exists col5;
#end
#begin
-- Alter database

View File

@ -30,6 +30,7 @@ create table table_with_visible_index (id int, data varchar(50), UNIQUE INDEX `d
create table table_with_index (id int, data varchar(50), UNIQUE INDEX `data_UNIQUE` (`data` ASC));
create table transactional_table(name varchar(255), class_id int, id int) transactional=1;
create table transactional(name varchar(255), class_id int, id int);
create table add_test(col1 varchar(255), col2 int, col3 int);
#end
#begin
-- Rename table
@ -77,6 +78,7 @@ do begin update test.t2 set 1c = 1c + 1; end; -- //
create index index1 on t1(col1) comment 'test index' comment 'some test' using btree;
create unique index index2 using btree on t2(1c desc, `_` asc);
create index index3 using hash on antlr_tokens(token(30) asc);
create index ix_add_test_col1 on add_test(col1) comment 'test index' using btree;
#end
#begin
-- Create logfile group