diff --git a/mysql-test/main/check_constraint.result b/mysql-test/main/check_constraint.result index e3986dcf75b86..e7fece897ed4f 100644 --- a/mysql-test/main/check_constraint.result +++ b/mysql-test/main/check_constraint.result @@ -10,9 +10,9 @@ t1 CREATE TABLE `t1` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci insert into t1 values (100,100); insert into t1 values (1,1); -ERROR 23000: CONSTRAINT `t1.a` failed for `test`.`t1` +ERROR 23000: CONSTRAINT `a` failed for `test`.`t1` insert into t1 values (20,1); -ERROR 23000: CONSTRAINT `t1.b` failed for `test`.`t1` +ERROR 23000: CONSTRAINT `b` failed for `test`.`t1` insert into t1 values (20,30); ERROR 23000: CONSTRAINT `min` failed for `test`.`t1` insert into t1 values (500,500); @@ -60,7 +60,7 @@ t1 CREATE TABLE `t1` ( CONSTRAINT `CONSTRAINT_1` CHECK (`a` + `b` + `c` < 500) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci insert into t1 values(105,105,105); -ERROR 23000: CONSTRAINT `t1.c` failed for `test`.`t1` +ERROR 23000: CONSTRAINT `c` failed for `test`.`t1` insert into t1 values(249,249,9); ERROR 23000: CONSTRAINT `CONSTRAINT_1` failed for `test`.`t1` insert into t1 values(105,105,9); @@ -145,7 +145,7 @@ ERROR HY000: Function or expression '@b' cannot be used in the CHECK clause of ` create table t1 (a int check (a = 1)); insert t1 values (1); insert t1 values (2); -ERROR 23000: CONSTRAINT `t1.a` failed for `test`.`t1` +ERROR 23000: CONSTRAINT `a` failed for `test`.`t1` insert t1 values (NULL); select * from t1; a @@ -165,13 +165,13 @@ ERROR 22007: Truncated incorrect DECIMAL value: 'Ken' SHOW WARNINGS; Level Code Message Error 1292 Truncated incorrect DECIMAL value: 'Ken' -Error 4025 CONSTRAINT `t1.FirstName` failed for `test`.`t1` +Error 4025 CONSTRAINT `FirstName` failed for `test`.`t1` INSERT INTO t1 VALUES (NULL, 'Ken'),(NULL, 'Brian'); ERROR 22007: Truncated incorrect DECIMAL value: 'Ken' SHOW WARNINGS; Level Code Message Error 1292 Truncated incorrect DECIMAL value: 'Ken' -Error 4025 CONSTRAINT `t1.FirstName` failed for `test`.`t1` +Error 4025 CONSTRAINT `FirstName` failed for `test`.`t1` INSERT IGNORE INTO t1 VALUES (NULL, 'Ken'); Warnings: Warning 1292 Truncated incorrect DECIMAL value: 'Ken' @@ -197,31 +197,6 @@ EmployeeID FirstName 5 Ken 6 Brian drop table t1; -# -# MDEV-16630: Ambiguous error message when check constraint -# matches table name -# -use test; -drop table if exists t; -create table t(a int, b int check(b>0), -constraint b check(a0), -constraint x check (a>10)); -show create table t; -Table Create Table -t CREATE TABLE `t` ( - `a` int(11) DEFAULT NULL, - `b` int(11) DEFAULT NULL CHECK (`b` > 0), - CONSTRAINT `b` CHECK (`a` < `b`), - CONSTRAINT `a` CHECK (`a` > 0), - CONSTRAINT `x` CHECK (`a` > 10) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci -# Field constraint 'b' will fail -insert into t values (-1, 0); -ERROR 23000: CONSTRAINT `t.b` failed for `test`.`t` -# Table constraint 'b' will fail -insert into t values (1,1); -ERROR 23000: CONSTRAINT `b` failed for `test`.`t` -drop table t; create table t1 (a int auto_increment primary key, b int, check (b > 5)); insert t1 (b) values (1); ERROR 23000: CONSTRAINT `CONSTRAINT_1` failed for `test`.`t1` @@ -298,13 +273,13 @@ drop table t1; # # MDEV-24274 ALTER TABLE with CHECK CONSTRAINTS gives "Out of Memory" error # -create table t1 (id varchar(2), constraint id check (id regexp '[a-z]')); +create table t1 (id varchar(2), constraint id1 check (id regexp '[a-z]')); alter table t1 force; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `id` varchar(2) DEFAULT NULL, - CONSTRAINT `id` CHECK (`id` regexp '[a-z]') + CONSTRAINT `id1` CHECK (`id` regexp '[a-z]') ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci drop table t1; # @@ -315,8 +290,131 @@ drop table t1; create table t1 (a int, b int as (a) check (b > 0)); insert t1 (a) values (1); insert t1 (a) values (-1); -ERROR 23000: CONSTRAINT `t1.b` failed for `test`.`t1` +ERROR 23000: CONSTRAINT `b` failed for `test`.`t1` drop table t1; # +# MDEV-24598: duplicate CHECK constraint name +# +create table t (a int check (a>2), +constraint a1 check (a < 5), +constraint a1 check (a > 5)); +ERROR HY000: Duplicate CHECK constraint name 'a1' +create table t (a int check (a>2), +constraint a check (a < 5)); +ERROR HY000: Duplicate CHECK constraint name 'a' +CREATE TABLE t ( +path VARCHAR(100) NOT NULL COLLATE 'utf8_general_ci', +json_c1 JSON NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', +json_c2 JSON NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', +comment VARCHAR(100) NULL DEFAULT NULL COLLATE 'utf8_general_ci', +UNIQUE INDEX path (path), +CONSTRAINT json_c1 CHECK (path > 0) +); +ERROR HY000: Duplicate CHECK constraint name 'json_c1' +select * from information_schema.check_constraints where table_name='t'; +CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE +create table t(a int); +alter table t add constraint a check (a > 10); +ERROR HY000: Duplicate CHECK constraint name 'a' +drop table t; +# +# MDEV-24602: cannot specify a name for a column check constraint +# +create table t(t int, +check (t>0), +constraint check(t>1), +constraint t_named check(t>2)); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `t` int(11) DEFAULT NULL, + CONSTRAINT `CONSTRAINT_1` CHECK (`t` > 0), + CONSTRAINT `CONSTRAINT_2` CHECK (`t` > 1), + CONSTRAINT `t_named` CHECK (`t` > 2) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT CONSTRAINT_NAME, TABLE_NAME, CONSTRAINT_TYPE +FROM information_schema.TABLE_CONSTRAINTS WHERE +TABLE_NAME = 't' AND TABLE_SCHEMA = 'test'; +CONSTRAINT_NAME TABLE_NAME CONSTRAINT_TYPE +CONSTRAINT_1 t CHECK +CONSTRAINT_2 t CHECK +t_named t CHECK +SELECT * from INFORMATION_SCHEMA.CHECK_CONSTRAINTS WHERE +CONSTRAINT_SCHEMA = 'test'; +CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE +def test t CONSTRAINT_1 `t` > 0 +def test t CONSTRAINT_2 `t` > 1 +def test t t_named `t` > 2 +drop table t; +create table t(t0 int, +t1 int check (t1>0), +t2 int constraint check(t2>0), +t3 int constraint t_field check(t3>0)); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `t0` int(11) DEFAULT NULL, + `t1` int(11) DEFAULT NULL CHECK (`t1` > 0), + `t2` int(11) DEFAULT NULL CHECK (`t2` > 0), + `t3` int(11) DEFAULT NULL CHECK (`t3` > 0) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT CONSTRAINT_NAME, TABLE_NAME, CONSTRAINT_TYPE +FROM information_schema.TABLE_CONSTRAINTS WHERE +TABLE_NAME = 't' AND TABLE_SCHEMA = 'test'; +CONSTRAINT_NAME TABLE_NAME CONSTRAINT_TYPE +t1 t CHECK +t2 t CHECK +t_field t CHECK +SELECT * from INFORMATION_SCHEMA.CHECK_CONSTRAINTS WHERE +CONSTRAINT_SCHEMA = 'test'; +CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE +def test t t1 `t1` > 0 +def test t t2 `t2` > 0 +def test t t_field `t3` > 0 +drop table t; +create table t(t1 int constraint t1_check check(t1>0), +t2 int check(t2>0), +t3 int constraint t_field check(t3>0), +t4 int constraint t_field check(t4>0)); +ERROR HY000: Duplicate CHECK constraint name 't_field' +create table t(t1 int constraint t1_check check(t1>0), +t2 int check(t2>0), +t3 int constraint t_field check(t3>0), +constraint table_check1 check(t1>0), +constraint table_check1 check(t2>0)); +ERROR HY000: Duplicate CHECK constraint name 'table_check1' +create table t(t1 int constraint t1_check check(t1>0), +t2 int check(t2>0), +t3 int constraint t_field check(t3>0), +constraint t_field check(t1>0)); +ERROR HY000: Duplicate CHECK constraint name 't_field' +create table t(t1 int constraint t1 check(t1>0)); +SELECT * from INFORMATION_SCHEMA.CHECK_CONSTRAINTS WHERE +CONSTRAINT_SCHEMA = 'test'; +CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE +def test t t1 `t1` > 0 +alter table t add constraint t1 check (t1<0); +ERROR HY000: Duplicate CHECK constraint name 't1' +SELECT * from INFORMATION_SCHEMA.CHECK_CONSTRAINTS WHERE +CONSTRAINT_SCHEMA = 'test'; +CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE +def test t t1 `t1` > 0 +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `t1` int(11) DEFAULT NULL CHECK (`t1` > 0) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +alter table t modify column t1 int constraint t1_greater_pi_check check (t1>3.14); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `t1` int(11) DEFAULT NULL CHECK (`t1` > 3.14) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT * from INFORMATION_SCHEMA.CHECK_CONSTRAINTS WHERE +CONSTRAINT_SCHEMA = 'test'; +CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE +def test t t1_greater_pi_check `t1` > 3.14 +drop table t; +# # End of 10.4 tests # diff --git a/mysql-test/main/check_constraint.test b/mysql-test/main/check_constraint.test index e12468e901392..d985582e968d1 100644 --- a/mysql-test/main/check_constraint.test +++ b/mysql-test/main/check_constraint.test @@ -135,34 +135,6 @@ set sql_mode=default; select * from t1; drop table t1; ---echo # ---echo # MDEV-16630: Ambiguous error message when check constraint ---echo # matches table name ---echo # - -use test; ---disable_warnings -drop table if exists t; ---enable_warnings - -create table t(a int, b int check(b>0), - constraint b check(a0), - constraint x check (a>10)); - -show create table t; - -# Generate error when field constraint 'b' is violated ---echo # Field constraint 'b' will fail ---error ER_CONSTRAINT_FAILED -insert into t values (-1, 0); - -# Generate error when table constraint 'b' is violated. ---echo # Table constraint 'b' will fail ---error ER_CONSTRAINT_FAILED -insert into t values (1,1); - -drop table t; - # # check constraints and auto_is_null typo # @@ -226,7 +198,7 @@ drop table t1; --echo # --echo # MDEV-24274 ALTER TABLE with CHECK CONSTRAINTS gives "Out of Memory" error --echo # -create table t1 (id varchar(2), constraint id check (id regexp '[a-z]')); +create table t1 (id varchar(2), constraint id1 check (id regexp '[a-z]')); alter table t1 force; show create table t1; drop table t1; @@ -244,6 +216,109 @@ insert t1 (a) values (1); insert t1 (a) values (-1); drop table t1; +--echo # +--echo # MDEV-24598: duplicate CHECK constraint name +--echo # + +# Field constraints have th name of columns, it is not possible to have duplicated +# constraints (ER_DUP_FIELDNAME) + +# Table constraints with the same name will raise ER_DUP_CONSTRAINT_NAME +--error ER_DUP_CONSTRAINT_NAME +create table t (a int check (a>2), + constraint a1 check (a < 5), + constraint a1 check (a > 5)); + +# Table constraint that has the same name as field +--error ER_DUP_CONSTRAINT_NAME +create table t (a int check (a>2), + constraint a check (a < 5)); + +# Check native Json constraint +--error ER_DUP_CONSTRAINT_NAME +CREATE TABLE t ( +path VARCHAR(100) NOT NULL COLLATE 'utf8_general_ci', +json_c1 JSON NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', +json_c2 JSON NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', +comment VARCHAR(100) NULL DEFAULT NULL COLLATE 'utf8_general_ci', +UNIQUE INDEX path (path), +CONSTRAINT json_c1 CHECK (path > 0) +); +select * from information_schema.check_constraints where table_name='t'; + +# Check Alter table +create table t(a int); +--error ER_DUP_CONSTRAINT_NAME +alter table t add constraint a check (a > 10); +drop table t; + +--echo # +--echo # MDEV-24602: cannot specify a name for a column check constraint +--echo # +# Table constraints (unnamed and named) +create table t(t int, + check (t>0), + constraint check(t>1), + constraint t_named check(t>2)); +show create table t; +SELECT CONSTRAINT_NAME, TABLE_NAME, CONSTRAINT_TYPE +FROM information_schema.TABLE_CONSTRAINTS WHERE +TABLE_NAME = 't' AND TABLE_SCHEMA = 'test'; +SELECT * from INFORMATION_SCHEMA.CHECK_CONSTRAINTS WHERE +CONSTRAINT_SCHEMA = 'test'; +drop table t; + +# Field constraints (with and without the names) +create table t(t0 int, + t1 int check (t1>0), + t2 int constraint check(t2>0), + t3 int constraint t_field check(t3>0)); +show create table t; +SELECT CONSTRAINT_NAME, TABLE_NAME, CONSTRAINT_TYPE +FROM information_schema.TABLE_CONSTRAINTS WHERE +TABLE_NAME = 't' AND TABLE_SCHEMA = 'test'; +SELECT * from INFORMATION_SCHEMA.CHECK_CONSTRAINTS WHERE +CONSTRAINT_SCHEMA = 'test'; +drop table t; + +# Field constraint names are the same +--error ER_DUP_CONSTRAINT_NAME +create table t(t1 int constraint t1_check check(t1>0), + t2 int check(t2>0), + t3 int constraint t_field check(t3>0), + t4 int constraint t_field check(t4>0)); + +# Table constraint names are the same +--error ER_DUP_CONSTRAINT_NAME +create table t(t1 int constraint t1_check check(t1>0), + t2 int check(t2>0), + t3 int constraint t_field check(t3>0), + constraint table_check1 check(t1>0), + constraint table_check1 check(t2>0)); + +# Table and field constraint names are the same +--error ER_DUP_CONSTRAINT_NAME +create table t(t1 int constraint t1_check check(t1>0), + t2 int check(t2>0), + t3 int constraint t_field check(t3>0), + constraint t_field check(t1>0)); + +# Adding table constraint with the same name will result in error for alter table. +create table t(t1 int constraint t1 check(t1>0)); +SELECT * from INFORMATION_SCHEMA.CHECK_CONSTRAINTS WHERE +CONSTRAINT_SCHEMA = 'test'; +--error ER_DUP_CONSTRAINT_NAME +alter table t add constraint t1 check (t1<0); +SELECT * from INFORMATION_SCHEMA.CHECK_CONSTRAINTS WHERE +CONSTRAINT_SCHEMA = 'test'; +# Show create table will show field constraint +show create table t; +alter table t modify column t1 int constraint t1_greater_pi_check check (t1>3.14); +# Show create table will show again field constraint +show create table t; +SELECT * from INFORMATION_SCHEMA.CHECK_CONSTRAINTS WHERE +CONSTRAINT_SCHEMA = 'test'; +drop table t; --echo # --echo # End of 10.4 tests --echo # diff --git a/mysql-test/main/constraints.result b/mysql-test/main/constraints.result index 53787fb5b651d..c4bf91753cd39 100644 --- a/mysql-test/main/constraints.result +++ b/mysql-test/main/constraints.result @@ -6,7 +6,7 @@ t1 CREATE TABLE `t1` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci insert into t1 values (1); insert into t1 values (0); -ERROR 23000: CONSTRAINT `t1.a` failed for `test`.`t1` +ERROR 23000: CONSTRAINT `a` failed for `test`.`t1` drop table t1; create table t1 (a int, b int, check (a>b)); show create table t1; @@ -195,7 +195,7 @@ create table t1 (a text default(length(now())) check (length(a) > 1)); insert into t1 values (); insert into t1 values ("ccc"); insert into t1 values (""); -ERROR 23000: CONSTRAINT `t1.a` failed for `test`.`t1` +ERROR 23000: CONSTRAINT `a` failed for `test`.`t1` select * from t1; a 19 diff --git a/mysql-test/main/invisible_field_debug.result b/mysql-test/main/invisible_field_debug.result index d73a823d7080e..171721b8ccb4b 100644 --- a/mysql-test/main/invisible_field_debug.result +++ b/mysql-test/main/invisible_field_debug.result @@ -69,7 +69,7 @@ select @a from dual; @a 9 alter table t1 add constraint a check (invisible > 2); -ERROR 42S22: Unknown column 'invisible' in 'CHECK' +ERROR HY000: Duplicate CHECK constraint name 'a' set debug_dbug= "+d,test_pseudo_invisible"; create table t2(a int, b int as (invisible +2) virtual); ERROR 42S22: Unknown column 'invisible' in 'GENERATED ALWAYS AS' diff --git a/mysql-test/main/invisible_field_debug.test b/mysql-test/main/invisible_field_debug.test index 3e844fc4521d1..19c3238c87dd8 100644 --- a/mysql-test/main/invisible_field_debug.test +++ b/mysql-test/main/invisible_field_debug.test @@ -52,7 +52,7 @@ select a , invisible from t1; ##set set @a=(select invisible from t1 limit 1); select @a from dual; ---error ER_BAD_FIELD_ERROR +--error ER_DUP_CONSTRAINT_NAME alter table t1 add constraint a check (invisible > 2); set debug_dbug= "+d,test_pseudo_invisible"; --error ER_BAD_FIELD_ERROR diff --git a/mysql-test/main/type_json.result b/mysql-test/main/type_json.result index 7c8a9cbb11396..415286d7bec3a 100644 --- a/mysql-test/main/type_json.result +++ b/mysql-test/main/type_json.result @@ -20,7 +20,7 @@ t1 CREATE TABLE `t1` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci insert t1 values ('[]'); insert t1 values ('a'); -ERROR 23000: CONSTRAINT `t1.a` failed for `test`.`t1` +ERROR 23000: CONSTRAINT `a` failed for `test`.`t1` create or replace table t1(a json not null); show create table t1; Table Create Table @@ -29,7 +29,7 @@ t1 CREATE TABLE `t1` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci insert t1 values ('[]'); insert t1 values ('a'); -ERROR 23000: CONSTRAINT `t1.a` failed for `test`.`t1` +ERROR 23000: CONSTRAINT `a` failed for `test`.`t1` set timestamp=unix_timestamp('2010:11:12 13:14:15'); create or replace table t1(a json default(json_object('now', now()))); show create table t1; @@ -75,7 +75,7 @@ drop table t1; create table t1 (t text) engine=myisam; insert into t1 values ("{}"),(""); create table t2 (t json) select t from t1; -ERROR 23000: CONSTRAINT `t2.t` failed for `test`.`t2` +ERROR 23000: CONSTRAINT `t` failed for `test`.`t2` select * from t2; ERROR 42S02: Table 'test.t2' doesn't exist drop table t1; @@ -83,7 +83,7 @@ create or replace table t1(a json default(json_object('now', 1)) check (json_val insert into t1 values (); insert into t1 values ("{}"); insert into t1 values ("xxx"); -ERROR 23000: CONSTRAINT `t1.a` failed for `test`.`t1` +ERROR 23000: CONSTRAINT `a` failed for `test`.`t1` select * from t1; a {"now": 1} diff --git a/mysql-test/suite/funcs_1/r/is_check_constraints.result b/mysql-test/suite/funcs_1/r/is_check_constraints.result index b7b70635de945..356208143e1c4 100644 --- a/mysql-test/suite/funcs_1/r/is_check_constraints.result +++ b/mysql-test/suite/funcs_1/r/is_check_constraints.result @@ -90,7 +90,7 @@ CREATE TABLE t3 ( a int, b int check (b>0), # field constraint named 'b' -CONSTRAINT b check (b>10), # table constraint +CONSTRAINT b0 check (b>10), # table constraint # `CHECK_CLAUSE` should allow more then `var(64)` constraints CONSTRAINT b1 check (b<123456789012345678901234567890123456789012345678901234567890123456789) ) ENGINE=InnoDB; @@ -105,7 +105,7 @@ def foo t1 t `t` > 2 def foo t2 CHK_dates `start_date` is null def foo t2 name char_length(`name`) > 2 def foo t3 b `b` > 0 -def foo t3 b `b` > 10 +def foo t3 b0 `b` > 10 def foo t3 b1 `b` < 123456789012345678901234567890123456789012345678901234567890123456789 disconnect con1; CONNECT con2, localhost, boo2,, test; diff --git a/mysql-test/suite/funcs_1/t/is_check_constraints.test b/mysql-test/suite/funcs_1/t/is_check_constraints.test index dbd286e6239f6..931b6c4e1160d 100644 --- a/mysql-test/suite/funcs_1/t/is_check_constraints.test +++ b/mysql-test/suite/funcs_1/t/is_check_constraints.test @@ -69,7 +69,7 @@ CREATE TABLE t3 ( a int, b int check (b>0), # field constraint named 'b' -CONSTRAINT b check (b>10), # table constraint +CONSTRAINT b0 check (b>10), # table constraint # `CHECK_CLAUSE` should allow more then `var(64)` constraints CONSTRAINT b1 check (b<123456789012345678901234567890123456789012345678901234567890123456789) ) ENGINE=InnoDB; diff --git a/mysql-test/suite/gcol/inc/gcol_column_def_options.inc b/mysql-test/suite/gcol/inc/gcol_column_def_options.inc index 6f4a8ab724071..09e00b127f32d 100644 --- a/mysql-test/suite/gcol/inc/gcol_column_def_options.inc +++ b/mysql-test/suite/gcol/inc/gcol_column_def_options.inc @@ -138,7 +138,7 @@ create table t1 (a int, b int generated always as (a % 2) stored references t2(a show create table t1; drop table t1; create table t1 (a int, b int generated always as (a % 2) virtual); ---error ER_PARSE_ERROR +--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN alter table t1 modify b int generated always as (a % 2) stored references t2(a); show create table t1; drop table t1; diff --git a/mysql-test/suite/gcol/r/gcol_column_def_options_innodb.result b/mysql-test/suite/gcol/r/gcol_column_def_options_innodb.result index 2422bdca363a6..8afc3ba92d260 100644 --- a/mysql-test/suite/gcol/r/gcol_column_def_options_innodb.result +++ b/mysql-test/suite/gcol/r/gcol_column_def_options_innodb.result @@ -163,7 +163,7 @@ t1 CREATE TABLE `t1` ( drop table t1; create table t1 (a int, b int generated always as (a % 2) virtual); alter table t1 modify b int generated always as (a % 2) stored references t2(a); -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'references t2(a)' at line 1 +ERROR HY000: This is not yet supported for generated columns show create table t1; Table Create Table t1 CREATE TABLE `t1` ( diff --git a/mysql-test/suite/gcol/r/gcol_column_def_options_myisam.result b/mysql-test/suite/gcol/r/gcol_column_def_options_myisam.result index 82c4b65512f60..0fc97834ef4a1 100644 --- a/mysql-test/suite/gcol/r/gcol_column_def_options_myisam.result +++ b/mysql-test/suite/gcol/r/gcol_column_def_options_myisam.result @@ -163,7 +163,7 @@ t1 CREATE TABLE `t1` ( drop table t1; create table t1 (a int, b int generated always as (a % 2) virtual); alter table t1 modify b int generated always as (a % 2) stored references t2(a); -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'references t2(a)' at line 1 +ERROR HY000: This is not yet supported for generated columns show create table t1; Table Create Table t1 CREATE TABLE `t1` ( diff --git a/mysql-test/suite/vcol/inc/vcol_column_def_options.inc b/mysql-test/suite/vcol/inc/vcol_column_def_options.inc index 2f28136ad63b6..916d75025d878 100644 --- a/mysql-test/suite/vcol/inc/vcol_column_def_options.inc +++ b/mysql-test/suite/vcol/inc/vcol_column_def_options.inc @@ -107,7 +107,7 @@ create table t1 (a int, b int as (a % 2) persistent references t2(a)); show create table t1; drop table t1; create table t1 (a int, b int as (a % 2)); ---error ER_PARSE_ERROR +--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN alter table t1 modify b int as (a % 2) persistent references t2(a); show create table t1; drop table t1; diff --git a/mysql-test/suite/vcol/r/vcol_column_def_options_innodb.result b/mysql-test/suite/vcol/r/vcol_column_def_options_innodb.result index 82ebc5e936cc8..6d92a5238da49 100644 --- a/mysql-test/suite/vcol/r/vcol_column_def_options_innodb.result +++ b/mysql-test/suite/vcol/r/vcol_column_def_options_innodb.result @@ -136,7 +136,7 @@ t1 CREATE TABLE `t1` ( drop table t1; create table t1 (a int, b int as (a % 2)); alter table t1 modify b int as (a % 2) persistent references t2(a); -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'references t2(a)' at line 1 +ERROR HY000: This is not yet supported for generated columns show create table t1; Table Create Table t1 CREATE TABLE `t1` ( diff --git a/mysql-test/suite/vcol/r/vcol_column_def_options_myisam.result b/mysql-test/suite/vcol/r/vcol_column_def_options_myisam.result index 92110338db4fb..e3e6912b3c198 100644 --- a/mysql-test/suite/vcol/r/vcol_column_def_options_myisam.result +++ b/mysql-test/suite/vcol/r/vcol_column_def_options_myisam.result @@ -136,7 +136,7 @@ t1 CREATE TABLE `t1` ( drop table t1; create table t1 (a int, b int as (a % 2)); alter table t1 modify b int as (a % 2) persistent references t2(a); -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'references t2(a)' at line 1 +ERROR HY000: This is not yet supported for generated columns show create table t1; Table Create Table t1 CREATE TABLE `t1` ( diff --git a/sql/field.cc b/sql/field.cc index e37b4801f6b7f..7cb13127292e6 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -11174,7 +11174,7 @@ Create_field *Create_field::clone(MEM_ROOT *mem_root) const - If field is a BLOB (Which doesn't support normal DEFAULT) */ -bool Column_definition::has_default_expression() +bool Column_definition::has_default_expression() const { return (default_value && (!default_value->expr->basic_const_item() || diff --git a/sql/field.h b/sql/field.h index 8d23a05e72094..a61f6963ce2b4 100644 --- a/sql/field.h +++ b/sql/field.h @@ -4953,7 +4953,7 @@ class Column_definition: public Sql_alloc, return make_field(share, mem_root, &addr, field_name_arg); } /* Return true if default is an expression that must be saved explicitly */ - bool has_default_expression(); + bool has_default_expression() const; bool has_default_now_unireg_check() const { diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 897027cc73db1..6c6d2ff310ba1 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3583,6 +3583,22 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, break; } } + if (sql_field->check_constraint) + { + if (dup_field->check_constraint) + { + if (dup_field->check_constraint->name.str && + sql_field->check_constraint->name.str && + !lex_string_cmp(system_charset_info, + &sql_field->check_constraint->name, + &dup_field->check_constraint->name)) + { + my_error(ER_DUP_CONSTRAINT_NAME, MYF(0), "CHECK", + sql_field->check_constraint->name.str); + DBUG_RETURN(true); + } + } + } } /* Don't pack rows in old tables if the user has requested this */ if ((sql_field->flags & BLOB_FLAG) || @@ -4413,6 +4429,31 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, if (!check->name.length || check->automatic_name) continue; + { + /* Check that there is no same field and table CHECK constraint names*/ + while((dup_field=it2++)) + { + if (!lex_string_cmp(system_charset_info, + &check->name, &dup_field->field_name)) + { + my_error(ER_DUP_CONSTRAINT_NAME, MYF(0), "CHECK", check->name.str); + DBUG_RETURN(TRUE); + } + + if (dup_field->check_constraint) + { + if (!lex_string_cmp(system_charset_info, + &check->name, &dup_field->check_constraint->name)) + { + my_error(ER_DUP_CONSTRAINT_NAME, MYF(0), "CHECK", check->name.str); + DBUG_RETURN(TRUE); + } + } + + } + it2.rewind(); + } + { /* Check that there's no repeating table CHECK constraint names. */ List_iterator_fast diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index f6f826e3e072b..dfffdd84bcd08 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -6615,6 +6615,12 @@ column_def: { $$= $1; } | field_spec references { $$= $1; } + | field_spec constraint check_constraint + { + $$= $1; + $$->check_constraint= $3; + $$->check_constraint->name= $2; + } ; key_def: @@ -8481,7 +8487,7 @@ alter_list_item: | ADD constraint_def { Lex->alter_info.flags|= ALTER_ADD_CHECK_CONSTRAINT; - } + } | ADD CONSTRAINT IF_SYM not EXISTS field_ident check_constraint { Lex->alter_info.flags|= ALTER_ADD_CHECK_CONSTRAINT; @@ -8496,7 +8502,7 @@ alter_list_item: $5->after= $6; } | MODIFY_SYM opt_column opt_if_exists_table_element - field_spec opt_place + column_def opt_place { Lex->alter_info.flags|= ALTER_CHANGE_COLUMN; Lex->create_last_non_select_table= Lex->last_table(); diff --git a/sql/table.cc b/sql/table.cc index 88154986805d5..62892a583999b 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -6009,18 +6009,8 @@ int TABLE::verify_constraints(bool ignore_failure) if (((*chk)->expr->val_int() == 0 && !(*chk)->expr->null_value) || in_use->is_error()) { - StringBuffer field_error(system_charset_info); - enum_vcol_info_type vcol_type= (*chk)->get_vcol_type(); - DBUG_ASSERT(vcol_type == VCOL_CHECK_TABLE || - vcol_type == VCOL_CHECK_FIELD); - if (vcol_type == VCOL_CHECK_FIELD) - { - field_error.append(s->table_name.str); - field_error.append("."); - } - field_error.append((*chk)->name.str); my_error(ER_CONSTRAINT_FAILED, - MYF(ignore_failure ? ME_WARNING : 0), field_error.c_ptr(), + MYF(ignore_failure ? ME_WARNING : 0), (*chk)->name.str, s->db.str, s->table_name.str); return ignore_failure ? VIEW_CHECK_SKIP : VIEW_CHECK_ERROR; } diff --git a/sql/unireg.cc b/sql/unireg.cc index f2d57e7549fcb..680a3faa54351 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -639,7 +639,7 @@ static bool pack_vcols(THD *thd, String *buf, List &create_fields, { Sql_mode_save_for_frm_handling sql_mode_save(thd); List_iterator it(create_fields); - Create_field *field; + const Create_field *field; for (uint field_nr=0; (field= it++); field_nr++) {