Spec-Zone .ru
спецификации, руководства, описания, API
|
VARCHAR
size may be increased using an in-place ALTER
TABLE
, as in this example:
ALTER TABLE t1 ALGORITHM=INPLACE, CHANGE COLUMN c1 c1 VARCHAR(255);
This is true as long as the number of length bytes required by a VARCHAR
column remains the same. For VARCHAR
values of 0 to 255, one length byte is required to encode the value. For
VARCHAR
values of 256 bytes or more, two length bytes are required. As a result, in-place ALTER TABLE
only supports increasing VARCHAR
size from 0 to 255 bytes or increasing VARCHAR
size from a value equal to or greater than 256 bytes.
In-place ALTER TABLE
does not support increasing VARCHAR
size from less than 256 bytes to a value equal to or greater than 256
bytes. In this case, the number of required length bytes would change from 1 to 2, which is only supported by a
table copy (ALGORITHM=COPY
). For example, attempting to change VARCHAR
column size from 255 to 256 using in-place ALTER TABLE
would return an error:
ALTER TABLE t1 ALGORITHM=INPLACE, CHANGE COLUMN c1 c1 VARCHAR(256);ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Cannot changecolumn type INPLACE. Try ALGORITHM=COPY.
Decreasing VARCHAR
size using in-place ALTER TABLE
is not supported. Decreasing VARCHAR
size requires a table copy (ALGORITHM=COPY
).