-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The aim of this WL is to implement CHECK constraints feature. The feature is supported for all the storage engines. The WL provides following functionality: a) Create check constraints on a table: WL implements following syntax to add check constraint in CREATE TABLE and ALTER TABLE, check_constraint_definition: [CONSTRAINT [symbol]] CHECK(expr) [[NOT] ENFORCED] Example: CREATE TABLE t1 (f1 INT CHECK (f1 < 929), f2 INT, CHECK (f2 < 929)); ALTER TABLE t1 ADD COLUMN f3 INT CHECK (f3 < 929), ADD CONSTRAINT ck CHECK (f2 > 1); If enforcement is not specified then check constraint is created in the ENFORCED state. b) Check constraints validation: For DML operations INSERT, UPDATE, REPLACE, LOAD DATA, LOAD XML, check constraints in ENFORCED states are validated on each row. The check constraint is satisfied if and only if expression is evaluated to TRUE or UNKNOWN(for NULL column value). Constraint violation error is reported otherwise. Example: CREATE TABLE t (s1 INT, CHECK (s1 > 0)) INSERT INTO t VALUES (-1) /* this should fail, the condition is FALSE */ INSERT INTO t VALUES (NULL) /* this should succeed, the condition is UNKNOWN */ INSERT INTO t VALUES (1) /* this should succeed, the condition is TRUE */ c) Alter check constraint's state: WL implements following syntax in ALTER TABLE statement to alter constraint's state. ALTER TABLE ... ALTER CHECK symbol [[NOT] ENFORCED] Example: ALTER TABLE t1 ALTER CHECK ck NOT ENFORCED; ALTER TABLE t1 ALTER CHECK ck ENFORCED; d) Drop check constraint: WL implements following syntax in ALTER TABLE statement to DROP check constraint. ALTER TABLE ... DROP CHECK symbol; Example: ALTER TABLE t1 DROP CHECK ck; e) SHOW CREATE TABLE lists check constraints defined on the table. Example: CREATE TABLE t1( f1 INT CHECK (f1 < 10), f2 INT CHECK (f2 < 10) NOT ENFORCED); SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `f1` int(11) DEFAULT NULL, `f2` int(11) DEFAULT NULL, CONSTRAINT `t1_chk_1` CHECK ((`f1` < 10)), CONSTRAINT `t1_chk_2` CHECK ((`f2` < 10)) /*!80015 NOT ENFORCED */, ); All check constraints are listed in the table check constraint form. Check constraint in not enforced state are listed with the conditional comment "NOT ENFORCED". f) INFORMATION_SCHEMA.CHECK_CONSTRAINTS is introduced to list check constraints. g) INFORMATION_SCHEMA.TABLE_CONSTRAINTS now lists even check constraints defined on the table. Column "ENFORCED" is introduced to TABLE_CONSTRAINTS table to list enforcement state [YES/NO] for constraints. h) WL implements core features defined in the ANSI/ISO SQL standard E141-06 "CHECK CONSTRAINTS". Please refer WL's HLS section R for the common restrictions on the check constraints. Change-Id: I9de7158200e829e05df322f8ffe7e782aa9b7ab1
- Loading branch information
Showing
177 changed files
with
10,363 additions
and
780 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
#------------------------------------------------------------------------ | ||
# Test case to verify MDL locking on check constraints with same names | ||
# in the concurrent CREATE TABLE statements. | ||
#------------------------------------------------------------------------ | ||
SET DEBUG_SYNC="after_acquiring_lock_on_check_constraints SIGNAL cc_locked WAIT_FOR continue"; | ||
CREATE TABLE t1 (f1 INT CHECK (f1 < 10), f2 INT, CONSTRAINT t1_ck CHECK(f2 < 10));; | ||
CONNECT con1, localhost, root; | ||
SET DEBUG_SYNC="now WAIT_FOR cc_locked"; | ||
CREATE TABLE t2 (f1 INT, f2 INT, CONSTRAINT t1_ck CHECK(f2 < 10));; | ||
CONNECT con2, localhost, root; | ||
# default connection acquires MDL lock on the check constraint name 'test.t1_ck'. | ||
# con1 waits for the MDL lock on 'test.t1_ck' at this point. | ||
SET DEBUG_SYNC="now SIGNAL continue"; | ||
connection con1; | ||
ERROR HY000: Duplicate check constraint name 't1_ck'. | ||
connection default; | ||
#------------------------------------------------------------------------ | ||
# Test case to verify MDL locking on check constraints names in the | ||
# RENAME TABLE and CREATE TABLE statements. | ||
#------------------------------------------------------------------------ | ||
SET DEBUG_SYNC="after_acquiring_lock_on_check_constraints_for_rename SIGNAL cc_locked WAIT_FOR continue"; | ||
RENAME TABLE t1 to t2;; | ||
connection con1; | ||
SET DEBUG_SYNC="now WAIT_FOR cc_locked"; | ||
CREATE TABLE t3 (f1 INT, CONSTRAINT t1_chk_1 CHECK (f1 < 10));; | ||
connection con2; | ||
# default connection acquires lock on check constraint 'test.t1_chk_1'. | ||
# Concurrent create operation with same name for check constraint in con1 | ||
# waits for the lock. | ||
SET DEBUG_SYNC="now SIGNAL continue"; | ||
connection con1; | ||
connection default; | ||
SHOW CREATE TABLE t2; | ||
Table Create Table | ||
t2 CREATE TABLE `t2` ( | ||
`f1` int(11) DEFAULT NULL, | ||
`f2` int(11) DEFAULT NULL, | ||
CONSTRAINT `t1_ck` CHECK ((`f2` < 10)), | ||
CONSTRAINT `t2_chk_1` CHECK ((`f1` < 10)) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci | ||
SHOW CREATE TABLE t3; | ||
Table Create Table | ||
t3 CREATE TABLE `t3` ( | ||
`f1` int(11) DEFAULT NULL, | ||
CONSTRAINT `t1_chk_1` CHECK ((`f1` < 10)) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci | ||
DROP TABLE t3; | ||
#------------------------------------------------------------------------ | ||
# Test case to verify MDL locking on generated check constraints names | ||
# in the RENAME TABLE using the target table name and CREATE TABLE | ||
# statements. | ||
#------------------------------------------------------------------------ | ||
SET DEBUG_SYNC="after_acquiring_lock_on_check_constraints_for_rename SIGNAL cc_locked WAIT_FOR continue"; | ||
RENAME TABLE t2 to t1;; | ||
connection con1; | ||
SET DEBUG_SYNC="now WAIT_FOR cc_locked"; | ||
CREATE TABLE t3 (f1 INT, CONSTRAINT t1_chk_1 CHECK (f1 < 10));; | ||
connection con2; | ||
# default connection acquires lock on check constraint name('test.t1_chk_1') | ||
# generated using target table t1. | ||
# concurrent con1 waits for the MDL on test.t1_chk_1 in CREATE TABLE | ||
# statement. | ||
SET DEBUG_SYNC="now SIGNAL continue"; | ||
connection con1; | ||
ERROR HY000: Duplicate check constraint name 't1_chk_1'. | ||
SHOW CREATE TABLE t1; | ||
Table Create Table | ||
t1 CREATE TABLE `t1` ( | ||
`f1` int(11) DEFAULT NULL, | ||
`f2` int(11) DEFAULT NULL, | ||
CONSTRAINT `t1_chk_1` CHECK ((`f1` < 10)), | ||
CONSTRAINT `t1_ck` CHECK ((`f2` < 10)) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci | ||
connection default; | ||
#------------------------------------------------------------------------ | ||
# Test case to verify MDL locking on check constraint name in ALTER | ||
# TABLE statement to RENAME table and CREATE TABLE statements. | ||
#------------------------------------------------------------------------ | ||
SET DEBUG_SYNC="after_acquiring_lock_on_check_constraints_for_rename SIGNAL cc_locked WAIT_FOR continue"; | ||
ALTER TABLE t1 RENAME TO t3;; | ||
connection con1; | ||
SET DEBUG_SYNC="now WAIT_FOR cc_locked"; | ||
CREATE TABLE t2 (f1 INT, CONSTRAINT t1_chk_1 CHECK (f1 < 10));; | ||
connection con2; | ||
# default connection acquires lock on check constraint 'test.t1_chk_1'. | ||
# Concurrent con1 waits for lock on test.t1_chk_1. | ||
SET DEBUG_SYNC="now SIGNAL continue"; | ||
connection con1; | ||
connection default; | ||
SHOW CREATE TABLE t2; | ||
Table Create Table | ||
t2 CREATE TABLE `t2` ( | ||
`f1` int(11) DEFAULT NULL, | ||
CONSTRAINT `t1_chk_1` CHECK ((`f1` < 10)) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci | ||
SHOW CREATE TABLE t3; | ||
Table Create Table | ||
t3 CREATE TABLE `t3` ( | ||
`f1` int(11) DEFAULT NULL, | ||
`f2` int(11) DEFAULT NULL, | ||
CONSTRAINT `t1_ck` CHECK ((`f2` < 10)), | ||
CONSTRAINT `t3_chk_1` CHECK ((`f1` < 10)) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci | ||
DROP TABLE t2; | ||
#------------------------------------------------------------------------ | ||
# Test case to verify MDL locking on generated check constraint name | ||
# using target table name in ALTER TABLE statement to RENAME table and | ||
# CREATE TABLE statements. | ||
#------------------------------------------------------------------------ | ||
SET DEBUG_SYNC="after_acquiring_lock_on_check_constraints_for_rename SIGNAL cc_locked WAIT_FOR continue"; | ||
ALTER TABLE t3 RENAME TO t1;; | ||
connection con1; | ||
SET DEBUG_SYNC="now WAIT_FOR cc_locked"; | ||
CREATE TABLE t2 (f1 INT, CONSTRAINT t1_chk_1 CHECK (f1 < 10));; | ||
connection con2; | ||
# default connection acquires lock on the generated check constraint | ||
# name('test.t1_chk_1') using target table name t1. con1 waits for | ||
# the lock on same name for check constraint. | ||
SET DEBUG_SYNC="now SIGNAL continue"; | ||
connection con1; | ||
ERROR HY000: Duplicate check constraint name 't1_chk_1'. | ||
connection default; | ||
SHOW CREATE TABLE t1; | ||
Table Create Table | ||
t1 CREATE TABLE `t1` ( | ||
`f1` int(11) DEFAULT NULL, | ||
`f2` int(11) DEFAULT NULL, | ||
CONSTRAINT `t1_chk_1` CHECK ((`f1` < 10)), | ||
CONSTRAINT `t1_ck` CHECK ((`f2` < 10)) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci | ||
connection default; | ||
disconnect con1; | ||
disconnect con2; | ||
DROP TABLE t1; | ||
SET DEBUG_SYNC='RESET'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.