@@ -16,48 +16,48 @@ CREATE TABLE t0
16
16
t int, check (t>32) # table constraint
17
17
) ENGINE=myisam;
18
18
SELECT * from information_schema.check_constraints;
19
- CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
20
- def foo t0 CONSTRAINT_1 `t` > 32
19
+ CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME LEVEL CHECK_CLAUSE
20
+ def foo t0 CONSTRAINT_1 Table `t` > 32
21
21
ALTER TABLE t0
22
22
ADD CONSTRAINT CHK_t0_t CHECK(t<100);
23
23
SELECT * from information_schema.check_constraints;
24
- CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
25
- def foo t0 CHK_t0_t `t` < 100
26
- def foo t0 CONSTRAINT_1 `t` > 32
24
+ CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME LEVEL CHECK_CLAUSE
25
+ def foo t0 CHK_t0_t Table `t` < 100
26
+ def foo t0 CONSTRAINT_1 Table `t` > 32
27
27
ALTER TABLE t0
28
28
DROP CONSTRAINT CHK_t0_t;
29
29
SELECT * from information_schema.check_constraints;
30
- CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
31
- def foo t0 CONSTRAINT_1 `t` > 32
30
+ CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME LEVEL CHECK_CLAUSE
31
+ def foo t0 CONSTRAINT_1 Table `t` > 32
32
32
ALTER TABLE t0
33
33
ADD CONSTRAINT CHECK(t<50);
34
34
SELECT * from information_schema.check_constraints;
35
- CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
36
- def foo t0 CONSTRAINT_1 `t` > 32
37
- def foo t0 CONSTRAINT_2 `t` < 50
35
+ CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME LEVEL CHECK_CLAUSE
36
+ def foo t0 CONSTRAINT_1 Table `t` > 32
37
+ def foo t0 CONSTRAINT_2 Table `t` < 50
38
38
CREATE TABLE t1
39
39
( t int CHECK(t>2), # field constraint
40
40
tt int,
41
41
CONSTRAINT CHECK (tt > 32), CONSTRAINT CHECK (tt <50),# autogenerated names table constraints
42
42
CONSTRAINT CHK_tt CHECK(tt<100) # named table constraint
43
43
) ENGINE=InnoDB;
44
44
SELECT * from information_schema.check_constraints;
45
- CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
46
- def foo t0 CONSTRAINT_1 `t` > 32
47
- def foo t0 CONSTRAINT_2 `t` < 50
48
- def foo t1 CHK_tt `tt` < 100
49
- def foo t1 CONSTRAINT_1 `tt` > 32
50
- def foo t1 CONSTRAINT_2 `tt` < 50
51
- def foo t1 t `t` > 2
45
+ CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME LEVEL CHECK_CLAUSE
46
+ def foo t0 CONSTRAINT_1 Table `t` > 32
47
+ def foo t0 CONSTRAINT_2 Table `t` < 50
48
+ def foo t1 CHK_tt Table `tt` < 100
49
+ def foo t1 CONSTRAINT_1 Table `tt` > 32
50
+ def foo t1 CONSTRAINT_2 Table `tt` < 50
51
+ def foo t1 t Column `t` > 2
52
52
ALTER TABLE t1
53
53
DROP CONSTRAINT CHK_tt;
54
54
SELECT * from information_schema.check_constraints;
55
- CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
56
- def foo t0 CONSTRAINT_1 `t` > 32
57
- def foo t0 CONSTRAINT_2 `t` < 50
58
- def foo t1 CONSTRAINT_1 `tt` > 32
59
- def foo t1 CONSTRAINT_2 `tt` < 50
60
- def foo t1 t `t` > 2
55
+ CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME LEVEL CHECK_CLAUSE
56
+ def foo t0 CONSTRAINT_1 Table `t` > 32
57
+ def foo t0 CONSTRAINT_2 Table `t` < 50
58
+ def foo t1 CONSTRAINT_1 Table `tt` > 32
59
+ def foo t1 CONSTRAINT_2 Table `tt` < 50
60
+ def foo t1 t Column `t` > 2
61
61
CREATE TABLE t2
62
62
(
63
63
name VARCHAR(30) CHECK(CHAR_LENGTH(name)>2), #field constraint
@@ -66,26 +66,26 @@ end_date DATE,
66
66
CONSTRAINT CHK_dates CHECK(start_date IS NULL) #table constraint
67
67
)ENGINE=Innodb;
68
68
SELECT * from information_schema.check_constraints;
69
- CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
70
- def foo t0 CONSTRAINT_1 `t` > 32
71
- def foo t0 CONSTRAINT_2 `t` < 50
72
- def foo t1 CONSTRAINT_1 `tt` > 32
73
- def foo t1 CONSTRAINT_2 `tt` < 50
74
- def foo t1 t `t` > 2
75
- def foo t2 CHK_dates `start_date` is null
76
- def foo t2 name char_length(`name`) > 2
69
+ CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME LEVEL CHECK_CLAUSE
70
+ def foo t0 CONSTRAINT_1 Table `t` > 32
71
+ def foo t0 CONSTRAINT_2 Table `t` < 50
72
+ def foo t1 CONSTRAINT_1 Table `tt` > 32
73
+ def foo t1 CONSTRAINT_2 Table `tt` < 50
74
+ def foo t1 t Column `t` > 2
75
+ def foo t2 CHK_dates Table `start_date` is null
76
+ def foo t2 name Column char_length(`name`) > 2
77
77
ALTER TABLE t1
78
78
ADD CONSTRAINT CHK_new_ CHECK(t>tt);
79
79
SELECT * from information_schema.check_constraints;
80
- CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
81
- def foo t0 CONSTRAINT_1 `t` > 32
82
- def foo t0 CONSTRAINT_2 `t` < 50
83
- def foo t1 CHK_new_ `t` > `tt`
84
- def foo t1 CONSTRAINT_1 `tt` > 32
85
- def foo t1 CONSTRAINT_2 `tt` < 50
86
- def foo t1 t `t` > 2
87
- def foo t2 CHK_dates `start_date` is null
88
- def foo t2 name char_length(`name`) > 2
80
+ CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME LEVEL CHECK_CLAUSE
81
+ def foo t0 CONSTRAINT_1 Table `t` > 32
82
+ def foo t0 CONSTRAINT_2 Table `t` < 50
83
+ def foo t1 CHK_new_ Table `t` > `tt`
84
+ def foo t1 CONSTRAINT_1 Table `tt` > 32
85
+ def foo t1 CONSTRAINT_2 Table `tt` < 50
86
+ def foo t1 t Column `t` > 2
87
+ def foo t2 CHK_dates Table `start_date` is null
88
+ def foo t2 name Column char_length(`name`) > 2
89
89
CREATE TABLE t3
90
90
(
91
91
a int,
@@ -95,22 +95,22 @@ CONSTRAINT b check (b>10), # table constraint
95
95
CONSTRAINT b1 check (b<123456789012345678901234567890123456789012345678901234567890123456789)
96
96
) ENGINE=InnoDB;
97
97
SELECT * from information_schema.check_constraints;
98
- CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
99
- def foo t0 CONSTRAINT_1 `t` > 32
100
- def foo t0 CONSTRAINT_2 `t` < 50
101
- def foo t1 CHK_new_ `t` > `tt`
102
- def foo t1 CONSTRAINT_1 `tt` > 32
103
- def foo t1 CONSTRAINT_2 `tt` < 50
104
- def foo t1 t `t` > 2
105
- def foo t2 CHK_dates `start_date` is null
106
- def foo t2 name char_length(`name`) > 2
107
- def foo t3 b `b` > 0
108
- def foo t3 b `b` > 10
109
- def foo t3 b1 `b` < 123456789012345678901234567890123456789012345678901234567890123456789
98
+ CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME LEVEL CHECK_CLAUSE
99
+ def foo t0 CONSTRAINT_1 Table `t` > 32
100
+ def foo t0 CONSTRAINT_2 Table `t` < 50
101
+ def foo t1 CHK_new_ Table `t` > `tt`
102
+ def foo t1 CONSTRAINT_1 Table `tt` > 32
103
+ def foo t1 CONSTRAINT_2 Table `tt` < 50
104
+ def foo t1 t Column `t` > 2
105
+ def foo t2 CHK_dates Table `start_date` is null
106
+ def foo t2 name Column char_length(`name`) > 2
107
+ def foo t3 b Column `b` > 0
108
+ def foo t3 b Table `b` > 10
109
+ def foo t3 b1 Table `b` < 123456789012345678901234567890123456789012345678901234567890123456789
110
110
disconnect con1;
111
111
CONNECT con2, localhost, boo2,, test;
112
112
SELECT * from information_schema.check_constraints;
113
- CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
113
+ CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME LEVEL CHECK_CLAUSE
114
114
disconnect con2;
115
115
CONNECT con1, localhost, boo1,,foo;
116
116
DROP TABLE t0;
@@ -136,16 +136,54 @@ Grants for foo@%
136
136
GRANT USAGE ON *.* TO `foo`@`%`
137
137
GRANT SELECT (a) ON `db`.`t1` TO `foo`@`%`
138
138
SELECT * FROM information_schema.check_constraints;
139
- CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
140
- def db t1 CONSTRAINT_1 `b` > 0
141
- def mysql global_priv Priv json_valid(`Priv`)
139
+ CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME LEVEL CHECK_CLAUSE
140
+ def db t1 CONSTRAINT_1 Table `b` > 0
141
+ def mysql global_priv Priv Column json_valid(`Priv`)
142
142
CONNECT con1,localhost, foo,, db;
143
143
SELECT a FROM t1;
144
144
a
145
145
1
146
146
2
147
147
SELECT * FROM information_schema.check_constraints;
148
- CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
148
+ CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME LEVEL CHECK_CLAUSE
149
149
connection default;
150
150
DROP USER foo;
151
151
DROP DATABASE db;
152
+ #
153
+ # MDEV-24601: INFORMATION_SCHEMA doesn't differentiate between
154
+ # column and table-level CHECK constraints
155
+ #
156
+ use test;
157
+ create table t(check (t0>0),
158
+ t0 int,
159
+ t1 int check (t1<0),
160
+ t2 int check (t2<-1),
161
+ CONSTRAINT tc_1 check(t1 > 1),
162
+ CONSTRAINT t2 check(t2 > 1));
163
+ show create table t;
164
+ Table Create Table
165
+ t CREATE TABLE `t` (
166
+ `t0` int(11) DEFAULT NULL,
167
+ `t1` int(11) DEFAULT NULL CHECK (`t1` < 0),
168
+ `t2` int(11) DEFAULT NULL CHECK (`t2` < -1),
169
+ CONSTRAINT `CONSTRAINT_1` CHECK (`t0` > 0),
170
+ CONSTRAINT `tc_1` CHECK (`t1` > 1),
171
+ CONSTRAINT `t2` CHECK (`t2` > 1)
172
+ ) ENGINE=MyISAM DEFAULT CHARSET=latin1
173
+ select * from information_schema.table_constraints where CONSTRAINT_TYPE='CHECK';
174
+ CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_SCHEMA TABLE_NAME CONSTRAINT_TYPE
175
+ def mysql Priv mysql global_priv CHECK
176
+ def test CONSTRAINT_1 test t CHECK
177
+ def test t1 test t CHECK
178
+ def test t2 test t CHECK
179
+ def test t2 test t CHECK
180
+ def test tc_1 test t CHECK
181
+ select * from information_schema.check_constraints;
182
+ CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME LEVEL CHECK_CLAUSE
183
+ def mysql global_priv Priv Column json_valid(`Priv`)
184
+ def test t CONSTRAINT_1 Table `t0` > 0
185
+ def test t t1 Column `t1` < 0
186
+ def test t t2 Column `t2` < -1
187
+ def test t t2 Table `t2` > 1
188
+ def test t tc_1 Table `t1` > 1
189
+ drop table t;
0 commit comments