-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Allow changing a column to be an AUTO_INCREMENT #39143
Labels
type/feature-request
Categorizes issue or PR as related to a new feature.
Comments
dveeden
added
the
type/feature-request
Categorizes issue or PR as related to a new feature.
label
Nov 14, 2022
With a small patch I can actually change the column: diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go
index bbf3d4fc5..973086f35 100644
--- a/ddl/ddl_api.go
+++ b/ddl/ddl_api.go
@@ -4696,10 +4696,6 @@ func GetModifiableColumnJob(
}
}
- // We don't support modifying column from not_auto_increment to auto_increment.
- if !mysql.HasAutoIncrementFlag(col.GetFlag()) && mysql.HasAutoIncrementFlag(newCol.GetFlag()) {
- return nil, dbterror.ErrUnsupportedModifyColumn.GenWithStackByArgs("can't set auto_increment")
- }
// Disallow modifying column from auto_increment to not auto_increment if the session variable `AllowRemoveAutoInc` is false.
if !sctx.GetSessionVars().AllowRemoveAutoInc && mysql.HasAutoIncrementFlag(col.GetFlag()) && !mysql.HasAutoIncrementFlag(newCol.GetFlag()) {
return nil, dbterror.ErrUnsupportedModifyColumn.GenWithStackByArgs("can't remove auto_increment without @@tidb_allow_remove_auto_inc enabled")
So it looks like this works for an empty table and when the So what's likely to be needed besides this is to make sure this is safe for multiple connections and multiple TiDB servers (Lock the table metadata?) and to automatically set the |
39 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Feature Request
Changing an integer column to be an
AUTO_INCREMENT
after the table is created isn't supported by TiDB, but is supported by MySQL.TiDB
And for
AUTO_RANDOM
:MySQL 8.0
PHPMyAdmin
As an example about why users would need/want this:
A backup made by phpMyAdmin 4.9.7 has this:
CREATE TABLE
statement for a table. The table doesn't have indexes.INSERT INTO
statements to load the dataALTER TABLE
statement to add multiple indexes and set a primary keyALTER TABLE
statement to change theid
column to beAUTO_INCREMENT
This way of re-creating a table with data was probably done to optimize for MySQL with the MyISAM storage engine and/or very old InnoDB versions. However this backup can still be loaded into MySQL 8.0 today.
On TiDB all statements work fine, except for the very last one.
There are probably other situations where changing a column to be an
AUTO_INCREMENT
orAUTO_RANDOM
after the initial creation.A similar case where changing a table after creation can be a problem is #38453
The text was updated successfully, but these errors were encountered: