1
0
mirror of https://github.com/MariaDB/server.git synced 2025-09-09 18:40:27 +03:00
Files
mariadb/mysql-test/suite/innodb/t/autoinc_persist.test
Marko Mäkelä 3cef4f8f0f MDEV-515 Reduce InnoDB undo logging for insert into empty table
We implement an idea that was suggested by Michael 'Monty' Widenius
in October 2017: When InnoDB is inserting into an empty table or partition,
we can write a single undo log record TRX_UNDO_EMPTY, which will cause
ROLLBACK to clear the table.

For this to work, the insert into an empty table or partition must be
covered by an exclusive table lock that will be held until the transaction
has been committed or rolled back, or the INSERT operation has been
rolled back (and the table is empty again), in lock_table_x_unlock().

Clustered index records that are covered by the TRX_UNDO_EMPTY record
will carry DB_TRX_ID=0 and DB_ROLL_PTR=1<<55, and thus they cannot
be distinguished from what MDEV-12288 leaves behind after purging the
history of row-logged operations.

Concurrent non-locking reads must be adjusted: If the read view was
created before the INSERT into an empty table, then we must continue
to imagine that the table is empty, and not try to read any records.
If the read view was created after the INSERT was committed, then
all records must be visible normally. To implement this, we introduce
the field dict_table_t::bulk_trx_id.

This special handling only applies to the very first INSERT statement
of a transaction for the empty table or partition. If a subsequent
statement in the transaction is modifying the initially empty table again,
we must enable row-level undo logging, so that we will be able to
roll back to the start of the statement in case of an error (such as
duplicate key).

INSERT IGNORE will continue to use row-level logging and locking, because
implementing it would require the ability to roll back the latest row.
Since the undo log that we write only allows us to roll back the entire
statement, we cannot support INSERT IGNORE. We will introduce a
handler::extra() parameter HA_EXTRA_IGNORE_INSERT to indicate to storage
engines that INSERT IGNORE is being executed.

In many test cases, we add an extra record to the table, so that during
the 'interesting' part of the test, row-level locking and logging will
be used.

Replicas will continue to use row-level logging and locking until
MDEV-24622 has been addressed. Likewise, this optimization will be
disabled in Galera cluster until MDEV-24623 enables it.

dict_table_t::bulk_trx_id: The latest active or committed transaction
that initiated an insert into an empty table or partition.
Protected by exclusive table lock and a clustered index leaf page latch.

ins_node_t::bulk_insert: Whether bulk insert was initiated.

trx_t::mod_tables: Use C++11 style accessors (emplace instead of insert).
Unlike earlier, this collection will cover also temporary tables.

trx_mod_table_time_t: Add start_bulk_insert(), end_bulk_insert(),
is_bulk_insert(), was_bulk_insert().

trx_undo_report_row_operation(): Before accessing any undo log pages,
invoke trx->mod_tables.emplace() in order to determine whether undo
logging was disabled, or whether this is the first INSERT and we are
supposed to write a TRX_UNDO_EMPTY record.

row_ins_clust_index_entry_low(): If we are inserting into an empty
clustered index leaf page, set the ins_node_t::bulk_insert flag for
the subsequent trx_undo_report_row_operation() call.

lock_rec_insert_check_and_lock(), lock_prdt_insert_check_and_lock():
Remove the redundant parameter 'flags' that can be checked in the caller.

btr_cur_ins_lock_and_undo(): Simplify the logic. Correctly write
DB_TRX_ID,DB_ROLL_PTR after invoking trx_undo_report_row_operation().

trx_mark_sql_stat_end(), ha_innobase::extra(HA_EXTRA_IGNORE_INSERT),
ha_innobase::external_lock(): Invoke trx_t::end_bulk_insert() so that
the next statement will not be covered by table-level undo logging.

ReadView::changes_visible(trx_id_t) const: New accessor for the case
where the trx_id_t is not read from a potentially corrupted index page
but directly from the memory. In this case, we can skip a sanity check.

row_sel(), row_sel_try_search_shortcut(), row_search_mvcc():
row_sel_try_search_shortcut_for_mysql(),
row_merge_read_clustered_index(): Check dict_table_t::bulk_trx_id.

row_sel_clust_sees(): Replaces lock_clust_rec_cons_read_sees().

lock_sec_rec_cons_read_sees(): Replaced with lower-level code.

btr_root_page_init(): Refactored from btr_create().

dict_index_t::clear(), dict_table_t::clear(): Empty an index or table,
for the ROLLBACK of an INSERT operation.

ROW_T_EMPTY, ROW_OP_EMPTY: Note a concurrent ROLLBACK of an INSERT
into an empty table.

