Skip to content

Commit 3c1e259

Browse files
ti-chi-botgithub-actions[bot]Oreoxmtqiancai
authored
v8.5.5: refine modify column (#22268) (#22319)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Aolin <aolinz@outlook.com> Co-authored-by: Grace Cai <qqzczy@126.com>
1 parent 5e45535 commit 3c1e259

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

sql-statements/sql-statement-modify-column.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,30 @@ summary: An overview of the usage of MODIFY COLUMN for the TiDB database.
55

66
# MODIFY COLUMN
77

8-
The `ALTER TABLE.. MODIFY COLUMN` statement modifies a column on an existing table. The modification can include changing the data type and attributes. To rename at the same time, use the [`CHANGE COLUMN`](/sql-statements/sql-statement-change-column.md) statement instead.
8+
The `ALTER TABLE ... MODIFY COLUMN` statement modifies a column on an existing table. The modification can include changing the data type and attributes. To rename the column at the same time, use the [`CHANGE COLUMN`](/sql-statements/sql-statement-change-column.md) statement instead.
99

10-
Since v5.1.0, TiDB has supported changes of data types for Reorg data, including but not limited to:
10+
Starting from v5.1.0, TiDB supports column type changes that require Reorg-Data. When performing such changes, TiDB rebuilds all existing data in the table by reading the original data, converting it to the new column type, and then writing the converted data back to the table. Because all table data must be processed, Reorg-Data operations typically take a long time, and the execution time is proportional to the amount of data in the table.
11+
12+
The following are some common examples of column type changes that require Reorg-Data:
1113

1214
- Changing `VARCHAR` to `BIGINT`
1315
- Modifying the `DECIMAL` precision
14-
- Compressing the length of `VARCHAR(10)` to `VARCHAR(5)`
16+
- Reducing the length of `VARCHAR(10)` to `VARCHAR(5)`
17+
18+
Starting from v8.5.5, TiDB optimizes some column type changes that previously required Reorg-Data. When the following conditions are met, TiDB rebuilds only the affected indexes instead of the entire table, thereby improving execution efficiency:
19+
20+
- The current session uses a strict [SQL mode](/sql-mode.md) (`sql_mode` includes `STRICT_TRANS_TABLES` or `STRICT_ALL_TABLES`).
21+
- The table has no TiFlash replicas.
22+
- There is no risk of data truncation during type conversion.
23+
24+
This optimization only applies to the following type change scenarios:
25+
26+
- Conversions between integer types, such as from `BIGINT` to `INT`
27+
- Conversions between string types where the character set remains unchanged, such as from `VARCHAR(200)` to `VARCHAR(100)`
28+
29+
> **Note:**
30+
>
31+
> When converting from `VARCHAR` to `CHAR`, the original data must not contain trailing spaces. If the original data contains trailing spaces, TiDB still performs Reorg-Data to ensure that the converted values comply with the padding rules of the `CHAR` type.
1532
1633
## Synopsis
1734

@@ -51,7 +68,7 @@ ColumnName ::=
5168

5269
## Examples
5370

54-
### Meta-Only Change
71+
### Meta-only change
5572

5673
{{< copyable "sql" >}}
5774

@@ -101,7 +118,7 @@ Create Table: CREATE TABLE `t1` (
101118
1 row in set (0.00 sec)
102119
```
103120

104-
### Reorg-Data Change
121+
### Reorg-Data change
105122

106123
{{< copyable "sql" >}}
107124

@@ -160,7 +177,7 @@ CREATE TABLE `t1` (
160177
> ERROR 1406 (22001): Data Too Long, field len 4, data len 5
161178
> ```
162179
>
163-
> - Due to the compatibility with the Async Commit feature, the DDL statement waits for a period of time (about 2.5s) before starting to process into Reorg Data.
180+
> - Due to the compatibility with the Async Commit feature, when [Metadata lock](/metadata-lock.md) is disabled, the DDL statement waits for a period of time (about 2.5s) before starting to process into Reorg-Data.
164181
>
165182
> ```
166183
> Query OK, 0 rows affected (2.52 sec)

0 commit comments

Comments
 (0)