Browse Source
MDEV-6076 Persistent AUTO_INCREMENT for InnoDB
MDEV-6076 Persistent AUTO_INCREMENT for InnoDB
This should be functionally equivalent to WL#6204 in MySQL 8.0.0, with the notable difference that the file format changes are limited to repurposing a previously unused data field in B-tree pages. For persistent InnoDB tables, write the last used AUTO_INCREMENT value to the root page of the clustered index, in the previously unused (0) PAGE_MAX_TRX_ID field, now aliased as PAGE_ROOT_AUTO_INC. Unlike some other previously unused InnoDB data fields, this one was actually always zero-initialized, at least since MySQL 3.23.49. The writes to PAGE_ROOT_AUTO_INC are protected by SX or X latch on the root page. The SX latch will allow concurrent read access to the root page. (The field PAGE_ROOT_AUTO_INC will only be read on the first-time call to ha_innobase::open() from the SQL layer. The PAGE_ROOT_AUTO_INC can only be updated when executing SQL, so read/write races are not possible.) During INSERT, the PAGE_ROOT_AUTO_INC is updated by the low-level function btr_cur_search_to_nth_level(), adding no extra page access. [Adaptive hash index lookup will be disabled during INSERT.] If some rare UPDATE modifies an AUTO_INCREMENT column, the PAGE_ROOT_AUTO_INC will be adjusted in a separate mini-transaction in ha_innobase::update_row(). When a page is reorganized, we have to preserve the PAGE_ROOT_AUTO_INC field. During ALTER TABLE, the initial AUTO_INCREMENT value will be copied from the table. ALGORITHM=COPY and online log apply in LOCK=NONE will update PAGE_ROOT_AUTO_INC in real time. innodb_col_no(): Determine the dict_table_t::cols[] element index corresponding to a Field of a non-virtual column. (The MySQL 5.7 implementation of virtual columns breaks the 1:1 relationship between Field::field_index and dict_table_t::cols[]. Virtual columns are omitted from dict_table_t::cols[]. Therefore, we must translate the field_index of AUTO_INCREMENT columns into an index of dict_table_t::cols[].) Upgrade from old data files: By default, the AUTO_INCREMENT sequence in old data files would appear to be reset, because PAGE_MAX_TRX_ID or PAGE_ROOT_AUTO_INC would contain the value 0 in each clustered index page. In new data files, PAGE_ROOT_AUTO_INC can only be 0 if the table is empty or does not contain any AUTO_INCREMENT column. For backward compatibility, we use the old method of SELECT MAX(auto_increment_column) for initializing the sequence. btr_read_autoinc(): Read the AUTO_INCREMENT sequence from a new-format data file. btr_read_autoinc_with_fallback(): A variant of btr_read_autoinc() that will resort to reading MAX(auto_increment_column) for data files that did not use AUTO_INCREMENT yet. It was manually tested that during the execution of innodb.autoinc_persist the compatibility logic is not activated (for new files, PAGE_ROOT_AUTO_INC is never 0 in nonempty clustered index root pages). initialize_auto_increment(): Replaces ha_innobase::innobase_initialize_autoinc(). This initializes the AUTO_INCREMENT metadata. Only called from ha_innobase::open(). ha_innobase::info_low(): Do not try to lazily initialize dict_table_t::autoinc. It must already have been initialized by ha_innobase::open() or ha_innobase::create(). Note: The adjustments to class ha_innopart were not tested, because the source code (native InnoDB partitioning) is not being compiled.pull/1523/head
38 changed files with 2531 additions and 716 deletions
-
19mysql-test/include/kill_and_restart_mysqld.inc
-
61mysql-test/suite/innodb/include/autoinc_persist_alter.inc
-
1131mysql-test/suite/innodb/r/autoinc_persist.result
-
11mysql-test/suite/innodb/r/innodb-autoinc-44030.result
-
8mysql-test/suite/innodb/r/innodb.result
-
533mysql-test/suite/innodb/t/autoinc_persist.test
-
3mysql-test/suite/innodb/t/innodb-autoinc-44030-master.opt
-
19mysql-test/suite/innodb/t/innodb-autoinc-44030.test
-
9mysql-test/suite/innodb/t/innodb.test
-
12mysql-test/suite/parts/r/partition_auto_increment_innodb.result
-
149storage/innobase/btr/btr0btr.cc
-
50storage/innobase/btr/btr0cur.cc
-
3storage/innobase/btr/btr0pcur.cc
-
93storage/innobase/dict/dict0dict.cc
-
6storage/innobase/dict/dict0mem.cc
-
332storage/innobase/handler/ha_innodb.cc
-
8storage/innobase/handler/ha_innodb.h
-
99storage/innobase/handler/ha_innopart.cc
-
13storage/innobase/handler/ha_innopart.h
-
174storage/innobase/handler/handler0alter.cc
-
30storage/innobase/include/btr0btr.h
-
5storage/innobase/include/btr0cur.h
-
4storage/innobase/include/btr0pcur.h
-
4storage/innobase/include/btr0pcur.ic
-
97storage/innobase/include/dict0dict.h
-
36storage/innobase/include/dict0dict.ic
-
5storage/innobase/include/dict0mem.h
-
37storage/innobase/include/page0page.h
-
12storage/innobase/include/page0page.ic
-
17storage/innobase/include/row0row.h
-
49storage/innobase/include/row0row.ic
-
15storage/innobase/include/row0sel.h
-
34storage/innobase/page/page0page.cc
-
26storage/innobase/page/page0zip.cc
-
19storage/innobase/row/row0import.cc
-
39storage/innobase/row/row0ins.cc
-
12storage/innobase/row/row0mysql.cc
-
73storage/innobase/row/row0sel.cc
@ -0,0 +1,19 @@ |
|||||
|
--let $_server_id= `SELECT @@server_id` |
||||
|
--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect |
||||
|
|
||||
|
if ($restart_parameters) |
||||
|
{ |
||||
|
--echo # Kill and restart: $restart_parameters |
||||
|
--exec echo "restart: $restart_parameters" > $_expect_file_name |
||||
|
} |
||||
|
if (!$restart_parameters) |
||||
|
{ |
||||
|
--echo # Kill and restart |
||||
|
--exec echo "restart" > $_expect_file_name |
||||
|
} |
||||
|
|
||||
|
--shutdown_server 0 |
||||
|
--source include/wait_until_disconnected.inc |
||||
|
--enable_reconnect |
||||
|
--source include/wait_until_connected_again.inc |
||||
|
--disable_reconnect |
||||
@ -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; |
||||
1131
mysql-test/suite/innodb/r/autoinc_persist.result
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,533 @@ |
|||||
|
--source include/have_innodb.inc |
||||
|
--source include/not_embedded.inc |
||||
|
|
||||
|
--echo # |
||||
|
--echo # MDEV-6076 Persistent AUTO_INCREMENT for InnoDB |
||||
|
--echo # |
||||
|
--echo # WL#6204 InnoDB persistent max value for autoinc columns |
||||
|
--echo # |
||||
|
--echo # Most of this test case is copied from the test innodb.autoinc_persist |
||||
|
--echo # that was introduced in MySQL 8.0.0. The observable behaviour |
||||
|
--echo # of MDEV-6076 is equivalent to WL#6204, with the exception that |
||||
|
--echo # there is less buffering taking place and redo log checkpoints |
||||
|
--echo # are not being treated specially. |
||||
|
--echo # Due to less buffering, there is no debug instrumentation testing |
||||
|
--echo # for MDEV-6076. |
||||
|
--echo # |
||||
|
|
||||
|
--echo # Pre-create several tables |
||||
|
|
||||
|
SET SQL_MODE='STRICT_ALL_TABLES'; |
||||
|
|
||||
|
CREATE TABLE t1(a TINYINT AUTO_INCREMENT KEY) ENGINE = InnoDB; |
||||
|
INSERT INTO t1 VALUES(0), (0), (0), (0), (-1), (-10), (0), |
||||
|
(20), (30), (31); |
||||
|
SELECT * FROM t1; |
||||
|
|
||||
|
CREATE TABLE t2(a TINYINT UNSIGNED AUTO_INCREMENT KEY) ENGINE = InnoDB; |
||||
|
--error ER_WARN_DATA_OUT_OF_RANGE |
||||
|
INSERT INTO t2 VALUES(-5); |
||||
|
INSERT INTO t2 VALUES(0), (0), (0), (0), (8), (10), (0), |
||||
|
(20), (30), (31); |
||||
|
SELECT * FROM t2; |
||||
|
|
||||
|
CREATE TABLE t3(a SMALLINT AUTO_INCREMENT KEY) ENGINE = InnoDB; |
||||
|
INSERT INTO t3 VALUES(0), (0), (0), (0), (-1), (-10), (0), |
||||
|
(20), (30), (31), (1024), (4096); |
||||
|
SELECT * FROM t3; |
||||
|
|
||||
|
CREATE TABLE t4(a SMALLINT UNSIGNED AUTO_INCREMENT KEY) ENGINE = InnoDB; |
||||
|
--error ER_WARN_DATA_OUT_OF_RANGE |
||||
|
INSERT INTO t4 VALUES(-5); |
||||
|
INSERT INTO t4 VALUES(0), (0), (0), (0), (8), (10), (0), |
||||
|
(20), (30), (31), (1024), (4096); |
||||
|
SELECT * FROM t4; |
||||
|
|
||||
|
CREATE TABLE t5(a MEDIUMINT AUTO_INCREMENT KEY) ENGINE = InnoDB; |
||||
|
INSERT INTO t5 VALUES(0), (0), (0), (0), (-1), (-10), (0), |
||||
|
(20), (30), (31), (1000000), (1000005); |
||||
|
SELECT * FROM t5; |
||||
|
|
||||
|
CREATE TABLE t6(a MEDIUMINT UNSIGNED AUTO_INCREMENT KEY) ENGINE = InnoDB; |
||||
|
--error ER_WARN_DATA_OUT_OF_RANGE |
||||
|
INSERT INTO t6 VALUES(-5); |
||||
|
INSERT INTO t6 VALUES(0), (0), (0), (0), (8), (10), (0), |
||||
|
(20), (30), (31), (1000000), (1000005); |
||||
|
SELECT * FROM t6; |
||||
|
|
||||
|
CREATE TABLE t7(a INT AUTO_INCREMENT KEY) ENGINE = InnoDB; |
||||
|
INSERT INTO t7 VALUES(0), (0), (0), (0), (-1), (-10), (0), |
||||
|
(20), (30), (31), (100000000), (100000008); |
||||
|
SELECT * FROM t7; |
||||
|
|
||||
|
CREATE TABLE t8(a INT UNSIGNED AUTO_INCREMENT KEY) ENGINE = InnoDB; |
||||
|
--error ER_WARN_DATA_OUT_OF_RANGE |
||||
|
INSERT INTO t8 VALUES(-5); |
||||
|
INSERT INTO t8 VALUES(0), (0), (0), (0), (8), (10), (0), |
||||
|
(20), (30), (31), (100000000), (100000008); |
||||
|
SELECT * FROM t8; |
||||
|
|
||||
|
CREATE TABLE t9(a BIGINT AUTO_INCREMENT KEY) ENGINE = InnoDB; |
||||
|
INSERT INTO t9 VALUES(0), (0), (0), (0), (-1), (-10), (0), |
||||
|
(20), (30), (31), (100000000000), (100000000006); |
||||
|
SELECT * FROM t9; |
||||
|
|
||||
|
CREATE TABLE t10(a BIGINT UNSIGNED AUTO_INCREMENT KEY) ENGINE = InnoDB; |
||||
|
--error ER_WARN_DATA_OUT_OF_RANGE |
||||
|
INSERT INTO t10 VALUES(-5); |
||||
|
INSERT INTO t10 VALUES(0), (0), (0), (0), (8), (10), (0), |
||||
|
(20), (30), (31), (100000000000), (100000000006); |
||||
|
SELECT * FROM t10; |
||||
|
|
||||
|
CREATE TABLE t11(a FLOAT AUTO_INCREMENT KEY) ENGINE = InnoDB; |
||||
|
INSERT INTO t11 VALUES(0), (0), (0), (0), (-1), (-10), (0), |
||||
|
(20), (30), (31); |
||||
|
SELECT * FROM t11; |
||||
|
|
||||
|
# Since autoinc counter is persisted by redo logs, we don't want to |
||||
|
# lose them on kill and restart, so to make the result after restart stable. |
||||
|
set global innodb_flush_log_at_trx_commit=1; |
||||
|
|
||||
|
CREATE TABLE t12(a DOUBLE AUTO_INCREMENT KEY) ENGINE = InnoDB; |
||||
|
INSERT INTO t12 VALUES(0), (0), (0), (0), (-1), (-10), (0), |
||||
|
(20), (30), (31); |
||||
|
SELECT * FROM t12; |
||||
|
|
||||
|
CREATE TABLE t13(a INT AUTO_INCREMENT PRIMARY KEY) ENGINE = InnoDB, |
||||
|
AUTO_INCREMENT = 1234; |
||||
|
|
||||
|
--echo # Scenario 1: Normal restart, to test if the counters are persisted |
||||
|
--source include/restart_mysqld.inc |
||||
|
|
||||
|
--echo # We expect these results should be equal to above SELECTs |
||||
|
SELECT * FROM t1; |
||||
|
SELECT * FROM t2; |
||||
|
SELECT * FROM t3; |
||||
|
SELECT * FROM t4; |
||||
|
SELECT * FROM t5; |
||||
|
SELECT * FROM t6; |
||||
|
SELECT * FROM t7; |
||||
|
SELECT * FROM t8; |
||||
|
SELECT * FROM t9; |
||||
|
SELECT * FROM t10; |
||||
|
SELECT * FROM t11; |
||||
|
SELECT * FROM t12; |
||||
|
|
||||
|
SELECT * FROM t13; |
||||
|
SHOW CREATE TABLE t13; |
||||
|
INSERT INTO t13 VALUES(0); |
||||
|
SELECT a AS `Expect 1234` FROM t13; |
||||
|
|
||||
|
--echo # Scenario 2: Delete some values, to test the counters should not be the |
||||
|
--echo # one which is the largest in current table |
||||
|
|
||||
|
set global innodb_flush_log_at_trx_commit=1; |
||||
|
|
||||
|
DELETE FROM t1 WHERE a > 30; |
||||
|
SELECT MAX(a) AS `Expect 30` FROM t1; |
||||
|
DELETE FROM t3 WHERE a > 2000; |
||||
|
SELECT MAX(a) AS `Expect 2000` FROM t3; |
||||
|
DELETE FROM t5 WHERE a > 1000000; |
||||
|
SELECT MAX(a) AS `Expect 1000000` FROM t5; |
||||
|
DELETE FROM t7 WHERE a > 100000000; |
||||
|
SELECT MAX(a) AS `Expect 100000000` FROM t7; |
||||
|
DELETE FROM t9 WHERE a > 100000000000; |
||||
|
SELECT MAX(a) AS `Expect 100000000000` FROM t9; |
||||
|
|
||||
|
--source include/restart_mysqld.inc |
||||
|
|
||||
|
INSERT INTO t1 VALUES(0), (0); |
||||
|
SELECT MAX(a) AS `Expect 33` FROM t1; |
||||
|
INSERT INTO t3 VALUES(0), (0); |
||||
|
SELECT MAX(a) AS `Expect 4098` FROM t3; |
||||
|
INSERT INTO t5 VALUES(0), (0); |
||||
|
SELECT MAX(a) AS `Expect 1000007` FROM t5; |
||||
|
INSERT INTO t7 VALUES(0), (0); |
||||
|
SELECT MAX(a) AS `Expect 100000010` FROM t7; |
||||
|
INSERT INTO t9 VALUES(0), (0); |
||||
|
SELECT MAX(a) AS `Expect 100000000008` FROM t9; |
||||
|
|
||||
|
--echo # Scenario 3: Insert some bigger counters, the next counter should start |
||||
|
--echo # from there |
||||
|
|
||||
|
INSERT INTO t1 VALUES(40), (0); |
||||
|
INSERT INTO t1 VALUES(42), (0); |
||||
|
SELECT a AS `Expect 43, 42` FROM t1 ORDER BY a DESC LIMIT 4; |
||||
|
INSERT INTO t3 VALUES(5000), (0); |
||||
|
INSERT INTO t3 VALUES(5010), (0); |
||||
|
SELECT a AS `Expect 5011, 5010` FROM t3 ORDER BY a DESC LIMIT 4; |
||||
|
INSERT INTO t5 VALUES(1000010), (0); |
||||
|
INSERT INTO t5 VALUES(1000020), (0); |
||||
|
SELECT a AS `Expect 1000021, 1000020` FROM t5 ORDER BY a DESC LIMIT 4; |
||||
|
INSERT INTO t7 VALUES(100000020), (0); |
||||
|
INSERT INTO t7 VALUES(100000030), (0); |
||||
|
SELECT a AS `Expect 100000031, 100000030` FROM t7 ORDER BY a DESC LIMIT 4; |
||||
|
INSERT INTO t9 VALUES(100000000010), (0); |
||||
|
INSERT INTO t9 VALUES(100000000020), (0); |
||||
|
SELECT a AS `Expect 100000000021, 100000000020` FROM t9 ORDER BY a DESC LIMIT 4; |
||||
|
|
||||
|
--echo # Scenario 4: Update some values, to test the counters should be updated |
||||
|
--echo # to the bigger value, but not smaller value. |
||||
|
|
||||
|
INSERT INTO t1 VALUES(50), (55); |
||||
|
# Updating to bigger value will update the auto-increment counter |
||||
|
UPDATE t1 SET a = 105 WHERE a = 5; |
||||
|
# Updating to smaller value will not update the counter |
||||
|
UPDATE t1 SET a = 100 WHERE a = 55; |
||||
|
--echo # This should insert 102, 106, 107, and make next counter 109. |
||||
|
INSERT INTO t1 VALUES(102), (0), (0); |
||||
|
SELECT a AS `Expect 107, 106` FROM t1 ORDER BY a DESC LIMIT 2; |
||||
|
DELETE FROM t1 WHERE a > 105; |
||||
|
INSERT INTO t1 VALUES(0); |
||||
|
SELECT MAX(a) AS `Expect 109` FROM t1; |
||||
|
|
||||
|
--echo # Test the same things on t3, t5, t7, t9, to test if DDTableBuffer would |
||||
|
--echo # be updated accordingly |
||||
|
|
||||
|
INSERT INTO t3 VALUES(60), (65); |
||||
|
# Updating to bigger value will update the auto-increment counter |
||||
|
UPDATE t3 SET a = 6005 WHERE a = 5; |
||||
|
# Updating to smaller value will not update the counter |
||||
|
UPDATE t3 SET a = 6000 WHERE a = 60; |
||||
|
--echo # This should insert 6002, 6006, 6007, and make next counter 6009. |
||||
|
INSERT INTO t3 VALUES(6002), (0), (0); |
||||
|
SELECT a AS `Expect 6007, 6006` FROM t3 ORDER BY a DESC LIMIT 2; |
||||
|
DELETE FROM t3 WHERE a > 6005; |
||||
|
INSERT INTO t3 VALUES(0); |
||||
|
SELECT MAX(a) AS `Expect 6009` FROM t3; |
||||
|
|
||||
|
INSERT INTO t5 VALUES(100), (200); |
||||
|
# Updating to bigger value will update the auto-increment counter |
||||
|
UPDATE t5 SET a = 1000105 WHERE a = 5; |
||||
|
# Updating to smaller value will not update the counter |
||||
|
UPDATE t5 SET a = 1000100 WHERE a = 100; |
||||
|
--echo # This should insert 1000102, 1000106, 1000107, and make next counter |
||||
|
--echo # 1000109. |
||||
|
INSERT INTO t5 VALUES(1000102), (0), (0); |
||||
|
SELECT a AS `Expect 1000107, 1000106` FROM t5 ORDER BY a DESC LIMIT 2; |
||||
|
DELETE FROM t5 WHERE a > 1000105; |
||||
|
INSERT INTO t5 VALUES(0); |
||||
|
SELECT MAX(a) AS `Expect 1000109` FROM t5; |
||||
|
|
||||
|
INSERT INTO t7 VALUES(100), (200); |
||||
|
# Updating to bigger value will update the auto-increment counter |
||||
|
UPDATE t7 SET a = 100000105 WHERE a = 5; |
||||
|
# Updating to smaller value will not update the counter |
||||
|
UPDATE t7 SET a = 100000100 WHERE a = 100; |
||||
|
--echo # This should insert 100000102, 1100000106, 100000107, and make next |
||||
|
--echo # counter 100000109. |
||||
|
INSERT INTO t7 VALUES(100000102), (0), (0); |
||||
|
SELECT a AS `Expect 100000107, 100000106` FROM t7 ORDER BY a DESC LIMIT 2; |
||||
|
DELETE FROM t7 WHERE a > 100000105; |
||||
|
INSERT INTO t7 VALUES(0); |
||||
|
SELECT MAX(a) AS `Expect 100000109` FROM t7; |
||||
|
|
||||
|
set global innodb_flush_log_at_trx_commit=1; |
||||
|
|
||||
|
INSERT INTO t9 VALUES(100), (200); |
||||
|
# Updating to bigger value will update the auto-increment counter |
||||
|
UPDATE t9 SET a = 100000000105 WHERE a = 5; |
||||
|
# Updating to smaller value will not update the counter |
||||
|
UPDATE t9 SET a = 100000000100 WHERE a = 100; |
||||
|
--echo # This should insert 100000000102, 100000000106, 100000000107, and make |
||||
|
--echo # next counter 100000000109. |
||||
|
INSERT INTO t9 VALUES(100000000102), (0), (0); |
||||
|
SELECT a AS `Expect 100000000107, 100000000106` FROM t9 ORDER BY a DESC LIMIT 2; |
||||
|
DELETE FROM t9 WHERE a > 100000000105; |
||||
|
INSERT INTO t9 VALUES(0); |
||||
|
SELECT MAX(a) AS `Expect 100000000109` FROM t9; |
||||
|
|
||||
|
--source include/restart_mysqld.inc |
||||
|
|
||||
|
INSERT INTO t1 VALUES(0), (0); |
||||
|
SELECT a AS `Expect 110, 111` FROM t1 ORDER BY a DESC LIMIT 2; |
||||
|
|
||||
|
INSERT INTO t3 VALUES(0), (0); |
||||
|
SELECT a AS `Expect 6010, 6011` FROM t3 ORDER BY a DESC LIMIT 2; |
||||
|
|
||||
|
INSERT INTO t5 VALUES(0), (0); |
||||
|
SELECT a AS `Expect 1100111, 1100110` FROM t5 ORDER BY a DESC LIMIT 2; |
||||
|
|
||||
|
INSERT INTO t7 VALUES(0), (0); |
||||
|
SELECT a AS `Expect 100000111, 100000110` FROM t7 ORDER BY a DESC LIMIT 2; |
||||
|
|
||||
|
INSERT INTO t9 VALUES(0), (0); |
||||
|
SELECT a AS `Expect 100000000111, 100000000110` FROM t9 ORDER BY a DESC LIMIT 2; |
||||
|
|
||||
|
--echo # Scenario 5: Test kill the server |
||||
|
|
||||
|
INSERT INTO t1 VALUES(125); |
||||
|
DELETE FROM t1 WHERE a = 125; |
||||
|
|
||||
|
INSERT INTO t3 VALUES(6100); |
||||
|
DELETE FROM t3 WHERE a = 6100; |
||||
|
|
||||
|
INSERT INTO t5 VALUES(1100200); |
||||
|
DELETE FROM t5 WHERE a = 1100200; |
||||
|
|
||||
|
INSERT INTO t7 VALUES(100000200); |
||||
|
DELETE FROM t7 WHERE a = 100000200; |
||||
|
|
||||
|
set global innodb_flush_log_at_trx_commit=1; |
||||
|
|
||||
|
INSERT INTO t9 VALUES(100000000200); |
||||
|
DELETE FROM t9 WHERE a = 100000000200; |
||||
|
|
||||
|
--source include/kill_and_restart_mysqld.inc |
||||
|
|
||||
|
INSERT INTO t1 VALUES(0); |
||||
|
SELECT a AS `Expect 126` FROM t1 ORDER BY a DESC LIMIT 1; |
||||
|
|
||||
|
INSERT INTO t3 VALUES(0); |
||||
|
SELECT a AS `Expect 6101` FROM t3 ORDER BY a DESC LIMIT 1; |
||||
|
|
||||
|
INSERT INTO t5 VALUES(0); |
||||
|
SELECT a AS `Expect 1100201` FROM t5 ORDER BY a DESC LIMIT 1; |
||||
|
|
||||
|
INSERT INTO t7 VALUES(0); |
||||
|
SELECT a AS `Expect 100000201` FROM t7 ORDER BY a DESC LIMIT 1; |
||||
|
|
||||
|
INSERT INTO t9 VALUES(0); |
||||
|
SELECT a AS `Expect 100000000201` FROM t9 ORDER BY a DESC LIMIT 1; |
||||
|
|
||||
|
--echo # Scenario 6: Test truncate will reset the counters to 0 |
||||
|
|
||||
|
TRUNCATE TABLE t1; |
||||
|
TRUNCATE TABLE t3; |
||||
|
TRUNCATE TABLE t5; |
||||
|
TRUNCATE TABLE t7; |
||||
|
TRUNCATE TABLE t9; |
||||
|
|
||||
|
INSERT INTO t1 VALUES(0), (0); |
||||
|
SELECT * FROM t1; |
||||
|
|
||||
|
INSERT INTO t3 VALUES(0), (0); |
||||
|
SELECT * FROM t3; |
||||
|
|
||||
|
INSERT INTO t5 VALUES(0), (0); |
||||
|
SELECT * FROM t5; |
||||
|
|
||||
|
INSERT INTO t7 VALUES(0), (0); |
||||
|
SELECT * FROM t7; |
||||
|
|
||||
|
INSERT INTO t9 VALUES(0), (0); |
||||
|
SELECT * FROM t9; |
||||
|
|
||||
|
set global innodb_flush_log_at_trx_commit=1; |
||||
|
|
||||
|
TRUNCATE TABLE t1; |
||||
|
TRUNCATE TABLE t3; |
||||
|
TRUNCATE TABLE t5; |
||||
|
TRUNCATE TABLE t7; |
||||
|
TRUNCATE TABLE t9; |
||||
|
|
||||
|
--source include/kill_and_restart_mysqld.inc |
||||
|
|
||||
|
INSERT INTO t1 VALUES(0), (0); |
||||
|
SELECT * FROM t1; |
||||
|
|
||||
|
INSERT INTO t3 VALUES(0), (0); |
||||
|
SELECT * FROM t3; |
||||
|
|
||||
|
INSERT INTO t5 VALUES(0), (0); |
||||
|
SELECT * FROM t5; |
||||
|
|
||||
|
INSERT INTO t7 VALUES(0), (0); |
||||
|
SELECT * FROM t7; |
||||
|
|
||||
|
INSERT INTO t9 VALUES(0), (0); |
||||
|
SELECT * FROM t9; |
||||
|
|
||||
|
--echo # Scenario 7: Test explicit rename table won't change the counter |
||||
|
|
||||
|
set global innodb_flush_log_at_trx_commit=1; |
||||
|
|
||||
|
RENAME TABLE t9 to t19; |
||||
|
INSERT INTO t19 VALUES(0), (0); |
||||
|
SELECT * FROM t19; |
||||
|
DELETE FROM t19 WHERE a = 4; |
||||
|
|
||||
|
--source include/kill_and_restart_mysqld.inc |
||||
|
|
||||
|
RENAME TABLE t19 to t9; |
||||
|
INSERT INTO t9 VALUES(0), (0); |
||||
|
SELECT * FROM t9; |
||||
|
|
||||
|
TRUNCATE TABLE t9; |
||||
|
|
||||
|
INSERT INTO t9 VALUES(0), (0); |
||||
|
SELECT * FROM t9; |
||||
|
|
||||
|
--echo # Scenario 8: Test ALTER TABLE operations |
||||
|
|
||||
|
INSERT INTO t3 VALUES(0), (0), (100), (200), (1000); |
||||
|
SELECT * FROM t3; |
||||
|
DELETE FROM t3 WHERE a > 300; |
||||
|
SELECT MAX(a) AS `Expect 200` FROM t3; |
||||
|
--echo # This will not change the counter to 150, but to 201, which is the next |
||||
|
--echo # of current max counter in the table |
||||
|
ALTER TABLE t3 AUTO_INCREMENT = 150; |
||||
|
SHOW CREATE TABLE t3; |
||||
|
INSERT INTO t3 VALUES(0); |
||||
|
SELECT MAX(a) AS `Expect 201` FROM t3; |
||||
|
--echo # This will change the counter to 500, which is bigger than any counter |
||||
|
--echo # in the table |
||||
|
ALTER TABLE t3 AUTO_INCREMENT = 500; |
||||
|
SHOW CREATE TABLE t3; |
||||
|
INSERT INTO t3 VALUES(0); |
||||
|
SELECT MAX(a) AS `Expect 500` FROM t3; |
||||
|
|
||||
|
TRUNCATE TABLE t3; |
||||
|
ALTER TABLE t3 AUTO_INCREMENT = 100; |
||||
|
SHOW CREATE TABLE t3; |
||||
|
INSERT INTO t3 VALUES(0), (0); |
||||
|
SELECT * FROM t3; |
||||
|
|
||||
|
INSERT INTO t3 VALUES(150), (180); |
||||
|
UPDATE t3 SET a = 200 WHERE a = 150; |
||||
|
INSERT INTO t3 VALUES(220); |
||||
|
--echo # This still fails to set to 120, but just 221 |
||||
|
ALTER TABLE t3 AUTO_INCREMENT = 120; |
||||
|
SHOW CREATE TABLE t3; |
||||
|
INSERT INTO t3 VALUES(0); |
||||
|
SELECT MAX(a) AS `Expect 221` FROM t3; |
||||
|
|
||||
|
DELETE FROM t3 WHERE a > 120; |
||||
|
|
||||
|
ALTER TABLE t3 AUTO_INCREMENT = 120; |
||||
|
SHOW CREATE TABLE t3; |
||||
|
|
||||
|
--echo # MDEV-6076: Test adding an AUTO_INCREMENT COLUMN |
||||
|
CREATE TABLE mdev6076a (b INT) ENGINE=InnoDB; |
||||
|
INSERT INTO mdev6076a VALUES(2),(1); |
||||
|
CREATE TABLE mdev6076b (b INT) ENGINE=InnoDB; |
||||
|
INSERT INTO mdev6076b VALUES(2),(1); |
||||
|
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON |
||||
|
ALTER TABLE mdev6076a ADD COLUMN a SERIAL FIRST, LOCK=NONE; |
||||
|
ALTER TABLE mdev6076a ADD COLUMN a SERIAL FIRST, ALGORITHM=INPLACE; |
||||
|
ALTER TABLE mdev6076b ADD COLUMN a SERIAL FIRST, AUTO_INCREMENT=100, |
||||
|
ALGORITHM=INPLACE; |
||||
|
|
||||
|
--source include/kill_and_restart_mysqld.inc |
||||
|
|
||||
|
INSERT INTO t3 VALUES(0); |
||||
|
SELECT MAX(a) AS `Expect 120` FROM t3; |
||||
|
|
||||
|
INSERT INTO mdev6076a SET b=0; |
||||
|
SELECT * FROM mdev6076a; |
||||
|
INSERT INTO mdev6076b SET b=0; |
||||
|
SELECT * FROM mdev6076b; |
||||
|
DROP TABLE mdev6076a, mdev6076b; |
||||
|
|
||||
|
set global innodb_flush_log_at_trx_commit=1; |
||||
|
|
||||
|
INSERT INTO t3 VALUES(0), (0), (200), (210); |
||||
|
|
||||
|
--echo # Test the different algorithms in ALTER TABLE |
||||
|
|
||||
|
--let $template = t3 |
||||
|
--let $algorithm = INPLACE |
||||
|
--let $table = t_inplace |
||||
|
--source suite/innodb/include/autoinc_persist_alter.inc |
||||
|
--let $algorithm = COPY |
||||
|
--let $table = t_copy |
||||
|
--source suite/innodb/include/autoinc_persist_alter.inc |
||||
|
|
||||
|
--echo # Scenario 9: Test the sql_mode = NO_AUTO_VALUE_ON_ZERO |
||||
|
|
||||
|
CREATE TABLE t30 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b INT, key(b)) ENGINE = InnoDB; |
||||
|
|
||||
|
set SQL_MODE = NO_AUTO_VALUE_ON_ZERO; |
||||
|
|
||||
|
INSERT INTO t30 VALUES(NULL, 1), (200, 2), (0, 3); |
||||
|
INSERT INTO t30(b) VALUES(4), (5), (6), (7); |
||||
|
SELECT * FROM t30 ORDER BY b; |
||||
|
ALTER TABLE t30 MODIFY b MEDIUMINT; |
||||
|
SELECT * FROM t30 ORDER BY b; |
||||
|
|
||||
|
set global innodb_flush_log_at_trx_commit=1; |
||||
|
|
||||
|
CREATE TABLE t31 (a INT) ENGINE = InnoDB; |
||||
|
INSERT INTO t31 VALUES(1), (2); |
||||
|
ALTER TABLE t31 ADD b INT AUTO_INCREMENT PRIMARY KEY; |
||||
|
INSERT INTO t31 VALUES(3, 0), (4, NULL), (5, NULL); |
||||
|
--error ER_DUP_ENTRY |
||||
|
INSERT INTO t31 VALUES(6, 0); |
||||
|
SELECT * FROM t31; |
||||
|
|
||||
|
--source include/kill_and_restart_mysqld.inc |
||||
|
|
||||
|
--echo # This will not insert 0 |
||||
|
INSERT INTO t31(a) VALUES(6), (0); |
||||
|
SELECT * FROM t31; |
||||
|
DROP TABLE t31; |
||||
|
|
||||
|
set SQL_MODE = NO_AUTO_VALUE_ON_ZERO; |
||||
|
|
||||
|
DELETE FROM t30 WHERE a = 0; |
||||
|
UPDATE t30 set a = 0 where b = 5; |
||||
|
SELECT * FROM t30 ORDER BY b; |
||||
|
DELETE FROM t30 WHERE a = 0; |
||||
|
|
||||
|
UPDATE t30 SET a = NULL WHERE b = 6; |
||||
|
UPDATE t30 SET a = 300 WHERE b = 7; |
||||
|
|
||||
|
SELECT * FROM t30 ORDER BY b; |
||||
|
|
||||
|
SET SQL_MODE = 0; |
||||
|
|
||||
|
--echo # Scenario 10: Rollback would not rollback the counter |
||||
|
CREATE TABLE t32 ( |
||||
|
a BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB; |
||||
|
|
||||
|
INSERT INTO t32 VALUES(0), (0); |
||||
|
|
||||
|
set global innodb_flush_log_at_trx_commit=1; |
||||
|
|
||||
|
START TRANSACTION; |
||||
|
INSERT INTO t32 VALUES(0), (0); |
||||
|
SELECT MAX(a) AS `Expect 4` FROM t32; |
||||
|
DELETE FROM t32 WHERE a >= 2; |
||||
|
ROLLBACK; |
||||
|
|
||||
|
--source include/kill_and_restart_mysqld.inc |
||||
|
|
||||
|
SELECT MAX(a) AS `Expect 2` FROM t32; |
||||
|
INSERT INTO t32 VALUES(0), (0); |
||||
|
SELECT MAX(a) AS `Expect 6` FROM t32; |
||||
|
|
||||
|
--echo # Scenario 11: Test duplicate primary key/secondary key will not stop |
||||
|
--echo # increasing the counter |
||||
|
|
||||
|
CREATE TABLE t33 ( |
||||
|
a BIGINT NOT NULL PRIMARY KEY, |
||||
|
b BIGINT NOT NULL AUTO_INCREMENT, |
||||
|
KEY(b)) ENGINE = InnoDB; |
||||
|
|
||||
|
INSERT INTO t33 VALUES(1, NULL); |
||||
|
INSERT INTO t33 VALUES(2, NULL); |
||||
|
--error ER_DUP_ENTRY |
||||
|
INSERT INTO t33 VALUES(2, NULL); |
||||
|
|
||||
|
INSERT INTO t33 VALUES(3, NULL); |
||||
|
SELECT MAX(b) AS `Expect 4` FROM t33; |
||||
|
|
||||
|
TRUNCATE TABLE t33; |
||||
|
|
||||
|
INSERT INTO t33 VALUES(1, NULL); |
||||
|
INSERT INTO t33 VALUES(2, NULL); |
||||
|
|
||||
|
set global innodb_flush_log_at_trx_commit=1; |
||||
|
|
||||
|
START TRANSACTION; |
||||
|
UPDATE t33 SET a = 10 WHERE a = 1; |
||||
|
--error ER_DUP_ENTRY |
||||
|
INSERT INTO t33 VALUES(2, NULL); |
||||
|
COMMIT; |
||||
|
|
||||
|
--source include/kill_and_restart_mysqld.inc |
||||
|
|
||||
|
INSERT INTO t33 VALUES(3, NULL); |
||||
|
SELECT MAX(b) AS `Expect 4` FROM t33; |
||||
|
|
||||
|
DROP TABLE t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t30, t32, t33; |
||||
@ -1,3 +0,0 @@ |
|||||
--default-storage-engine=MyISAM |
|
||||
--innodb-strict-mode=0 |
|
||||
--innodb-file-per-table=0 |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue