Skip to content
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

Support for PK changes from signed int to unsigned bigint #52500

Open
dveeden opened this issue Apr 11, 2024 · 0 comments
Open

Support for PK changes from signed int to unsigned bigint #52500

dveeden opened this issue Apr 11, 2024 · 0 comments
Labels
compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) type/compatibility type/feature-request Categorizes issue or PR as related to a new feature.

Comments

@dveeden
Copy link
Contributor

dveeden commented Apr 11, 2024

Feature Request

Is your feature request related to a problem? Please describe:

A table is created with INT (signed). Then the volume of the data changes. Changing it to BIGINT might help a bit but eventually changing it to BIGINT UNSIGNED is needed.

This can be seen as a sub-issue of #18090

Describe the feature you'd like:

Allow this to work:

CREATE TABLE t (id INT, PRIMARY KEY (id));
ALTER TABLE t MODIFY COLUMN id BIGINT UNSIGNED;

Describe alternatives you've considered:

Something like this might be possible:

CREATE TABLE t2 (id BIGINT UNSIGNED, PRIMARY KEY (id));
INSERT INTO t2 SELECT * FROM t;
RENAME TABLE t TO t_old, t2 TO t;
DROP TABLE t_old;

However:

  • This would likely cause and/or need downtime for the application
  • This is not very efficient
  • This would cause a big stream of data on TiCDC
  • This needs TiDB specific handling of this change (not MySQL Compatible behavior)
  • This either needs the BATCH statement or external tools for larger tables, adding operational overhead.
  • This needs a lot of time.

Another option:

ALTER TABLE t DROP PRIMARY KEY;
ALTER TABLE t MODIFY COLUMN id BIGINT UNSIGNED;
ALTER TABLE t ADD PRIMARY KEY(id);

However:

  • This only works for NONCLUSTERED tables, which isn't the default
  • This leaves a gap in which PK's are not enforced.
  • Doing these 3 operations in a single statement isn't supported by TiDB.

Teachability, Documentation, Adoption, Migration Strategy:

  1. New negative values should be rejected
  2. Then the table contents should be checked for negative values
  3. Then the change should be made. This should be a metadata only change if possible.
  4. Then values bigger than the max-signed value should be allowed.
@dveeden dveeden added type/feature-request Categorizes issue or PR as related to a new feature. type/compatibility compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) labels Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) type/compatibility type/feature-request Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

1 participant