Learn about operations supported by the INPLACE algorithm, which rebuilds the table but allows concurrent DML, offering a balance between performance and availability.
When the ALGORITHM clause is set to INPLACE, the supported operations are a superset of the operations that are supported when the ALGORITHM clause is set to NOCOPY. Similarly, when the ALGORITHM clause is set to NOCOPY, the supported operations are a superset of the operations that are supported when the ALGORITHM clause is set to INSTANT.
Therefore, when the clause is set to INPLACE, some operations are supported by inheritance. See the following additional pages for more information about these supported operations:
ALTER TABLE ... ADD COLUMNInnoDB supports adding columns to a table with set to INPLACE.
The table is rebuilt, which means that all of the data is reorganized substantially, and the indexes are rebuilt. As a result, the operation is quite expensive.
With the exception of adding an column, this operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example:
This applies to for tables.
ALTER TABLE ... DROP COLUMNInnoDB supports dropping columns from a table with set to INPLACE.
The table is rebuilt, which means that all of the data is reorganized substantially, and the indexes are rebuilt. As a result, the operation is quite expensive.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example:
This applies to for tables.
ALTER TABLE ... MODIFY COLUMNThis applies to for tables.
InnoDB supports reordering columns within a table with set to INPLACE.
The table is rebuilt, which means that all of the data is reorganized substantially, and the indexes are rebuilt. As a result, the operation is quite expensive.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example:
InnoDB does not support modifying a column's data type with set to INPLACE in most cases. There are some exceptions:
In and later, InnoDB supports increasing the length of VARCHAR columns with set to INPLACE, unless it would require changing the number of bytes requires to represent the column's length. A VARCHAR column that is between 0 and 255 bytes in size requires 1 byte to represent its length, while a VARCHAR column that is 256 bytes or longer requires 2 bytes to represent its length. This means that the length of a column cannot be increased with set to INPLACE if the original length was less than 256 bytes, and the new length is 256 bytes or more.
In and later, InnoDB supports increasing the length of VARCHAR
See for more information.
For example, this fails:
But this succeeds in and later, because the original length of the column is less than 256 bytes, and the new length is still less than 256 bytes:
But this fails in and later, because the original length of the column is less than 256 bytes, and the new length is greater than 256 bytes:
InnoDB supports modifying a column to allow values with set to INPLACE.
The table is rebuilt, which means that all of the data is reorganized substantially, and the indexes are rebuilt. As a result, the operation is quite expensive.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example:
InnoDB supports modifying a column to not allow values with set to INPLACE. It is required for to be enabled in . The operation will fail if the column contains any NULL values. Changes that would interfere with referential integrity are also not permitted.
The table is rebuilt, which means that all of the data is reorganized substantially, and the indexes are rebuilt. As a result, the operation is quite expensive.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example:
ENUM OptionInnoDB supports adding a new option to a column with set to INPLACE. In order to add a new option with set to INPLACE, the following requirements must be met:
It must be added to the end of the list.
The storage requirements must not change.
This operation only changes the table's metadata, so the table does not have to be rebuilt..
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example, this succeeds:
But this fails:
SET OptionInnoDB supports adding a new option to a column with set to INPLACE. In order to add a new option with set to INPLACE, the following requirements must be met:
It must be added to the end of the list.
The storage requirements must not change.
This operation only changes the table's metadata, so the table does not have to be rebuilt..
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example, this succeeds:
But this fails:
In and later, InnoDB supports removing from a column with set to INPLACE. In order for this to work, the system variable must be set to KEEP. See for more information.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example:
ALTER TABLE ... ALTER COLUMNThis applies to for tables.
InnoDB supports modifying a column's value with set to INPLACE.
This operation only changes the table's metadata, so the table does not have to be rebuilt.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example:
InnoDB supports removing a column's value with set to INPLACE.
This operation only changes the table's metadata, so the table does not have to be rebuilt.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example:
ALTER TABLE ... CHANGE COLUMNInnoDB supports renaming a column with set to INPLACE, unless the column's data type or attributes changed in addition to the name.
This operation only changes the table's metadata, so the table does not have to be rebuilt.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example, this succeeds:
But this fails:
This applies to for tables.
ALTER TABLE ... ADD PRIMARY KEYInnoDB supports adding a primary key to a table with set to INPLACE.
If the new primary key column is not defined as , then it is highly recommended for to be enabled in . Otherwise, NULL values are silently converted to the default value for the given data type, which is probably not the desired behavior in this scenario.
The table is rebuilt, which means that all of the data is reorganized substantially, and the indexes are rebuilt. As a result, the operation is quite expensive.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example, this succeeds:
But this fails:
And this fails:
This applies to for tables.
ALTER TABLE ... DROP PRIMARY KEYInnoDB does not support dropping a primary key with set to INPLACE in most cases.
If you try to do so, then you will see an error. InnoDB only supports this operation with set to COPY. Concurrent DML is not permitted.
However, there is an exception. If you are dropping a primary key, and adding a new one at the same time, then that operation can be performed with set to INPLACE. This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example, this fails:
But this succeeds:
This applies to for tables.
ALTER TABLE ... ADD INDEX and CREATE INDEXThis applies to and for tables.
InnoDB supports adding a plain index to a table with set to INPLACE. The table is not rebuilt.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example, this succeeds:
And this succeeds:
InnoDB supports adding a index to a table with set to INPLACE. The table is not rebuilt in some cases.
However, there are some limitations, such as:
Adding a index to a table that does not have a user-defined FTS_DOC_ID column will require the table to be rebuilt once. When the table is rebuilt, the system adds a hidden FTS_DOC_ID column. From that point forward, adding additional indexes to the same table will not require the table to be rebuilt when is set to INPLACE.
Only one index may be added at a time when is set to INPLACE.
This operation supports a read-only locking strategy. This strategy can be explicitly chosen by setting the clause to SHARED. When this strategy is used, read-only concurrent DML is permitted.
For example, this succeeds, but requires the table to be rebuilt, so that the hidden FTS_DOC_ID column can be added:
And this succeeds in the same way as above:
And this succeeds, and the second command does not require the table to be rebuilt:
But this second command fails, because only one index can be added at a time:
And this third command fails, because a table cannot be rebuilt when it has more than one index:
InnoDB supports adding a index to a table with set to INPLACE.
However, there are some limitations, such as:
If a table has a index, then it cannot be rebuilt by any operations when the clause is set to NONE.
This operation supports a read-only locking strategy. This strategy can be explicitly chosen by setting the clause to SHARED. When this strategy is used, read-only concurrent DML is permitted.
For example, this succeeds:
And this succeeds in the same way as above:
ALTER TABLE ... DROP INDEX and DROP INDEXInnoDB supports dropping indexes from a table with set to INPLACE.
This operation only changes the table's metadata, so the table does not have to be rebuilt.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example, this succeeds:
And this succeeds:
This applies to and for tables.
ALTER TABLE ... ADD FOREIGN KEYInnoDB supports adding foreign key constraints to a table with set to INPLACE. In order to add a new foreign key constraint to a table with set to INPLACE, the system variable needs to be set to OFF. If it is set to ON, then ALGORITHM=COPY is required.
This operation only changes the table's metadata, so the table does not have to be rebuilt.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example, this fails:
But this succeeds:
This applies to for tables.
ALTER TABLE ... DROP FOREIGN KEYInnoDB supports dropping foreign key constraints from a table with set to INPLACE.
This operation only changes the table's metadata, so the table does not have to be rebuilt.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example:
This applies to for tables.
ALTER TABLE ... AUTO_INCREMENT=...InnoDB supports changing a table's value with set to INPLACE. This operation should finish instantly. The table is not rebuilt.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example:
This applies to for tables.
ALTER TABLE ... ROW_FORMAT=...InnoDB supports changing a table's with set to INPLACE.
The table is rebuilt, which means that all of the data is reorganized substantially, and the indexes are rebuilt. As a result, the operation is quite expensive.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example:
This applies to for tables.
ALTER TABLE ... KEY_BLOCK_SIZE=...InnoDB supports changing a table's with set to INPLACE.
The table is rebuilt, which means that all of the data is reorganized substantially, and the indexes are rebuilt. As a result, the operation is quite expensive.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example:
This applies to for tables.
ALTER TABLE ... PAGE_COMPRESSED=... and ALTER TABLE ... PAGE_COMPRESSION_LEVEL=...In and later, InnoDB supports setting a table's value to 1 with set to INPLACE. InnoDB also supports changing a table's value from 1 to 0 with set to INPLACE.
In these versions, InnoDB also supports changing a table's value with set to INPLACE.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
See for more information.
For example, this succeeds:
And this succeeds:
And this succeeds:
This applies to and for tables.
ALTER TABLE ... DROP SYSTEM VERSIONINGInnoDB supports dropping from a table with set to INPLACE.
This operation supports the read-only locking strategy. This strategy can be explicitly chosen by setting the clause to SHARED. When this strategy is used, read-only concurrent DML is permitted.
For example:
This applies to for tables.
ALTER TABLE ... DROP CONSTRAINTIn and later, InnoDB supports dropping a constraint from a table with set to INPLACE. See for more information.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example:
This applies to for tables.
ALTER TABLE ... FORCEInnoDB supports forcing a table rebuild with set to INPLACE.
The table is rebuilt, which means that all of the data is reorganized substantially, and the indexes are rebuilt. As a result, the operation is quite expensive.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example:
This applies to for tables.
ALTER TABLE ... ENGINE=InnoDBInnoDB supports forcing a table rebuild with set to INPLACE.
The table is rebuilt, which means that all of the data is reorganized substantially, and the indexes are rebuilt. As a result, the operation is quite expensive.
This operation supports the non-locking strategy. This strategy can be explicitly chosen by setting the clause to NONE. When this strategy is used, all concurrent DML is permitted.
For example:
This applies to for tables.
OPTIMIZE TABLE ...InnoDB supports optimizing a table with set to INPLACE.
If the system variable is set to OFF, and if the system variable is also set to OFF, then OPTIMIZE TABLE are equivalent to ALTER TABLE … FORCE.
The table is rebuilt, which means that all of the data is reorganized substantially, and the indexes are rebuilt. As a result, the operation is quite expensive.
If either of the previously mentioned system variables is set to ON, then OPTIMIZE TABLE will optimize some data without rebuilding the table. However, the file size will not be reduced.
For example, this succeeds:
And this succeeds, but the table is not rebuilt:
This applies to for tables.
ALTER TABLE ... RENAME TO and RENAME TABLE ...InnoDB supports renaming a table with set to INPLACE.
This operation only changes the table's metadata, so the table does not have to be rebuilt.
This operation supports the exclusive locking strategy. This strategy can be explicitly chosen by setting the clause to EXCLUSIVE. When this strategy is used, concurrent DML is not permitted.
For example, this succeeds:
And this succeeds:
This applies to and for tables.
If a table has more than one index, then it cannot be rebuilt by any operations when is set to INPLACE.
If a table has a index, then it cannot be rebuilt by any operations when the clause is set to NONE.
If a table has a index, then it cannot be rebuilt by any operations when the clause is set to NONE.
do not currently support online DDL for all of the same operations that are supported for "real" columns.
See for more information on the limitations.
This page is licensed: CC BY-SA / Gnu FDL
INPLACE in the cases where the operation supports having the INSTANT.INPLACE.If a table has a FULLTEXT index, then it cannot be rebuilt by any ALTER TABLE operations when the LOCK clause is set to NONE.
CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab ADD COLUMN c VARCHAR(50);
Query OK, 0 rows affected (0.006 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab DROP COLUMN c;
Query OK, 0 rows affected (0.021 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab MODIFY COLUMN c VARCHAR(50) AFTER a;
Query OK, 0 rows affected (0.022 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab MODIFY COLUMN c INT;
ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPYCREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
) CHARACTER SET=latin1;
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab MODIFY COLUMN c VARCHAR(100);
Query OK, 0 rows affected (0.005 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(255)
) CHARACTER SET=latin1;
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab MODIFY COLUMN c VARCHAR(256);
ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPYCREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50) NOT NULL
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab MODIFY COLUMN c VARCHAR(50) NULL;
Query OK, 0 rows affected (0.021 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab MODIFY COLUMN c VARCHAR(50) NOT NULL;
Query OK, 0 rows affected (0.021 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c ENUM('red', 'green')
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab MODIFY COLUMN c ENUM('red', 'green', 'blue');
Query OK, 0 rows affected (0.004 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c ENUM('red', 'green')
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab MODIFY COLUMN c ENUM('red', 'blue', 'green');
ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPYCREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c SET('red', 'green')
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab MODIFY COLUMN c SET('red', 'green', 'blue');
Query OK, 0 rows affected (0.004 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c SET('red', 'green')
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab MODIFY COLUMN c SET('red', 'blue', 'green');
ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPYCREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50) WITH SYSTEM VERSIONING
);
SET SESSION system_versioning_alter_history='KEEP';
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab MODIFY COLUMN c VARCHAR(50) WITHOUT SYSTEM VERSIONING;
Query OK, 0 rows affected (0.005 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab ALTER COLUMN c SET DEFAULT 'NO value explicitly provided.';
Query OK, 0 rows affected (0.005 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50) DEFAULT 'NO value explicitly provided.'
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab ALTER COLUMN c DROP DEFAULT;
Query OK, 0 rows affected (0.005 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab CHANGE COLUMN c str VARCHAR(50);
Query OK, 0 rows affected (0.006 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab CHANGE COLUMN c num INT;
ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPYCREATE OR REPLACE TABLE tab (
a INT,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION sql_mode='STRICT_TRANS_TABLES';
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab ADD PRIMARY KEY (a);
Query OK, 0 rows affected (0.021 sec)CREATE OR REPLACE TABLE tab (
a INT,
b VARCHAR(50),
c VARCHAR(50)
);
INSERT INTO tab VALUES (NULL, NULL, NULL);
SET SESSION sql_mode='STRICT_TRANS_TABLES';
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab ADD PRIMARY KEY (a);
ERROR 1265 (01000): Data truncated for column 'a' at row 1CREATE OR REPLACE TABLE tab (
a INT,
b VARCHAR(50),
c VARCHAR(50)
);
INSERT INTO tab VALUES (1, NULL, NULL);
INSERT INTO tab VALUES (1, NULL, NULL);
SET SESSION sql_mode='STRICT_TRANS_TABLES';
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab ADD PRIMARY KEY (a);
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab DROP PRIMARY KEY;
ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported. Reason: Dropping a primary key is not allowed without also adding a new primary key. Try ALGORITHM=COPYCREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION sql_mode='STRICT_TRANS_TABLES';
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab DROP PRIMARY KEY, ADD PRIMARY KEY (b);
Query OK, 0 rows affected (0.020 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab ADD INDEX b_index (b);
Query OK, 0 rows affected (0.010 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
CREATE INDEX b_index ON tab (b);
Query OK, 0 rows affected (0.011 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab ADD FULLTEXT INDEX b_index (b);
Query OK, 0 rows affected (0.055 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
CREATE FULLTEXT INDEX b_index ON tab (b);
Query OK, 0 rows affected (0.041 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab ADD FULLTEXT INDEX b_index (b);
Query OK, 0 rows affected (0.043 sec)
ALTER TABLE tab ADD FULLTEXT INDEX c_index (c);
Query OK, 0 rows affected (0.017 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50),
d VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab ADD FULLTEXT INDEX b_index (b);
Query OK, 0 rows affected (0.041 sec)
ALTER TABLE tab ADD FULLTEXT INDEX c_index (c), ADD FULLTEXT INDEX d_index (d);
ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported. Reason: InnoDB presently supports one FULLTEXT index creation at a time. Try ALGORITHM=COPYCREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab ADD FULLTEXT INDEX b_index (b);
Query OK, 0 rows affected (0.040 sec)
ALTER TABLE tab ADD FULLTEXT INDEX c_index (c);
Query OK, 0 rows affected (0.015 sec)
ALTER TABLE tab FORCE;
ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported. Reason: InnoDB presently supports one FULLTEXT index creation at a time. Try ALGORITHM=COPYCREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c GEOMETRY NOT NULL
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab ADD SPATIAL INDEX c_index (c);
Query OK, 0 rows affected (0.006 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c GEOMETRY NOT NULL
);
SET SESSION alter_algorithm='INPLACE';
CREATE SPATIAL INDEX c_index ON tab (c);
Query OK, 0 rows affected (0.006 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50),
INDEX b_index (b)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab DROP INDEX b_index;CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50),
INDEX b_index (b)
);
SET SESSION alter_algorithm='INPLACE';
DROP INDEX b_index ON tab;CREATE OR REPLACE TABLE tab1 (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50),
d INT
);
CREATE OR REPLACE TABLE tab2 (
a INT PRIMARY KEY,
b VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab1 ADD FOREIGN KEY tab2_fk (d) REFERENCES tab2 (a);
ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported. Reason: Adding foreign keys needs foreign_key_checks=OFF. Try ALGORITHM=COPYCREATE OR REPLACE TABLE tab1 (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50),
d INT
);
CREATE OR REPLACE TABLE tab2 (
a INT PRIMARY KEY,
b VARCHAR(50)
);
SET SESSION foreign_key_checks=OFF;
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab1 ADD FOREIGN KEY tab2_fk (d) REFERENCES tab2 (a);
Query OK, 0 rows affected (0.011 sec)CREATE OR REPLACE TABLE tab2 (
a INT PRIMARY KEY,
b VARCHAR(50)
);
CREATE OR REPLACE TABLE tab1 (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50),
d INT,
FOREIGN KEY tab2_fk (d) REFERENCES tab2 (a)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab1 DROP FOREIGN KEY tab2_fk;
Query OK, 0 rows affected (0.005 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab AUTO_INCREMENT=100;
Query OK, 0 rows affected (0.004 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
) ROW_FORMAT=DYNAMIC;
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab ROW_FORMAT=COMPRESSED;
Query OK, 0 rows affected (0.025 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
) ROW_FORMAT=COMPRESSED
KEY_BLOCK_SIZE=4;
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab KEY_BLOCK_SIZE=2;
Query OK, 0 rows affected (0.021 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab PAGE_COMPRESSED=1;
Query OK, 0 rows affected (0.006 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
) PAGE_COMPRESSED=1;
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab PAGE_COMPRESSED=0;
Query OK, 0 rows affected (0.020 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
) PAGE_COMPRESSED=1
PAGE_COMPRESSION_LEVEL=5;
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab PAGE_COMPRESSION_LEVEL=4;
Query OK, 0 rows affected (0.006 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
) WITH SYSTEM VERSIONING;
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab DROP SYSTEM VERSIONING;CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50),
CONSTRAINT b_not_empty CHECK (b != '')
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab DROP CONSTRAINT b_not_empty;
Query OK, 0 rows affected (0.004 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab FORCE;
Query OK, 0 rows affected (0.022 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab ENGINE=InnoDB;
Query OK, 0 rows affected (0.022 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SHOW GLOBAL VARIABLES WHERE Variable_name IN('innodb_defragment', 'innodb_optimize_fulltext_only');
+-------------------------------+-------+
| Variable_name | Value |
+-------------------------------+-------+
| innodb_defragment | OFF |
| innodb_optimize_fulltext_only | OFF |
+-------------------------------+-------+
SET SESSION alter_algorithm='INPLACE';
OPTIMIZE TABLE tab;
+---------+----------+----------+-------------------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+---------+----------+----------+-------------------------------------------------------------------+
| db1.tab | optimize | note | Table does not support optimize, doing recreate + analyze instead |
| db1.tab | optimize | status | OK |
+---------+----------+----------+-------------------------------------------------------------------+
2 rows in set (0.026 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET GLOBAL innodb_defragment=ON;
SHOW GLOBAL VARIABLES WHERE Variable_name IN('innodb_defragment', 'innodb_optimize_fulltext_only');
+-------------------------------+-------+
| Variable_name | Value |
+-------------------------------+-------+
| innodb_defragment | ON |
| innodb_optimize_fulltext_only | OFF |
+-------------------------------+-------+
SET SESSION alter_algorithm='INPLACE';
OPTIMIZE TABLE tab;
+---------+----------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+---------+----------+----------+----------+
| db1.tab | optimize | status | OK |
+---------+----------+----------+----------+
1 row in set (0.004 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
ALTER TABLE tab RENAME TO old_tab;
Query OK, 0 rows affected (0.011 sec)CREATE OR REPLACE TABLE tab (
a INT PRIMARY KEY,
b VARCHAR(50),
c VARCHAR(50)
);
SET SESSION alter_algorithm='INPLACE';
RENAME TABLE tab TO old_tab;