Skip to content

Commit

Permalink
MDEV-18819: Add a test case
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-m committed Mar 5, 2019
1 parent 730ed99 commit 90f09ba
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 0 deletions.
116 changes: 116 additions & 0 deletions mysql-test/suite/innodb/r/innodb-alter-nullable.result
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,119 @@ c
0
1
DROP TABLE t1;
CREATE TABLE t1(c INT, g INT AS (c) PERSISTENT) ENGINE=InnoDB;
CREATE TABLE t2(c INT, v INT AS (c) VIRTUAL) ENGINE=InnoDB;
CREATE TABLE t3(c INT, v INT AS (c) VIRTUAL, INDEX(v)) ENGINE=InnoDB;
INSERT INTO t1 SET c=NULL;
INSERT INTO t2 SET c=NULL;
INSERT INTO t3 SET c=NULL;
SET @old_sql_mode = @@sql_mode;
SET sql_mode = '';
ALTER TABLE t1 MODIFY c INT NOT NULL;
affected rows: 1
info: Records: 1 Duplicates: 0 Warnings: 1
Warnings:
Warning 1265 Data truncated for column 'c' at row 1
ALTER TABLE t2 MODIFY c INT NOT NULL;
affected rows: 1
info: Records: 1 Duplicates: 0 Warnings: 1
Warnings:
Warning 1265 Data truncated for column 'c' at row 1
ALTER TABLE t3 MODIFY c INT NOT NULL;
affected rows: 1
info: Records: 1 Duplicates: 0 Warnings: 1
Warnings:
Warning 1265 Data truncated for column 'c' at row 1
SET sql_mode = @old_sql_mode;
SELECT * FROM t1;
c g
0 0
SELECT * FROM t2;
c v
0 0
SELECT * FROM t3;
c v
0 0
SELECT v FROM t3 FORCE INDEX(v);
v
0
CHECK TABLE t1,t2,t3;
Table Op Msg_type Msg_text
test.t1 check status OK
test.t2 check status OK
test.t3 check status OK
DROP TABLE t1,t2,t3;
CREATE TABLE t1(c INT, g INT AS (c) PERSISTENT) ENGINE=InnoDB;
CREATE TABLE t2(c INT, v INT AS (c) VIRTUAL) ENGINE=InnoDB;
CREATE TABLE t3(c INT, v INT AS (c) VIRTUAL, INDEX(v)) ENGINE=InnoDB;
INSERT INTO t1 SET c=NULL;
INSERT INTO t2 SET c=NULL;
INSERT INTO t3 SET c=NULL;
ALTER IGNORE TABLE t1 MODIFY c INT NOT NULL;
affected rows: 1
info: Records: 1 Duplicates: 0 Warnings: 1
Warnings:
Warning 1265 Data truncated for column 'c' at row 1
ALTER IGNORE TABLE t2 MODIFY c INT NOT NULL;
affected rows: 1
info: Records: 1 Duplicates: 0 Warnings: 1
Warnings:
Warning 1265 Data truncated for column 'c' at row 1
ALTER IGNORE TABLE t3 MODIFY c INT NOT NULL;
affected rows: 1
info: Records: 1 Duplicates: 0 Warnings: 1
Warnings:
Warning 1265 Data truncated for column 'c' at row 1
SELECT * FROM t1;
c g
0 0
SELECT * FROM t2;
c v
0 0
SELECT * FROM t3;
c v
0 0
SELECT v FROM t3 FORCE INDEX(v);
v
0
CHECK TABLE t1,t2,t3;
Table Op Msg_type Msg_text
test.t1 check status OK
test.t2 check status OK
test.t3 check status OK
DROP TABLE t1,t2,t3;
CREATE TABLE t1(c INT, g INT AS (c) PERSISTENT) ENGINE=InnoDB;
CREATE TABLE t2(c INT, v INT AS (c) VIRTUAL) ENGINE=InnoDB;
CREATE TABLE t3(c INT, v INT AS (c) VIRTUAL, INDEX(v)) ENGINE=InnoDB;
INSERT INTO t1 SET c=NULL;
INSERT INTO t2 SET c=NULL;
INSERT INTO t3 SET c=NULL;
ALTER TABLE t1 MODIFY c INT NOT NULL;
ERROR 22004: Invalid use of NULL value
ALTER TABLE t2 MODIFY c INT NOT NULL;
ERROR 22004: Invalid use of NULL value
ALTER TABLE t3 MODIFY c INT NOT NULL;
ERROR 01000: Data truncated for column 'c' at row 1
UPDATE t1 SET c=0;
UPDATE t2 SET c=0;
UPDATE t3 SET c=0;
ALTER TABLE t1 MODIFY c INT NOT NULL;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
ALTER TABLE t2 MODIFY c INT NOT NULL;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
# MDEV-18819 FIXME: This should not require ALGORITHM=COPY.
ALTER TABLE t3 MODIFY c INT NOT NULL;
affected rows: 1
info: Records: 1 Duplicates: 0 Warnings: 0
SELECT * FROM t1;
c g
0 0
SELECT * FROM t2;
c v
0 0
SELECT * FROM t3;
c v
0 0
DROP TABLE t1,t2,t3;
68 changes: 68 additions & 0 deletions mysql-test/suite/innodb/t/innodb-alter-nullable.test
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,74 @@ ALTER IGNORE TABLE t1 ADD PRIMARY KEY(c);
SELECT * FROM t1;
DROP TABLE t1;

