-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDEV-14474 information_schema.check_constraints
Implement according to standard SQL specification 2008. The check_constraints table is used for fetching metadata about the constraints defined for tables in all databases.
- Loading branch information
Showing
9 changed files
with
334 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
# | ||
# MDEV-14474: Create INFORMATION_SCHEMA.CHECK_CONSTRAINTS | ||
# | ||
set check_constraint_checks=1; | ||
use test; | ||
create table t0 | ||
( | ||
t int, check (t>32) # table constraint | ||
) ENGINE=myisam; | ||
SELECT * from information_schema.check_constraints; | ||
CONSTRAINT_CATALOG def | ||
CONSTRAINT_SCHEMA test | ||
CONSTRAINT_NAME CONSTRAINT_1 | ||
TABLE_NAME t0 | ||
CHECK_CLAUSE `t` > 32 | ||
ALTER TABLE t0 | ||
ADD CONSTRAINT CHK_t0_t CHECK(t<100); | ||
SELECT * from information_schema.check_constraints; | ||
CONSTRAINT_CATALOG def | ||
CONSTRAINT_SCHEMA test | ||
CONSTRAINT_NAME CONSTRAINT_1 | ||
TABLE_NAME t0 | ||
CHECK_CLAUSE `t` > 32 | ||
CONSTRAINT_CATALOG def | ||
CONSTRAINT_SCHEMA test | ||
CONSTRAINT_NAME CHK_t0_t | ||
TABLE_NAME t0 | ||
CHECK_CLAUSE `t` < 100 | ||
ALTER TABLE t0 | ||
DROP CONSTRAINT CHK_t0_t; | ||
SELECT * from information_schema.check_constraints; | ||
CONSTRAINT_CATALOG def | ||
CONSTRAINT_SCHEMA test | ||
CONSTRAINT_NAME CONSTRAINT_1 | ||
TABLE_NAME t0 | ||
CHECK_CLAUSE `t` > 32 | ||
CREATE TABLE t1 | ||
( t int CHECK(t>2), # field constraint | ||
tt int, CONSTRAINT CHK_tt CHECK(tt<100) # table constraint | ||
) ENGINE=InnoDB; | ||
SELECT * from information_schema.check_constraints; | ||
CONSTRAINT_CATALOG def | ||
CONSTRAINT_SCHEMA test | ||
CONSTRAINT_NAME t | ||
TABLE_NAME t1 | ||
CHECK_CLAUSE `t` > 2 | ||
CONSTRAINT_CATALOG def | ||
CONSTRAINT_SCHEMA test | ||
CONSTRAINT_NAME CHK_tt | ||
TABLE_NAME t1 | ||
CHECK_CLAUSE `tt` < 100 | ||
CONSTRAINT_CATALOG def | ||
CONSTRAINT_SCHEMA test | ||
CONSTRAINT_NAME CONSTRAINT_1 | ||
TABLE_NAME t0 | ||
CHECK_CLAUSE `t` > 32 | ||
ALTER TABLE t1 | ||
DROP CONSTRAINT CHK_tt; | ||
SELECT * from information_schema.check_constraints; | ||
CONSTRAINT_CATALOG def | ||
CONSTRAINT_SCHEMA test | ||
CONSTRAINT_NAME t | ||
TABLE_NAME t1 | ||
CHECK_CLAUSE `t` > 2 | ||
CONSTRAINT_CATALOG def | ||
CONSTRAINT_SCHEMA test | ||
CONSTRAINT_NAME CONSTRAINT_1 | ||
TABLE_NAME t0 | ||
CHECK_CLAUSE `t` > 32 | ||
create table t2 | ||
( | ||
name VARCHAR(30) CHECK(CHAR_LENGTH(name)>2), #field constraint | ||
start_date DATE, | ||
end_date DATE, | ||
CONSTRAINT CHK_dates CHECK(start_date IS NULL) #table constraint | ||
)ENGINE=Innodb; | ||
SELECT * from information_schema.check_constraints; | ||
CONSTRAINT_CATALOG def | ||
CONSTRAINT_SCHEMA test | ||
CONSTRAINT_NAME name | ||
TABLE_NAME t2 | ||
CHECK_CLAUSE char_length(`name`) > 2 | ||
CONSTRAINT_CATALOG def | ||
CONSTRAINT_SCHEMA test | ||
CONSTRAINT_NAME CHK_dates | ||
TABLE_NAME t2 | ||
CHECK_CLAUSE `start_date` is null | ||
CONSTRAINT_CATALOG def | ||
CONSTRAINT_SCHEMA test | ||
CONSTRAINT_NAME t | ||
TABLE_NAME t1 | ||
CHECK_CLAUSE `t` > 2 | ||
CONSTRAINT_CATALOG def | ||
CONSTRAINT_SCHEMA test | ||
CONSTRAINT_NAME CONSTRAINT_1 | ||
TABLE_NAME t0 | ||
CHECK_CLAUSE `t` > 32 | ||
ALTER TABLE t1 | ||
ADD CONSTRAINT CHK_new_ CHECK(t>tt); | ||
SELECT * from information_schema.check_constraints; | ||
CONSTRAINT_CATALOG def | ||
CONSTRAINT_SCHEMA test | ||
CONSTRAINT_NAME name | ||
TABLE_NAME t2 | ||
CHECK_CLAUSE char_length(`name`) > 2 | ||
CONSTRAINT_CATALOG def | ||
CONSTRAINT_SCHEMA test | ||
CONSTRAINT_NAME CHK_dates | ||
TABLE_NAME t2 | ||
CHECK_CLAUSE `start_date` is null | ||
CONSTRAINT_CATALOG def | ||
CONSTRAINT_SCHEMA test | ||
CONSTRAINT_NAME t | ||
TABLE_NAME t1 | ||
CHECK_CLAUSE `t` > 2 | ||
CONSTRAINT_CATALOG def | ||
CONSTRAINT_SCHEMA test | ||
CONSTRAINT_NAME CHK_new_ | ||
TABLE_NAME t1 | ||
CHECK_CLAUSE `t` > `tt` | ||
CONSTRAINT_CATALOG def | ||
CONSTRAINT_SCHEMA test | ||
CONSTRAINT_NAME CONSTRAINT_1 | ||
TABLE_NAME t0 | ||
CHECK_CLAUSE `t` > 32 | ||
create table t3 | ||
( | ||
a int, | ||
b int check (b>0), # field constraint named 'b' | ||
CONSTRAINT b check (b>10) # table constraint | ||
) ENGINE=InnoDB; | ||
select * from information_schema.check_constraints; | ||
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_NAME CHECK_CLAUSE | ||
def test b t3 `b` > 0 | ||
def test b t3 `b` > 10 | ||
def test name t2 char_length(`name`) > 2 | ||
def test CHK_dates t2 `start_date` is null | ||
def test t t1 `t` > 2 | ||
def test CHK_new_ t1 `t` > `tt` | ||
def test CONSTRAINT_1 t0 `t` > 32 | ||
drop table t0; | ||
drop table t1; | ||
drop table t2; | ||
drop table t3; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--source include/have_innodb.inc | ||
--echo # | ||
--echo # MDEV-14474: Create INFORMATION_SCHEMA.CHECK_CONSTRAINTS | ||
--echo # | ||
|
||
set check_constraint_checks=1; | ||
|
||
use test; | ||
create table t0 | ||
( | ||
t int, check (t>32) # table constraint | ||
) ENGINE=myisam; | ||
|
||
--vertical_results | ||
SELECT * from information_schema.check_constraints; | ||
|
||
ALTER TABLE t0 | ||
ADD CONSTRAINT CHK_t0_t CHECK(t<100); | ||
|
||
SELECT * from information_schema.check_constraints; | ||
|
||
ALTER TABLE t0 | ||
DROP CONSTRAINT CHK_t0_t; | ||
|
||
SELECT * from information_schema.check_constraints; | ||
|
||
CREATE TABLE t1 | ||
( t int CHECK(t>2), # field constraint | ||
tt int, CONSTRAINT CHK_tt CHECK(tt<100) # table constraint | ||
) ENGINE=InnoDB; | ||
|
||
SELECT * from information_schema.check_constraints; | ||
|
||
ALTER TABLE t1 | ||
DROP CONSTRAINT CHK_tt; | ||
|
||
SELECT * from information_schema.check_constraints; | ||
|
||
create table t2 | ||
( | ||
name VARCHAR(30) CHECK(CHAR_LENGTH(name)>2), #field constraint | ||
start_date DATE, | ||
end_date DATE, | ||
CONSTRAINT CHK_dates CHECK(start_date IS NULL) #table constraint | ||
)ENGINE=Innodb; | ||
|
||
SELECT * from information_schema.check_constraints; | ||
|
||
ALTER TABLE t1 | ||
ADD CONSTRAINT CHK_new_ CHECK(t>tt); | ||
|
||
SELECT * from information_schema.check_constraints; | ||
|
||
|
||
# Create table with same field and table check constraint name | ||
create table t3 | ||
( | ||
a int, | ||
b int check (b>0), # field constraint named 'b' | ||
CONSTRAINT b check (b>10) # table constraint | ||
) ENGINE=InnoDB; | ||
|
||
--horizontal_results | ||
select * from information_schema.check_constraints; | ||
|
||
drop table t0; | ||
drop table t1; | ||
drop table t2; | ||
drop table t3; |
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.