Pre-General Availability Draft: 2017-07-24
ALTER TABLE operations permitted for
generated columns are
Generated columns can be added.
The data type and expression of generated columns can be modified.
Generated columns can be renamed or dropped, if no other column refers to them.
Virtual generated columns cannot be altered to stored generated columns, or vice versa. To work around this, drop the column, then add it with the new definition.
Nongenerated columns can be altered to stored but not virtual generated columns.
Stored but not virtual generated columns can be altered to nongenerated columns. The stored generated values become the values of the nongenerated column.
ADD COLUMNis not an in-place operation for stored columns (done without using a temporary table) because the expression must be evaluated by the server. For stored columns, indexing changes are done in place, and expression changes are not done in place. Changes to column comments are done in place.
For non-partitioned tables,
DROP COLUMNare in-place operations for virtual columns. However, adding or dropping a virtual column cannot be performed in place in combination with other
For partitioned tables,
DROP COLUMNare not in-place operations for virtual columns.
InnoDBsupports secondary indexes on virtual generated columns. Adding or dropping a secondary index on a virtual generated column is an in-place operation. For more information, see Section 126.96.36.199, “Secondary Indexes and Generated Columns”.
VIRTUALgenerated column is added to a table or modified, it is not ensured that data being calculated by the generated column expression will not be out of range for the column. This can lead to inconsistent data being returned and unexpectedly failed statements. To permit control over whether validation occurs for such columns,
WITHOUT VALIDATION(the default if neither clause is specified), an in-place operation is performed (if possible), data integrity is not checked, and the statement finishes more quickly. However, later reads from the table might report warnings or errors for the column if values are out of range.
ALTER TABLEcopies the table. If an out-of-range or any other error occurs, the statement fails. Because a table copy is performed, the statement takes longer.
WITH VALIDATIONare permitted only with
CHANGE COLUMN, and
MODIFY COLUMNoperations. An
ER_WRONG_USAGEerror occurs otherwise.
If expression evaluation causes truncation or provides incorrect input to a function, the
ALTER TABLEstatement terminates with an error and the DDL operation is rejected.
ALTER TABLEstatement that changes the default value of a column
col_namemay also change the value of a generated column expression that refers to the column using
col_name, which may change the value of a generated column expression that refers to the column using
DEFAULT(. For this reason,
ALTER TABLEoperations that change the definition of a column now cause a table rebuild if any generated column expression uses