Skip to content

Commit

Permalink
MDEV-15338 Crash in debug build when dropping column that is part of …
Browse files Browse the repository at this point in the history
…CHECK

Crash happened when deleting all columns that was part of a check constraint

The bug was that read map for from table was used when
checking CHECK constraint and was not properly reset
in copy_data_between_tables()
  • Loading branch information
montywi committed May 22, 2018
1 parent a107c79 commit 2dff8fe
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
33 changes: 33 additions & 0 deletions mysql-test/r/check.result
Expand Up @@ -52,3 +52,36 @@ connection default;
UNLOCK TABLES;
DROP TABLE t1;
disconnect con1;
#
# MDEV-15338
# Assertion `!table || (!table->read_set ||
# bitmap_is_set(table->read_set, field_index))'
# failed on dropping column with CHECK
#
CREATE TABLE t1 (a INT, b INT, CHECK (a>0)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1,2),(3,4);
ALTER TABLE t1 DROP COLUMN a;
CREATE OR REPLACE TABLE t1 (a INT, b INT, CHECK (a>0)) ENGINE=MyISAM;
ALTER TABLE t1 DROP COLUMN b;
CREATE OR REPLACE TABLE t1 (a INT, b INT, c INT, CHECK (a+b>0)) ENGINE=MyISAM;
ALTER TABLE t1 DROP COLUMN b;
ERROR 42S22: Unknown column 'b' in 'CHECK'
ALTER TABLE t1 DROP COLUMN a, DROP COLUMN b;
CREATE OR REPLACE TABLE t1 (a INT, b INT, c INT, CHECK (a+b>0)) ENGINE=MyISAM;
ALTER TABLE t1 DROP CONSTRAINT `CONSTRAINT_1`;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
`c` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
CREATE OR REPLACE TABLE t1 (a INT, b INT, c INT, CHECK (a+b>0)) ENGINE=MyISAM;
ALTER TABLE t1 DROP COLUMN b, DROP CONSTRAINT `CONSTRAINT_1`;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`c` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
24 changes: 24 additions & 0 deletions mysql-test/t/check.test
Expand Up @@ -79,3 +79,27 @@ disconnect con1;

# Wait till we reached the initial number of concurrent sessions
--source include/wait_until_count_sessions.inc

--echo #
--echo # MDEV-15338
--echo # Assertion `!table || (!table->read_set ||
--echo # bitmap_is_set(table->read_set, field_index))'
--echo # failed on dropping column with CHECK
--echo #

CREATE TABLE t1 (a INT, b INT, CHECK (a>0)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1,2),(3,4);
ALTER TABLE t1 DROP COLUMN a;
CREATE OR REPLACE TABLE t1 (a INT, b INT, CHECK (a>0)) ENGINE=MyISAM;
ALTER TABLE t1 DROP COLUMN b;
CREATE OR REPLACE TABLE t1 (a INT, b INT, c INT, CHECK (a+b>0)) ENGINE=MyISAM;
--error ER_BAD_FIELD_ERROR
ALTER TABLE t1 DROP COLUMN b;
ALTER TABLE t1 DROP COLUMN a, DROP COLUMN b;
CREATE OR REPLACE TABLE t1 (a INT, b INT, c INT, CHECK (a+b>0)) ENGINE=MyISAM;
ALTER TABLE t1 DROP CONSTRAINT `CONSTRAINT_1`;
SHOW CREATE TABLE t1;
CREATE OR REPLACE TABLE t1 (a INT, b INT, c INT, CHECK (a+b>0)) ENGINE=MyISAM;
ALTER TABLE t1 DROP COLUMN b, DROP CONSTRAINT `CONSTRAINT_1`;
SHOW CREATE TABLE t1;
DROP TABLE t1;
5 changes: 5 additions & 0 deletions sql/sql_table.cc
Expand Up @@ -9844,6 +9844,11 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,

alter_table_manage_keys(to, from->file->indexes_are_disabled(), keys_onoff);

/* Set read map for all fields in from table */
from->default_column_bitmaps();
bitmap_set_all(from->read_set);
from->file->column_bitmaps_signal();

/* We can abort alter table for any table type */
thd->abort_on_warning= !ignore && thd->is_strict_mode();

Expand Down

0 comments on commit 2dff8fe

Please sign in to comment.