CREATE TABLE t1(c INT, g INT AS (c) PERSISTENT) ENGINE=InnoDB;
CREATE TABLE t2(c INT, v INT AS (c) VIRTUAL) ENGINE=InnoDB;
CREATE TABLE t3(c INT, v INT AS (c) VIRTUAL, INDEX(v)) ENGINE=InnoDB;
INSERT INTO t1 SET c=NULL;
INSERT INTO t2 SET c=NULL;
INSERT INTO t3 SET c=NULL;
SET @old_sql_mode = @@sql_mode;
# Allow lossy conversions of data
SET sql_mode = '';
--enable_info
ALTER TABLE t1 MODIFY c INT NOT NULL;
ALTER TABLE t2 MODIFY c INT NOT NULL;
ALTER TABLE t3 MODIFY c INT NOT NULL;
--disable_info
SET sql_mode = @old_sql_mode;
SELECT * FROM t1;
SELECT * FROM t2;
SELECT * FROM t3;
SELECT v FROM t3 FORCE INDEX(v);
CHECK TABLE t1,t2,t3;
DROP TABLE t1,t2,t3;

CREATE TABLE t1(c INT, g INT AS (c) PERSISTENT) ENGINE=InnoDB;
CREATE TABLE t2(c INT, v INT AS (c) VIRTUAL) ENGINE=InnoDB;
CREATE TABLE t3(c INT, v INT AS (c) VIRTUAL, INDEX(v)) ENGINE=InnoDB;
INSERT INTO t1 SET c=NULL;
INSERT INTO t2 SET c=NULL;
INSERT INTO t3 SET c=NULL;
--enable_info
ALTER IGNORE TABLE t1 MODIFY c INT NOT NULL;
ALTER IGNORE TABLE t2 MODIFY c INT NOT NULL;
ALTER IGNORE TABLE t3 MODIFY c INT NOT NULL;
--disable_info
SELECT * FROM t1;
SELECT * FROM t2;
SELECT * FROM t3;
SELECT v FROM t3 FORCE INDEX(v);
CHECK TABLE t1,t2,t3;
DROP TABLE t1,t2,t3;

CREATE TABLE t1(c INT, g INT AS (c) PERSISTENT) ENGINE=InnoDB;
CREATE TABLE t2(c INT, v INT AS (c) VIRTUAL) ENGINE=InnoDB;
CREATE TABLE t3(c INT, v INT AS (c) VIRTUAL, INDEX(v)) ENGINE=InnoDB;
INSERT INTO t1 SET c=NULL;
INSERT INTO t2 SET c=NULL;
INSERT INTO t3 SET c=NULL;
--enable_info
--error ER_INVALID_USE_OF_NULL
ALTER TABLE t1 MODIFY c INT NOT NULL;
--error ER_INVALID_USE_OF_NULL
ALTER TABLE t2 MODIFY c INT NOT NULL;
--error WARN_DATA_TRUNCATED
ALTER TABLE t3 MODIFY c INT NOT NULL;
--disable_info
UPDATE t1 SET c=0;
UPDATE t2 SET c=0;
UPDATE t3 SET c=0;
--enable_info
ALTER TABLE t1 MODIFY c INT NOT NULL;
ALTER TABLE t2 MODIFY c INT NOT NULL;
--echo # MDEV-18819 FIXME: This should not require ALGORITHM=COPY.
ALTER TABLE t3 MODIFY c INT NOT NULL;
--disable_info
SELECT * FROM t1;
SELECT * FROM t2;
SELECT * FROM t3;
DROP TABLE t1,t2,t3;

# Check that all connections opened by test cases in this file are really
# gone so execution of other tests won't be affected by their presence.
--source include/wait_until_count_sessions.inc

0 comments on commit 90f09ba

Please sign in to comment.