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 dumping sequences #32538

Closed
kennytm opened this issue Apr 25, 2020 · 2 comments · Fixed by #32570
Closed

Support dumping sequences #32538

kennytm opened this issue Apr 25, 2020 · 2 comments · Fixed by #32570
Labels
component/dumpling This is related to Dumpling of TiDB. feature/accepted This feature request is accepted by product managers priority/P2 The issue has P2 priority. type/new-feature

Comments

@kennytm
Copy link
Contributor

kennytm commented Apr 25, 2020

Support dumping MariaDB and TiDB sequences. The sequence schema file should contain two statements:

CREATE SEQUENCE `seq_name` ...;
DO setval(`seq_name`, 1001);

The sequence value can be obtained by:

  • MariaDB: SELECT next_not_cached_value FROM seq_name (a sequence is just a table in MariaDB)
  • TiDB: no SQL statements yet, to be done.
@kennytm kennytm added the priority/P2 The issue has P2 priority. label May 28, 2020
@lichunzhu lichunzhu transferred this issue from pingcap/dumpling Feb 22, 2022
@lichunzhu lichunzhu added component/dumpling This is related to Dumpling of TiDB. feature/accepted This feature request is accepted by product managers type/new-feature labels Feb 22, 2022
@lichunzhu
Copy link
Contributor

TiDB's show table next_row_id handle can get next_not_cached_value can get next_not_cached_value now.

mysql> show create sequence s;
+----------+--------------------------------------------------------------------------------------------------------------------------+
| Sequence | Create Sequence                                                                                                          |
+----------+--------------------------------------------------------------------------------------------------------------------------+
| s        | CREATE SEQUENCE `s` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB |
+----------+--------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> show table test.s next_row_id;
+---------+------------+-------------+--------------------+----------------+
| DB_NAME | TABLE_NAME | COLUMN_NAME | NEXT_GLOBAL_ROW_ID | ID_TYPE        |
+---------+------------+-------------+--------------------+----------------+
| test    | s          | _tidb_rowid |                  1 | AUTO_INCREMENT |
| test    | s          |             |                  1 | SEQUENCE       |
+---------+------------+-------------+--------------------+----------------+
2 rows in set (0.00 sec)

mysql> select nextval(s);
+------------+
| nextval(s) |
+------------+
|          1 |
+------------+
1 row in set (0.01 sec)

mysql> show table test.s next_row_id;
+---------+------------+-------------+--------------------+----------------+
| DB_NAME | TABLE_NAME | COLUMN_NAME | NEXT_GLOBAL_ROW_ID | ID_TYPE        |
+---------+------------+-------------+--------------------+----------------+
| test    | s          | _tidb_rowid |                  1 | AUTO_INCREMENT |
| test    | s          |             |               1001 | SEQUENCE       |
+---------+------------+-------------+--------------------+----------------+
2 rows in set (0.00 sec)

Dumpling should support using show create sequence to get sequence SQL and use select setval(seq, next_not_cached_value) to rebase sequence start value to next_not_cached_value. Both SQLs should be written in format like test.s-schema-sequence.

@lichunzhu
Copy link
Contributor

sql example:
test-s-schema-sequence.sql

CREATE SEQUENCE `s` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
select setval(s, 1001);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/dumpling This is related to Dumpling of TiDB. feature/accepted This feature request is accepted by product managers priority/P2 The issue has P2 priority. type/new-feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants