You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sql-statements/sql-statement-modify-column.md
+21-3Lines changed: 21 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,14 +5,32 @@ summary: An overview of the usage of MODIFY COLUMN for the TiDB database.
5
5
6
6
# MODIFY COLUMN
7
7
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.
9
9
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:
11
13
12
14
- Changing `VARCHAR` to `BIGINT`
13
15
- Modifying the `DECIMAL` precision
14
16
- Compressing the length of `VARCHAR(10)` to `VARCHAR(5)`
15
17
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
+
```
16
34
## Synopsis
17
35
18
36
```ebnf+diagram
@@ -160,7 +178,7 @@ CREATE TABLE `t1` (
160
178
> ERROR 1406 (22001): Data Too Long, field len 4, data len 5
161
179
> ```
162
180
>
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 ReorgData.
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.
0 commit comments