Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support parsing mysql 8 check related DDL statement #4089 #4095

Merged
merged 3 commits into from
Dec 25, 2020

Conversation

WillsonYip
Copy link
Contributor

@WillsonYip WillsonYip commented Dec 16, 2020

fix issue #4089

增加mysql 8 check语句的支持, 包括下面:

CREATE TABLE `t12` (
	`c1` int DEFAULT NULL,
	`c2` int DEFAULT NULL,
	`c3` int DEFAULT NULL,
	CONSTRAINT `c12_positive` CHECK (`c2` > 0) NOT ENFORCED,
	CONSTRAINT `c21_nonzero` CHECK (`c1` <> 0),
	CONSTRAINT `t12_chk_1` CHECK (`c1` <> `c2`),
	CONSTRAINT `t12_chk_2` CHECK (`c1` > 10),
	CONSTRAINT `t12_chk_3` CHECK (`c3` < 100),
	CONSTRAINT `t12_chk_4` CHECK (`c1` > `c3`)
) ENGINE = InnoDB CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;

# 新增check 约束
ALTER TABLE t1 ADD CONSTRAINT chk1 CHECK((a>1));
ALTER TABLE t1 ADD CONSTRAINT chk1 CHECK((a>1)) NOT ENFORCED; 

# 删除check 约束
ALTER TABLE t1 DROP CONSTRAINT t1_check ;

# 让check约束不生效
alter table t1 ALTER CHECK  t1_check  ENFORCED;
alter table t1 ALTER CHECK  t1_check  NOT ENFORCED;

修改说明:

  1. 修改MySqlCreateTableParser,使得支持create table语句中的 [CONSTRAINT [symbol]] CHECK (expr) [[NOT] ENFORCED]语法

  2. 新增MysqlAlterTableAlterCheck 类来识别 ALTER TABLE tbl_name ALTER {CHECK | CONSTRAINT} symbol [NOT] ENFORCED 语句

  3. 调整MySqlStatementParser.java代码顺序,使得可以支持 ALTER TABLE tbl_name ADD [CONSTRAINT [symbol]] CHECK (expr) [[NOT] ENFORCED] 语句

  4. ALTER TABLE tbl_name DROP {CHECK | CONSTRAINT} symbol 这个不需要修改,已经支持了

@CLAassistant
Copy link

CLAassistant commented Dec 16, 2020

CLA assistant check
All committers have signed the CLA.

@wenshao
Copy link
Member

wenshao commented Dec 16, 2020

请补上testcase

@wenshao wenshao added this to the 1.2.5 milestone Dec 16, 2020
@wenshao
Copy link
Member

wenshao commented Dec 24, 2020

请签署CLA

@wenshao wenshao merged commit 40ad863 into alibaba:master Dec 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants