Skip to content

Commit 37158b3

Browse files
github-actions[bot]ti-chi-bot
authored andcommitted
Auto-sync: Update English docs from Chinese PR
Synced from: pingcap/docs-cn#21110 Target PR: pingcap#22268 AI Provider: gemini Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 0847697 commit 37158b3

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,32 @@ 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 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+
Since v5.1.0, TiDB supports column type changes that require Reorg-Data. When performing such changes, TiDB rebuilds all existing data in the table. The specific process includes reading original table data, converting the data according to the new column type, and then rewriting the converted data into the table. Since it needs to process all table data, Reorg-Data operations usually take a long time, and their execution time is directly 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
1416
- Compressing the length of `VARCHAR(10)` to `VARCHAR(5)`
1517

18+
Starting from v8.5.5 and v9.0.0, TiDB has optimized some column type changes that originally required Reorg-Data. When the following conditions are met, TiDB will no longer rebuild table data but only rebuild affected indexes, thereby improving execution efficiency:
19+
20+
- The current session's [SQL mode](/sql-mode.md) is strict mode (`sql_mode` includes `STRICT_TRANS_TABLES` or `STRICT_ALL_TABLES`).
21+
- There is no risk of data truncation during type conversion.
22+
23+
This optimization applies to the following type change scenarios:
24+
25+
- Changes between integer types (for example, from `BIGINT` to `INT`).
26+
- Changes between string types (for example, from `VARCHAR(200)` to `VARCHAR(100)`).
27+
28+
> **Note:**
29+
>
30+
> When converting from `VARCHAR` to `CHAR`, all original data must not contain trailing spaces. If data that does not meet this condition exists, TiDB will still perform Reorg-Data to ensure that the converted data complies with the `CHAR` type's padding rules.
31+
32+
## 语法图
33+
```
1634
## Synopsis
1735
1836
```ebnf+diagram
@@ -160,7 +178,7 @@ CREATE TABLE `t1` (
160178
> ERROR 1406 (22001): Data Too Long, field len 4, data len 5
161179
> ```
162180
>
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.
181+
> - 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.
164182
>
165183
> ```
166184
> Query OK, 0 rows affected (2.52 sec)

0 commit comments

Comments
 (0)