-
Notifications
You must be signed in to change notification settings - Fork 709
refine modify column #22268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
qiancai
wants to merge
6
commits into
pingcap:master
Choose a base branch
from
qiancai:refine_modifycolumn-21110
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
refine modify column #22268
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d9673c2
Add temp.md
qiancai 3906042
Delete temp.md
qiancai 0e2681e
Auto-sync: Update English docs from Chinese PR
github-actions[bot] 3a02f97
Update sql-statements/sql-statement-modify-column.md
qiancai fa8d351
Update sql-statement-modify-column.md
qiancai 63d1e04
Update sql-statements/sql-statement-modify-column.md
qiancai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,13 +6,29 @@ | |||||
|
|
||||||
| # MODIFY COLUMN | ||||||
|
|
||||||
| 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. | ||||||
| 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. | ||||||
|
|
||||||
| Since v5.1.0, TiDB has supported changes of data types for Reorg data, including but not limited to: | ||||||
| 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. | ||||||
|
|
||||||
| The following are some common examples of column type changes that require Reorg-Data: | ||||||
|
|
||||||
| - Changing `VARCHAR` to `BIGINT` | ||||||
| - Modifying the `DECIMAL` precision | ||||||
| - Compressing the length of `VARCHAR(10)` to `VARCHAR(5)` | ||||||
| - Reducing the length of `VARCHAR(10)` to `VARCHAR(5)` | ||||||
|
|
||||||
| Starting from v8.5.5 and v9.0.0, TiDB optimizes some column type changes that previously required Reorg-Data. When the following conditions are met, TiDB no longer rebuilds the table data; instead, it rebuilds only the affected indexes, thereby improving execution efficiency: | ||||||
|
|
||||||
| - The current session uses a strict [SQL mode](/sql-mode.md) (`sql_mode` includes `STRICT_TRANS_TABLES` or `STRICT_ALL_TABLES`). | ||||||
| - There is no risk of data truncation during type conversion. | ||||||
|
|
||||||
| This optimization applies to the following type change scenarios: | ||||||
|
|
||||||
| - Conversions between integer types, such as from `BIGINT` to `INT` | ||||||
| - Conversions between string types, such as from `VARCHAR(200)` to `VARCHAR(100)` | ||||||
|
|
||||||
| > **Note:** | ||||||
| > | ||||||
| > 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 data complies with the padding rules of the `CHAR` type. | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| ## Synopsis | ||||||
|
|
||||||
|
|
@@ -59,7 +75,7 @@ | |||||
|
|
||||||
| ## Examples | ||||||
|
|
||||||
| ### Meta-Only Change | ||||||
| ### Meta-only change | ||||||
|
|
||||||
| {{< copyable "sql" >}} | ||||||
|
|
||||||
|
|
@@ -109,7 +125,7 @@ | |||||
| 1 row in set (0.00 sec) | ||||||
| ``` | ||||||
|
|
||||||
| ### Reorg-Data Change | ||||||
| ### Reorg-Data change | ||||||
|
|
||||||
| {{< copyable "sql" >}} | ||||||
|
|
||||||
|
|
@@ -168,7 +184,7 @@ | |||||
| > ERROR 1406 (22001): Data Too Long, field len 4, data len 5 | ||||||
| > ``` | ||||||
| > | ||||||
| > - 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. | ||||||
| > - 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. | ||||||
|
Check failure on line 187 in sql-statements/sql-statement-modify-column.md
|
||||||
| > | ||||||
| > ``` | ||||||
| > Query OK, 0 rows affected (2.52 sec) | ||||||
|
|
||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.