mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
Bug#45567: Fast ALTER TABLE broken for enum and set
The problem was that appending values to the end of an existing ENUM or SET column was being treated as table data modification, preventing a immediately (fast) table alteration that occurs when only table metadata is being modified. The cause was twofold: adding a enumeration or set members to the end of the list of valid member values was not being considered a "compatible" table alteration, and for SET columns, the check was being done upon the max display length and not the underlying (pack) length of the field. The solution is to augment the function that checks wether two ENUM or SET fields are compatible -- by comparing the pack lengths and performing a limited comparison of the member values. mysql-test/r/alter_table.result: Add test case result for Bug#45567 mysql-test/t/alter_table.test: Add test case for Bug#45567 sql/field.cc: Check whether two fields can be considered 'equal' for table alteration purposes. Fields are equal if they retain the same pack length and if new members are added to the end of the list. sql/field.h: Add comment and remove method.
This commit is contained in:
@ -1268,4 +1268,66 @@ a b
|
||||
4 b
|
||||
5 a
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# Bug#45567: Fast ALTER TABLE broken for enum and set
|
||||
#
|
||||
DROP TABLE IF EXISTS t1;
|
||||
CREATE TABLE t1 (a ENUM('a1','a2'));
|
||||
INSERT INTO t1 VALUES ('a1'),('a2');
|
||||
# No copy: No modification
|
||||
ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2');
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
# No copy: Add new enumeration to the end
|
||||
ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','a3');
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
# Copy: Modify and add new to the end
|
||||
ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','xx','a5');
|
||||
affected rows: 2
|
||||
info: Records: 2 Duplicates: 0 Warnings: 0
|
||||
# Copy: Remove from the end
|
||||
ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','xx');
|
||||
affected rows: 2
|
||||
info: Records: 2 Duplicates: 0 Warnings: 0
|
||||
# Copy: Add new enumeration
|
||||
ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','a0','xx');
|
||||
affected rows: 2
|
||||
info: Records: 2 Duplicates: 0 Warnings: 0
|
||||
# No copy: Add new enumerations to the end
|
||||
ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','a0','xx','a5','a6');
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1 (a SET('a1','a2'));
|
||||
INSERT INTO t1 VALUES ('a1'),('a2');
|
||||
# No copy: No modification
|
||||
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2');
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
# No copy: Add new to the end
|
||||
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a3');
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
# Copy: Modify and add new to the end
|
||||
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','xx','a5');
|
||||
affected rows: 2
|
||||
info: Records: 2 Duplicates: 0 Warnings: 0
|
||||
# Copy: Remove from the end
|
||||
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','xx');
|
||||
affected rows: 2
|
||||
info: Records: 2 Duplicates: 0 Warnings: 0
|
||||
# Copy: Add new member
|
||||
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a0','xx');
|
||||
affected rows: 2
|
||||
info: Records: 2 Duplicates: 0 Warnings: 0
|
||||
# No copy: Add new to the end
|
||||
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a0','xx','a5','a6');
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
# Copy: Numerical incrase (pack lenght)
|
||||
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a0','xx','a5','a6','a7','a8','a9','a10');
|
||||
affected rows: 2
|
||||
info: Records: 2 Duplicates: 0 Warnings: 0
|
||||
DROP TABLE t1;
|
||||
End of 5.1 tests
|
||||
|
@ -1000,4 +1000,50 @@ ALTER TABLE t1 MODIFY b ENUM('a', 'z', 'b', 'c') NOT NULL;
|
||||
SELECT * FROM t1;
|
||||
DROP TABLE t1;
|
||||
|
||||
--echo #
|
||||
--echo # Bug#45567: Fast ALTER TABLE broken for enum and set
|
||||
--echo #
|
||||
|
||||
--disable_warnings
|
||||
DROP TABLE IF EXISTS t1;
|
||||
--enable_warnings
|
||||
|
||||
CREATE TABLE t1 (a ENUM('a1','a2'));
|
||||
INSERT INTO t1 VALUES ('a1'),('a2');
|
||||
--enable_info
|
||||
--echo # No copy: No modification
|
||||
ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2');
|
||||
--echo # No copy: Add new enumeration to the end
|
||||
ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','a3');
|
||||
--echo # Copy: Modify and add new to the end
|
||||
ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','xx','a5');
|
||||
--echo # Copy: Remove from the end
|
||||
ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','xx');
|
||||
--echo # Copy: Add new enumeration
|
||||
ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','a0','xx');
|
||||
--echo # No copy: Add new enumerations to the end
|
||||
ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','a0','xx','a5','a6');
|
||||
--disable_info
|
||||
DROP TABLE t1;
|
||||
|
||||
CREATE TABLE t1 (a SET('a1','a2'));
|
||||
INSERT INTO t1 VALUES ('a1'),('a2');
|
||||
--enable_info
|
||||
--echo # No copy: No modification
|
||||
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2');
|
||||
--echo # No copy: Add new to the end
|
||||
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a3');
|
||||
--echo # Copy: Modify and add new to the end
|
||||
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','xx','a5');
|
||||
--echo # Copy: Remove from the end
|
||||
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','xx');
|
||||
--echo # Copy: Add new member
|
||||
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a0','xx');
|
||||
--echo # No copy: Add new to the end
|
||||
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a0','xx','a5','a6');
|
||||
--echo # Copy: Numerical incrase (pack lenght)
|
||||
ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a0','xx','a5','a6','a7','a8','a9','a10');
|
||||
--disable_info
|
||||
DROP TABLE t1;
|
||||
|
||||
--echo End of 5.1 tests
|
||||
|
Reference in New Issue
Block a user