-
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-16365 Setting a column NOT NULL fails to return error for
NULL values when there is no DEFAULT Copy and inplace algorithm works similarly for NULL to NOT NULL conversion for the following cases: (1) strict sql mode - Should give error. (2) non-strict sql mode - Should give warnings alone (3) alter ignore table command. - Should give warnings alone.
- Loading branch information
1 parent
1abd877
commit 88aaf59
Showing
33 changed files
with
663 additions
and
349 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
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,71 @@ | ||
--source include/have_innodb.inc | ||
|
||
CREATE TABLE t1(f1 INT)ENGINE=INNODB; | ||
INSERT INTO t1 VALUES(NULL); | ||
SELECT * FROM t1; | ||
--enable_info | ||
--error $error_code | ||
ALTER TABLE t1 CHANGE f1 f1 INT NOT NULL; | ||
--disable_info | ||
SELECT * FROM t1; | ||
DROP TABLE t1; | ||
|
||
CREATE TABLE t1(f1 CHAR(10))ENGINE=INNODB; | ||
INSERT INTO t1 VALUES(NULL); | ||
SELECT * FROM t1; | ||
--enable_info | ||
--error $error_code | ||
ALTER TABLE t1 CHANGE f1 f1 CHAR(10) NOT NULL; | ||
--disable_info | ||
SELECT * FROM t1; | ||
DROP TABLE t1; | ||
|
||
CREATE TABLE t1(f1 VARCHAR(10))ENGINE=INNODB; | ||
INSERT INTO t1 VALUES(NULL); | ||
SELECT * FROM t1; | ||
--enable_info | ||
--error $error_code | ||
ALTER TABLE t1 CHANGE f1 f1 VARCHAR(20) NOT NULL; | ||
--disable_info | ||
SELECT * FROM t1; | ||
DROP TABLE t1; | ||
|
||
CREATE TABLE t1(f1 TEXT)ENGINE=INNODB; | ||
INSERT INTO t1 VALUES(NULL); | ||
SELECT * FROM t1; | ||
--enable_info | ||
--error $error_code | ||
ALTER TABLE t1 CHANGE f1 f1 TEXT NOT NULL DEFAULT 'abc'; | ||
--disable_info | ||
SELECT * FROM t1; | ||
DROP TABLE t1; | ||
|
||
CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL, f3 INT)ENGINE=INNODB; | ||
INSERT INTO t1 VALUES(2, 2, NULL); | ||
SELECT * FROM t1; | ||
--enable_info | ||
--error $error_code | ||
ALTER TABLE t1 CHANGE f3 f3 INT NOT NULL DEFAULT (f1 + f2); | ||
--disable_info | ||
SELECT * FROM t1; | ||
DROP TABLE t1; | ||
|
||
CREATE TABLE t1(f1 INT NOT NULL DEFAULT 0, b TINYINT)ENGINE=InnoDB; | ||
INSERT INTO t1 VALUES(10, NULL); | ||
SELECT * FROM t1; | ||
--enable_info | ||
--error $error_code | ||
ALTER TABLE t1 CHANGE b b TINYINT NOT NULL DEFAULT if(unix_timestamp()>1,1000,0); | ||
--disable_info | ||
SELECT * FROM t1; | ||
DROP TABLE t1; | ||
|
||
# Alter ignore should work irrespective of sql mode | ||
|
||
CREATE TABLE t1(c1 INT NOT NULL, c2 INT, PRIMARY KEY(c1))ENGINE=INNODB; | ||
INSERT INTO t1 VALUES(1, NULL); | ||
--enable_info | ||
ALTER IGNORE TABLE t1 CHANGE c2 c2 INT NOT NULL DEFAULT 2; | ||
--disable_info | ||
SELECT * FROM t1; | ||
DROP TABLE t1; |
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,63 @@ | ||
--source include/have_innodb.inc | ||
--source include/have_debug.inc | ||
--source include/have_debug_sync.inc | ||
|
||
# Alter table should fail for strict sql mode | ||
|
||
CREATE TABLE t1(c1 INT NOT NULL, c2 INT, PRIMARY KEY(c1))ENGINE=INNODB; | ||
INSERT INTO t1 VALUES(1, 1); | ||
--enable_info | ||
SET DEBUG_SYNC= 'row_merge_after_scan | ||
SIGNAL opened WAIT_FOR flushed'; | ||
send ALTER TABLE t1 CHANGE c2 c2 INT NOT NULL DEFAULT 2; | ||
connect (con1,localhost,root); | ||
SET DEBUG_SYNC= 'now WAIT_FOR opened'; | ||
INSERT INTO t1 VALUES(2, NULL); | ||
UPDATE t1 SET c1 = 3 WHERE c2 = 1; | ||
SET DEBUG_SYNC= 'now SIGNAL flushed'; | ||
connection default; | ||
--error $error_code | ||
reap; | ||
--disable_info | ||
SELECT * FROM t1; | ||
DROP TABLE t1; | ||
|
||
# Alter table should successfully apply the log for the alter operation | ||
|
||
CREATE TABLE t1(c1 INT NOT NULL, c2 INT, PRIMARY KEY(c1))ENGINE=INNODB; | ||
INSERT INTO t1 VALUES(1, 1); | ||
--enable_info | ||
SET DEBUG_SYNC= 'row_merge_after_scan | ||
SIGNAL opened WAIT_FOR flushed'; | ||
send ALTER TABLE t1 CHANGE c2 c2 INT NOT NULL DEFAULT 2; | ||
connection con1; | ||
SET DEBUG_SYNC= 'now WAIT_FOR opened'; | ||
INSERT INTO t1 VALUES(2, 3); | ||
UPDATE t1 SET c1 = 3 WHERE c2 = 1; | ||
SET DEBUG_SYNC= 'now SIGNAL flushed'; | ||
connection default; | ||
reap; | ||
--disable_info | ||
SELECT * FROM t1; | ||
DROP TABLE t1; | ||
|
||
# Alter ignore should not give error | ||
|
||
CREATE TABLE t1(c1 INT NOT NULL, c2 INT, c3 INT, PRIMARY KEY(c1))ENGINE=INNODB; | ||
INSERT INTO t1 VALUES(1, 2, 3); | ||
--enable_info | ||
SET DEBUG_SYNC= 'row_merge_after_scan | ||
SIGNAL opened WAIT_FOR flushed'; | ||
send ALTER IGNORE TABLE t1 CHANGE c2 c2 INT NOT NULL DEFAULT 2; | ||
connection con1; | ||
SET DEBUG_SYNC= 'now WAIT_FOR opened'; | ||
UPDATE t1 SET c2= 2 WHERE c1 = 1; | ||
INSERT INTO t1 VALUES (2, NULL, 4); | ||
SET DEBUG_SYNC= 'now SIGNAL flushed'; | ||
connection default; | ||
reap; | ||
--disable_info | ||
SELECT * FROM t1; | ||
DROP TABLE t1; | ||
disconnect con1; | ||
SET DEBUG_SYNC='RESET'; |
42 changes: 42 additions & 0 deletions
42
mysql-test/suite/innodb/r/alter_non_null,COPY,NON-STRICT.rdiff
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,42 @@ | ||
7,8c7,8 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
--- | ||
> affected rows: 1 | ||
> info: Records: 1 Duplicates: 0 Warnings: 1 | ||
21,22c21,22 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
--- | ||
> affected rows: 1 | ||
> info: Records: 1 Duplicates: 0 Warnings: 1 | ||
35,36c35,36 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
--- | ||
> affected rows: 1 | ||
> info: Records: 1 Duplicates: 0 Warnings: 1 | ||
49,50c49,50 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
--- | ||
> affected rows: 1 | ||
> info: Records: 1 Duplicates: 0 Warnings: 1 | ||
63,64c63,64 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
--- | ||
> affected rows: 1 | ||
> info: Records: 1 Duplicates: 0 Warnings: 1 | ||
77,78c77,78 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
--- | ||
> affected rows: 1 | ||
> info: Records: 1 Duplicates: 0 Warnings: 1 | ||
88,89c88,89 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
--- | ||
> affected rows: 1 | ||
> info: Records: 1 Duplicates: 0 Warnings: 1 |
72 changes: 72 additions & 0 deletions
72
mysql-test/suite/innodb/r/alter_non_null,COPY,STRICT.rdiff
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,72 @@ | ||
7,10c7 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
< Warnings: | ||
< Warning 1265 Data truncated for column 'f1' at row 1 | ||
--- | ||
> ERROR 01000: Data truncated for column 'f1' at row 1 | ||
13c10 | ||
< 0 | ||
--- | ||
> NULL | ||
21,24c18 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
< Warnings: | ||
< Warning 1265 Data truncated for column 'f1' at row 1 | ||
--- | ||
> ERROR 01000: Data truncated for column 'f1' at row 1 | ||
27c21 | ||
< | ||
--- | ||
> NULL | ||
35,38c29 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
< Warnings: | ||
< Warning 1265 Data truncated for column 'f1' at row 1 | ||
--- | ||
> ERROR 01000: Data truncated for column 'f1' at row 1 | ||
41c32 | ||
< | ||
--- | ||
> NULL | ||
49,52c40 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
< Warnings: | ||
< Warning 1265 Data truncated for column 'f1' at row 1 | ||
--- | ||
> ERROR 01000: Data truncated for column 'f1' at row 1 | ||
55c43 | ||
< | ||
--- | ||
> NULL | ||
63,66c51 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
< Warnings: | ||
< Warning 1265 Data truncated for column 'f3' at row 1 | ||
--- | ||
> ERROR 01000: Data truncated for column 'f3' at row 1 | ||
69c54 | ||
< 2 2 0 | ||
--- | ||
> 2 2 NULL | ||
77,80c62 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
< Warnings: | ||
< Warning 1265 Data truncated for column 'b' at row 1 | ||
--- | ||
> ERROR 01000: Data truncated for column 'b' at row 1 | ||
83c65 | ||
< 10 0 | ||
--- | ||
> 10 NULL | ||
88,89c70,71 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
--- | ||
> affected rows: 1 | ||
> info: Records: 1 Duplicates: 0 Warnings: 1 |
66 changes: 66 additions & 0 deletions
66
mysql-test/suite/innodb/r/alter_non_null,INPLACE,STRICT.rdiff
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,66 @@ | ||
7,10c7 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
< Warnings: | ||
< Warning 1265 Data truncated for column 'f1' at row 1 | ||
--- | ||
> ERROR 01000: Data truncated for column 'f1' at row 1 | ||
13c10 | ||
< 0 | ||
--- | ||
> NULL | ||
21,24c18 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
< Warnings: | ||
< Warning 1265 Data truncated for column 'f1' at row 1 | ||
--- | ||
> ERROR 01000: Data truncated for column 'f1' at row 1 | ||
27c21 | ||
< | ||
--- | ||
> NULL | ||
35,38c29 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
< Warnings: | ||
< Warning 1265 Data truncated for column 'f1' at row 1 | ||
--- | ||
> ERROR 01000: Data truncated for column 'f1' at row 1 | ||
41c32 | ||
< | ||
--- | ||
> NULL | ||
49,52c40 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
< Warnings: | ||
< Warning 1265 Data truncated for column 'f1' at row 1 | ||
--- | ||
> ERROR 01000: Data truncated for column 'f1' at row 1 | ||
55c43 | ||
< | ||
--- | ||
> NULL | ||
63,66c51 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
< Warnings: | ||
< Warning 1265 Data truncated for column 'f3' at row 1 | ||
--- | ||
> ERROR 01000: Data truncated for column 'f3' at row 1 | ||
69c54 | ||
< 2 2 0 | ||
--- | ||
> 2 2 NULL | ||
77,80c62 | ||
< affected rows: 0 | ||
< info: Records: 0 Duplicates: 0 Warnings: 1 | ||
< Warnings: | ||
< Warning 1265 Data truncated for column 'b' at row 1 | ||
--- | ||
> ERROR 01000: Data truncated for column 'b' at row 1 | ||
83c65 | ||
< 10 0 | ||
--- | ||
> 10 NULL |
Oops, something went wrong.