Skip to content

Commit

Permalink
WL#6204 - InnoDB persistent max value for autoinc columns
Browse files Browse the repository at this point in the history
This worklog makes use of the framework introduced by WL#7816 to persist
the autoinc counters. After this worklog there would be some behaviour
changes or important points of autoinc counter:

1. Counters of AUTO_INCREMENT should be strictly incremental, as it works
now, when the server is running.

2. Allocated counters won't be reused after the server restart normally,
this must be guaranteed.

3. Allocated counters won't be reused after the server restart from a
crash, this can NOT be guaranteed, since we can't flush the redo logs
immediately everytime.

4. Rollback of transaction won't revert the counter.

5. 'ALTER TABLE' would not change the counter to a smaller value than
current existing max counter in the table.

6. If a counter is updated to some larger value than current next value,
the larger value should be remembered and next counter should start from
it.

The persistence during DDL is not supported very well now, since some
DDL operations are not atomic now. This would be fixed in WL#7743,
WL#7141, and WL#7016.

RB:9138
Reviewed-by: Jimmy Yang <jimmy.yang@oracle.com>
Reviewed-by: Marko Makela <marko.makela@oracle.com>
  • Loading branch information
Bin Su committed Nov 19, 2015
1 parent b6a9959 commit dcb8792
Show file tree
Hide file tree
Showing 42 changed files with 3,501 additions and 252 deletions.
61 changes: 61 additions & 0 deletions mysql-test/suite/innodb/include/autoinc_persist_alter.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

eval CREATE TABLE $table LIKE $template;

eval INSERT INTO $table SELECT * FROM $template;

eval SELECT * FROM $table;

eval SHOW CREATE TABLE $table;

--echo # This will keep the autoinc counter
eval ALTER TABLE $table AUTO_INCREMENT = 250, ALGORITHM = $algorithm;
--echo # We expect the counter to be 250
eval SHOW CREATE TABLE $table;

--echo # This should keep the autoinc counter as well
eval ALTER TABLE $table ADD COLUMN b INT, ALGORITHM = $algorithm;
--echo # We expect the counter to be 250
eval SHOW CREATE TABLE $table;

eval DELETE FROM $table WHERE a > 150;

eval SELECT * FROM $table;

--echo # This should reset the autoinc counter to the one specified
--echo # Since it's smaller than current one but bigger than existing
--echo # biggest counter in the table
eval ALTER TABLE $table AUTO_INCREMENT = 180, ALGORITHM = $algorithm;
--echo # We expect the counter to be 180
eval SHOW CREATE TABLE $table;

--echo # This should reset the autoinc counter to the next value of
--echo # current max counter in the table, since the specified value
--echo # is smaller than the existing biggest value(50 < 123)
eval ALTER TABLE $table DROP COLUMN b, AUTO_INCREMENT = 50, ALGORITHM = $algorithm;
--echo # We expect the counter to be 123
eval SHOW CREATE TABLE $table;

eval INSERT INTO $table VALUES(0), (0);

eval SELECT MAX(a) AS `Expect 124` FROM $table;

eval OPTIMIZE TABLE $table;

eval SHOW CREATE TABLE $table;

--source include/restart_mysqld.inc

--echo # We expect the counter to still be 125
eval SHOW CREATE TABLE $table;

eval DELETE FROM $table WHERE a >= 123;

eval CREATE UNIQUE INDEX idx_aa ON $table(a);

--source include/restart_mysqld.inc

eval INSERT INTO $table VALUES(0), (0);

eval SELECT MAX(a) AS `Expect 126` FROM $table;

eval DROP TABLE $table;
Loading

0 comments on commit dcb8792

Please sign in to comment.