Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
10.0(EOL), 10.1(EOL), 10.2(EOL), 10.3(EOL), 10.4(EOL)
Description
The COLLATE attribute of a column only affects the way how any indexes that are built on the column will be sorted. Thus, it should be possible to change the collation of a column without rebuilding the table, except if the column is part of the PRIMARY KEY.
Currently, changing the collation requires the table to be rebuilt with ALGORITHM=COPY, in all cases below:
--source include/have_innodb.inc
|
CREATE TABLE t1 ( |
a CHAR(1) COLLATE utf8_bin PRIMARY KEY, |
b CHAR(1) COLLATE utf8_bin UNIQUE, |
c CHAR(1) COLLATE utf8_bin |
) ENGINE=InnoDB;
|
ALTER TABLE t1 CHANGE COLUMN c c CHAR(1) COLLATE utf8_general_ci, |
ALGORITHM=INSTANT;
|
ALTER TABLE t1 CHANGE COLUMN b b CHAR(1) COLLATE utf8_general_ci, |
ALGORITHM=NOCOPY; # implies DROP INDEX b, ADD UNIQUE INDEX(b) |
ALTER TABLE t1 CHANGE COLUMN a a CHAR(1) COLLATE utf8_general_ci, |
ALGORITHM=INPLACE; # rebuild due to DROP PRIMARY KEY, ADD PRIMARY KEY(a) |
DROP TABLE t1; |
(When testing versions predating MDEV-13134, replace the ALGORITHM=INSTANT and ALGORITHM=NOCOPY with the broader clause ALGORITHM=INPLACE.)
Attachments
Issue Links
- causes
-
MDEV-22771 Assertion `fields[i].same(instant.fields[i])' failed in dict_index_t::instant_add_field
-
- Closed
-
-
MDEV-26294 Duplicate entries in unique index not detected when changing collation with INPLACE / NOCOPY algoritm
-
- Closed
-
-
MDEV-27280 server crashes on CHECK TABLE after COLLATE change for utf8mb4
-
- Closed
-
- is blocked by
-
MDEV-18961 Converting charset to BINARY should be instantaneous
-
- Closed
-
-
MDEV-19283 Move the code from Field_str::is_equal() to Field_string::is_equal()
-
- Closed
-
- is duplicated by
-
MDEV-18583 Avoid copying when changing the type of an indexed column
-
- Closed
-
- relates to
-
MDEV-11424 Instant ALTER TABLE of failure-free record format changes
-
- Closed
-
-
MDEV-15564 Avoid table rebuild in ALTER TABLE on collation or charset changes
-
- Closed
-
-
MDEV-17300 MariaDB Galera cluster crash after issuing ALTER table
-
- Closed
-
-
MDEV-29436 Change text column collation unnecessarily requires ALGORITHM=COPY
-
- Open
-
I don’t think that we should try to support the table-rebuilding case in InnoDB.
If the SQL layer sets the correct flags, InnoDB should support this via the existing flags for adding and dropping (effectively rebuilding) all affected indexes.
The only InnoDB change should be related to determining whether the character encoding of CHAR(n) columns can be changed instantaneously. For ROW_FORMAT=REDUNDANT, InnoDB cannot allow that, because the columns would always be stored as n*mbmaxlen bytes.
For other ROW_FORMAT than REDUNDANT, InnoDB can allow instantaneous CHAR(n) changes from utf8mb3 to utf8mb4, because it internally uses a variable-length encoding (n*mbminlen…n*mbmaxlen bytes) when mbminlen!=mbmaxlen.