[MDEV-13134] Introduce ALTER TABLE attributes ALGORITHM=NOCOPY and ALGORITHM=INSTANT Created: 2017-06-20 Updated: 2022-02-24 Resolved: 2018-05-07 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data Definition - Alter Table, Storage Engine - InnoDB |
| Fix Version/s: | 10.3.7 |
| Type: | Task | Priority: | Major |
| Reporter: | Marko Mäkelä | Assignee: | Thirunarayanan Balathandayuthapani |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | ddl, online-ddl | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Description |
|
When MySQL 5.6 introduced the ALGORITHM attribute to ALTER TABLE, only two possible values were introduced in addition to the implied value ALGORITHM=DEFAULT: ALGORITHM=COPY to refer to the old-style ALTER TABLE that basically consists of CREATE TABLE, INSERT…SELECT, RENAME TABLE and DROP TABLE, and ALGORITHM=INPLACE to refer to the "fast" ALTER TABLE whose first incarnation was implemented in the InnoDB Plugin for MySQL 5.1. This choice of keywords is unfortunate, because the supposedly "fast" algorithm would sometimes copy the table. Already the InnoDB Plugin would do it when executing ADD PRIMARY KEY. In MySQL 5.6, several ALGORITHM=INPLACE operations would actually copy the table. Most notably, these would be ADD COLUMN, DROP COLUMN, reordering columns, and changing ROW_FORMAT, and naturally the FORCE attribute that forces a rebuild. The following was originally written in It would be nice to introduce new syntax to prevent nasty surprises. When an operation is expected to be quick, it could be better to return an error than to perform a disruptive (resource-intensive and time-consuming) operation. ALGORITHM=INSTANT will refuse any operation that must modify any data in files. (Updates to metadata are possible.) ALGORITHM=NOCOPY will refuse any operation that would rebuild the clustered index (and the whole table). With respect to the allowed operations, ALGORITHM=INSTANT is a subset of ALGORITHM=NOCOPY which is a subset of ALGORITHM=INPLACE which is a subset of ALGORITHM=COPY. Example:
|
| Comments |
| Comment by Elena Stepanova [ 2017-06-20 ] | ||||
|
As discussed with marko, it might be good in the scope of this task to get rid of this rather pointless warning:
| ||||
| Comment by Marko Mäkelä [ 2017-09-25 ] | ||||
|
As part of this change, I think that we should strongly consider optimizing away non-changes to ENGINE or ROW_FORMAT or possibly other attributes.
If a rebuild is desired, the FORCE keyword can be specified:
| ||||
| Comment by Marko Mäkelä [ 2018-03-26 ] | ||||
|
This looks OK from the InnoDB point of view, after addressing my review comments. | ||||
| Comment by Marko Mäkelä [ 2018-03-29 ] | ||||
|
I posted some more review comments. The only thing that is missing from the InnoDB side is the removal of the warning InnoDB rebuilding table to add column FTS_DOC_ID and the testing of ADD FULLTEXT INDEX…ALGORITHM=NOCOPY. The non-change of ENGINE or ROW_FORMAT will continue to rebuild the table, for now. And those operations will be refused by ALGORITHM=NOCOPY or ALGORITHM=INSTANT. | ||||
| Comment by Thirunarayanan Balathandayuthapani [ 2018-03-30 ] | ||||
|
https://github.com/MariaDB/server/commit/45be7b5ff7abc61c48e7b79877b8ed0bb430e5f3 This is the latest commit. | ||||
| Comment by Thirunarayanan Balathandayuthapani [ 2018-04-02 ] | ||||
| Comment by Marko Mäkelä [ 2018-04-04 ] | ||||
|
The latest looks OK from the InnoDB perspective; the only problem is a misleading error message for refusing ADD FULLTEXT INDEX…ALGORITHM=NOCOPY when a hidden FTS_DOC_ID column would be created. I think that we should consider extending the existing Boolean parameter old_alter_table to integer as follows:
The values 0 and 1 would correspond to the current behaviour. Values 1 to 4 would limit the choice of ALTER TABLE operations. If one wants to avoid performance surprises on the server, one could configure old_alter_table=4 or old_alter_table=3. Then, any ALTER TABLE would be refused, unless it is instantaneous or avoids a table rebuild. Users could explicitly specify ALGORITHM if they want a more expensive operation. | ||||
| Comment by Marko Mäkelä [ 2018-04-05 ] | ||||
|
The name old_alter_table is not very intuitive. Perhaps an alias alter_algorithm should be defined, with the default value alter_algorithm=default (0). | ||||
| Comment by Thirunarayanan Balathandayuthapani [ 2018-05-07 ] | ||||
|
Introduced new alter algorithm type called NOCOPY & INSTANT for inplace alter operation. NOCOPY - Algorithm refuses any alter operation that would rebuild the clustered index. INSTANT - Algorithm allow any alter operation that would modify only meta data. It is a Introduce new variable called alter_algorithm. The values are DEFAULT(0), COPY(1), INPLACE(2), NOCOPY(3), INSTANT(4) Message to deprecate old_alter_table variable and make it alias for alter_algorithm variable. alter_algorithm variable for slave is always set to default value. | ||||
| Comment by Thirunarayanan Balathandayuthapani [ 2018-05-07 ] | ||||
|
Removed the warning for InnoDB table building to add FTS_DOC_ID as well. | ||||
| Comment by Matthias Leich [ 2018-05-07 ] | ||||
|
10.3 commit c5b28e55f6ff2a77bf67a2052cc4f4ddd73bc151 compiled with debug |