This is joint work with Thirunarayanan Balathandayuthapani,
who created a working prototype.
Thanks to Matthias Leich for extensive testing.
2021-01-25 18:41:27 +02:00

559 lines
17 KiB
Plaintext

--source include/have_innodb.inc
# Restarting is not supported when testing the embedded server.
--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;
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;
--echo # Scenario 1: Normal restart, to test if the counters are persisted
--echo # Scenario 2: Delete some values, to test the counters should not be the
--echo # one which is the largest in current table
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;
CREATE TABLE t13(a INT AUTO_INCREMENT PRIMARY KEY) ENGINE = InnoDB,
AUTO_INCREMENT = 1234;
--source include/restart_mysqld.inc
SHOW CREATE TABLE t13;
INSERT INTO t13 VALUES(0);
SELECT a AS `Expect 1234` FROM t13;
DROP TABLE t13;
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;
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;
--echo # Ensure that all changes before the server is killed are persisted.
set global innodb_flush_log_at_trx_commit=1;
INSERT INTO t9 VALUES(100000000200);
DELETE FROM t9 WHERE a = 100000000200;
--let $shutdown_timeout=0
--source include/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;
--echo # Ensure that all changes before the server is killed are persisted.
set global innodb_flush_log_at_trx_commit=1;
TRUNCATE TABLE t1;
TRUNCATE TABLE t3;
TRUNCATE TABLE t5;
TRUNCATE TABLE t7;
TRUNCATE TABLE t9;
--echo # Scenario 7: Test explicit rename table won't change the counter
RENAME TABLE t9 to t19;
INSERT INTO t19 VALUES(0), (0);
SELECT * FROM t19;
--source include/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 t19 VALUES(0), (0);
SELECT * FROM t19;
DELETE FROM t19 WHERE a = 4;
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;
--echo # MDEV-6076: Test root page split and page_create_empty()
CREATE TABLE mdev6076empty (b SERIAL, pad CHAR(255) NOT NULL DEFAULT '')
ENGINE=InnoDB;
BEGIN;
--echo # Insert records in descending order of AUTO_INCREMENT,
--echo # causing a page split on the very last insert.
--echo # Without the fix in btr_page_empty() this would lose the counter value.
--echo # Without the fix in page_create_empty() the counter value would be lost
--echo # when ROLLBACK deletes the last row.
--disable_query_log
let $i= 55;
while ($i) {
eval INSERT INTO mdev6076empty SET b=$i;
dec $i;
}
--enable_query_log
ROLLBACK;
--source include/restart_mysqld.inc
INSERT INTO t3 VALUES(0);
SELECT MAX(a) AS `Expect 120` FROM t3;
INSERT INTO mdev6076a SET b=NULL;
SELECT * FROM mdev6076a;
INSERT INTO mdev6076b SET b=NULL;
SELECT * FROM mdev6076b;
# MDEV-515 resets the PAGE_ROOT_AUTOINC field in
# root page during rollback.
--disable_query_log
BEGIN;
let $i = 55;
WHILE ($i) {
eval INSERT INTO mdev6076empty SET b=$i;
dec $i;
}
ROLLBACK;
--enable_query_log
INSERT INTO mdev6076empty SET b=NULL;
SELECT * FROM mdev6076empty;
DROP TABLE mdev6076a, mdev6076b, mdev6076empty;
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;
--echo # Ensure that all changes before the server is killed are persisted.
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;
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);
--echo # Ensure that all changes before the server is killed are persisted.
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;
--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/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;
SELECT MAX(a) AS `Expect 2` FROM t32;
INSERT INTO t32 VALUES(0), (0);
SELECT MAX(a) AS `Expect 6` FROM t32;
FLUSH TABLES t33 FOR EXPORT;
let MYSQLD_DATADIR=`select @@datadir`;
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_backup_tablespaces("test", "t33");
EOF
UNLOCK TABLES;
DROP TABLE t33;
CREATE TABLE t33 (
a BIGINT NOT NULL PRIMARY KEY,
b BIGINT NOT NULL AUTO_INCREMENT,
KEY(b)) ENGINE = InnoDB;
ALTER TABLE t33 DISCARD TABLESPACE;
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_discard_tablespaces("test", "t33");
ib_restore_tablespaces("test", "t33");
EOF
ALTER TABLE t33 IMPORT TABLESPACE;
INSERT INTO t33 VALUES(3, NULL);
SELECT MAX(b) AS `Expect 4` FROM t33;
SELECT * FROM t33;
DROP TABLE t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t30, t32, t33;