2017-08-30 13:06:13 +03:00
|
|
|
--source include/innodb_page_size_small.inc
|
2017-09-16 16:55:16 +03:00
|
|
|
--source include/innodb_encrypt_log.inc
|
2017-08-29 15:40:37 +03:00
|
|
|
--source include/have_debug.inc
|
2017-08-29 11:27:28 +03:00
|
|
|
--source include/have_debug_sync.inc
|
|
|
|
|
|
|
|
let $innodb_metrics_select=
|
|
|
|
SELECT name, count FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE subsystem = 'ddl';
|
|
|
|
|
|
|
|
call mtr.add_suppression("InnoDB: Warning: Small buffer pool size");
|
|
|
|
# these will be triggered by DISCARD TABLESPACE
|
|
|
|
call mtr.add_suppression("InnoDB: Error: table 'test/t1'");
|
2021-03-18 13:17:30 +05:30
|
|
|
call mtr.add_suppression("MariaDB is trying to open a table handle but the .ibd file for");
|
2017-08-29 11:27:28 +03:00
|
|
|
|
|
|
|
# DISCARD TABLESPACE needs file-per-table
|
|
|
|
SET @global_innodb_file_per_table_orig = @@global.innodb_file_per_table;
|
|
|
|
SET GLOBAL innodb_file_per_table = on;
|
|
|
|
|
|
|
|
# Save the initial number of concurrent sessions.
|
|
|
|
--source include/count_sessions.inc
|
|
|
|
|
2017-09-16 16:55:16 +03:00
|
|
|
CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 INT NOT NULL, c3 CHAR(255) NOT NULL)
|
2017-08-29 11:27:28 +03:00
|
|
|
ENGINE = InnoDB;
|
|
|
|
INSERT INTO t1 VALUES (1,1,''), (2,2,''), (3,3,''), (4,4,''), (5,5,'');
|
|
|
|
|
|
|
|
SET GLOBAL innodb_monitor_enable = module_ddl;
|
|
|
|
eval $innodb_metrics_select;
|
|
|
|
|
|
|
|
SET DEBUG_SYNC = 'RESET';
|
|
|
|
SET DEBUG_SYNC = 'write_row_noreplace SIGNAL have_handle WAIT_FOR go_ahead';
|
|
|
|
--send
|
|
|
|
INSERT INTO t1 VALUES(1,2,3);
|
|
|
|
|
|
|
|
connect (con1,localhost,root,,);
|
|
|
|
|
|
|
|
# This should block at the end because of the INSERT in connection default
|
|
|
|
# is holding a metadata lock.
|
|
|
|
SET DEBUG_SYNC = 'now WAIT_FOR have_handle';
|
|
|
|
SET lock_wait_timeout = 1;
|
|
|
|
--error ER_LOCK_WAIT_TIMEOUT
|
|
|
|
ALTER TABLE t1 ROW_FORMAT=REDUNDANT;
|
|
|
|
SET DEBUG_SYNC = 'now SIGNAL go_ahead';
|
|
|
|
|
|
|
|
connection default;
|
|
|
|
--error ER_DUP_ENTRY
|
|
|
|
reap;
|
|
|
|
eval $innodb_metrics_select;
|
|
|
|
|
|
|
|
connection con1;
|
2017-08-29 15:40:37 +03:00
|
|
|
SET @saved_debug_dbug = @@SESSION.debug_dbug;
|
|
|
|
SET DEBUG_DBUG = '+d,innodb_OOM_prepare_inplace_alter';
|
2017-08-29 11:27:28 +03:00
|
|
|
--error ER_OUT_OF_RESOURCES
|
|
|
|
ALTER TABLE t1 ROW_FORMAT=REDUNDANT, ALGORITHM=INPLACE, LOCK=NONE;
|
2017-08-29 15:40:37 +03:00
|
|
|
SET SESSION DEBUG = @saved_debug_dbug;
|
2017-08-29 11:27:28 +03:00
|
|
|
SET SESSION DEBUG = '+d,innodb_OOM_inplace_alter';
|
|
|
|
--error ER_OUT_OF_RESOURCES
|
|
|
|
ALTER TABLE t1 ROW_FORMAT=REDUNDANT, ALGORITHM=INPLACE, LOCK=NONE;
|
2017-08-29 15:40:37 +03:00
|
|
|
SET SESSION DEBUG = @saved_debug_dbug;
|
2017-08-29 11:27:28 +03:00
|
|
|
ALTER TABLE t1 ROW_FORMAT=REDUNDANT, ALGORITHM=INPLACE, LOCK=NONE;
|
|
|
|
|
|
|
|
connection default;
|
|
|
|
SHOW CREATE TABLE t1;
|
|
|
|
# Insert a duplicate entry (4) for the upcoming UNIQUE INDEX(c2).
|
|
|
|
BEGIN;
|
|
|
|
INSERT INTO t1 VALUES(7,4,2);
|
|
|
|
|
|
|
|
connection con1;
|
|
|
|
# This DEBUG_SYNC should not kick in yet, because the duplicate key will be
|
|
|
|
# detected before we get a chance to apply the online log.
|
|
|
|
SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL scanned WAIT_FOR insert_done';
|
|
|
|
# This will be a lock wait timeout on the meta-data lock,
|
|
|
|
# because the transaction inserting (7,4,2) is still active.
|
|
|
|
--error ER_LOCK_WAIT_TIMEOUT
|
|
|
|
ALTER TABLE t1 DROP PRIMARY KEY, ADD UNIQUE INDEX(c2);
|
|
|
|
|
|
|
|
connection default;
|
|
|
|
COMMIT;
|
|
|
|
|
|
|
|
connection con1;
|
|
|
|
--error ER_DUP_ENTRY
|
|
|
|
ALTER TABLE t1 DROP PRIMARY KEY, ADD UNIQUE INDEX(c2);
|
|
|
|
|
|
|
|
connection default;
|
|
|
|
DELETE FROM t1 WHERE c1 = 7;
|
|
|
|
|
|
|
|
connection con1;
|
|
|
|
ALTER TABLE t1 DROP PRIMARY KEY, ADD UNIQUE INDEX(c2), ROW_FORMAT=COMPACT,
|
|
|
|
LOCK = SHARED, ALGORITHM = INPLACE;
|
|
|
|
|
|
|
|
# The previous DEBUG_SYNC should be ignored, because an exclusive lock
|
|
|
|
# has been requested and the online log is not being allocated.
|
|
|
|
ALTER TABLE t1 ADD UNIQUE INDEX(c2),
|
|
|
|
LOCK = EXCLUSIVE, ALGORITHM = INPLACE;
|
|
|
|
|
|
|
|
SHOW CREATE TABLE t1;
|
|
|
|
# Now the previous DEBUG_SYNC should kick in.
|
|
|
|
--send
|
|
|
|
ALTER TABLE t1 DROP INDEX c2, ADD PRIMARY KEY(c1);
|
|
|
|
|
|
|
|
connection default;
|
|
|
|
SET DEBUG_SYNC = 'now WAIT_FOR scanned';
|
|
|
|
eval $innodb_metrics_select;
|
|
|
|
|
|
|
|
# Insert a duplicate entry (4) for the already started UNIQUE INDEX(c1).
|
|
|
|
INSERT INTO t1 VALUES(4,7,2);
|
|
|
|
SET DEBUG_SYNC = 'now SIGNAL insert_done';
|
|
|
|
|
|
|
|
connection con1;
|
|
|
|
# Because the modification log will be applied in order and we did
|
|
|
|
# not roll back before the log apply, there will be a duplicate key
|
|
|
|
# error on the (4,7,2).
|
|
|
|
--error ER_DUP_ENTRY
|
|
|
|
reap;
|
MDEV-15250 UPSERT during ALTER TABLE results in 'Duplicate entry' error for alter
- InnoDB DDL results in `Duplicate entry' if concurrent DML throws
duplicate key error. The following scenario explains the problem
connection con1:
ALTER TABLE t1 FORCE;
connection con2:
INSERT INTO t1(pk, uk) VALUES (2, 2), (3, 2);
In connection con2, InnoDB throws the 'DUPLICATE KEY' error because
of unique index. Alter operation will throw the error when applying
the concurrent DML log.
- Inserting the duplicate key for unique index logs the insert
operation for online ALTER TABLE. When insertion fails,
transaction does rollback and it leads to logging of
delete operation for online ALTER TABLE.
While applying the insert log entries, alter operation
encounters 'DUPLICATE KEY' error.
- To avoid the above fake duplicate scenario, InnoDB should
not write any log for online ALTER TABLE before DML transaction
commit.
- User thread which does DML can apply the online log if
InnoDB ran out of online log and index is marked as completed.
Set online log error if apply phase encountered any error.
It can also clear all other indexes log, marks the newly
added indexes as corrupted.
- Removed the old online code which was a part of DML operations
commit_inplace_alter_table() : Does apply the online log
for the last batch of secondary index log and does frees
the log for the completed index.
trx_t::apply_online_log: Set to true while writing the undo
log if the modified table has active DDL
trx_t::apply_log(): Apply the DML changes to online DDL tables
dict_table_t::is_active_ddl(): Returns true if the table
has an active DDL
dict_index_t::online_log_make_dummy(): Assign dummy value
for clustered index online log to indicate the secondary
indexes are being rebuild.
dict_index_t::online_log_is_dummy(): Check whether the online
log has dummy value
ha_innobase_inplace_ctx::log_failure(): Handle the apply log
failure for online DDL transaction
row_log_mark_other_online_index_abort(): Clear out all other
online index log after encountering the error during
row_log_apply()
row_log_get_error(): Get the error happened during row_log_apply()
row_log_online_op(): Does apply the online log if index is
completed and ran out of memory. Returns false if apply log fails
UndorecApplier: Introduced a class to maintain the undo log
record, latched undo buffer page, parse the undo log record,
maintain the undo record type, info bits and update vector
UndorecApplier::get_old_rec(): Get the correct version of the
clustered index record that was modified by the current undo
log record
UndorecApplier::clear_undo_rec(): Clear the undo log related
information after applying the undo log record
UndorecApplier::log_update(): Handle the update, delete undo
log and apply it on online indexes
UndorecApplier::log_insert(): Handle the insert undo log
and apply it on online indexes
UndorecApplier::is_same(): Check whether the given roll pointer
is generated by the current undo log record information
trx_t::rollback_low(): Set apply_online_log for the transaction
after partially rollbacked transaction has any active DDL
prepare_inplace_alter_table_dict(): After allocating the online
log, InnoDB does create fulltext common tables. Fulltext index
doesn't allow the index to be online. So removed the dead
code of online log removal
Thanks to Marko Mäkelä for providing the initial prototype and
Matthias Leich for testing the issue patiently.
2022-04-25 13:36:56 +05:30
|
|
|
DELETE FROM t1 WHERE c1=4 and c2=7;
|
2017-08-29 11:27:28 +03:00
|
|
|
connection default;
|
|
|
|
ROLLBACK;
|
|
|
|
|
|
|
|
connection con1;
|
|
|
|
SHOW CREATE TABLE t1;
|
|
|
|
# Now, rebuild the table without any concurrent DML, while no duplicate exists.
|
|
|
|
--error ER_CANT_DROP_FIELD_OR_KEY
|
|
|
|
ALTER TABLE t1 DROP PRIMARY KEY, ADD UNIQUE INDEX(c2), ALGORITHM = INPLACE;
|
|
|
|
ALTER TABLE t1 DROP INDEX c2, ADD PRIMARY KEY(c1), ALGORITHM = INPLACE;
|
|
|
|
eval $innodb_metrics_select;
|
|
|
|
|
|
|
|
connection default;
|
|
|
|
--error ER_DUP_ENTRY
|
|
|
|
INSERT INTO t1 VALUES(6,3,1);
|
|
|
|
--error ER_DUP_ENTRY
|
|
|
|
INSERT INTO t1 VALUES(7,4,2);
|
|
|
|
DROP INDEX c2_2 ON t1;
|
|
|
|
BEGIN;
|
|
|
|
INSERT INTO t1 VALUES(7,4,2);
|
|
|
|
ROLLBACK;
|
|
|
|
|
|
|
|
connection con1;
|
|
|
|
let $ID= `SELECT @id := CONNECTION_ID()`;
|
|
|
|
--error ER_QUERY_INTERRUPTED
|
|
|
|
KILL QUERY @id;
|
|
|
|
|
2017-09-25 09:29:27 +03:00
|
|
|
SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL rebuilt WAIT_FOR dml_done';
|
|
|
|
SET DEBUG_SYNC = 'row_log_table_apply2_before SIGNAL applied WAIT_FOR kill_done';
|
2017-08-29 11:27:28 +03:00
|
|
|
--send
|
|
|
|
ALTER TABLE t1 ROW_FORMAT=REDUNDANT;
|
|
|
|
|
|
|
|
connection default;
|
|
|
|
SET DEBUG_SYNC = 'now WAIT_FOR rebuilt';
|
|
|
|
eval $innodb_metrics_select;
|
2017-09-25 09:29:27 +03:00
|
|
|
BEGIN;
|
|
|
|
INSERT INTO t1 VALUES(7,4,2);
|
|
|
|
ROLLBACK;
|
|
|
|
SET DEBUG_SYNC = 'now SIGNAL dml_done WAIT_FOR applied';
|
2017-08-29 11:27:28 +03:00
|
|
|
let $ignore= `SELECT @id := $ID`;
|
|
|
|
KILL QUERY @id;
|
|
|
|
SET DEBUG_SYNC = 'now SIGNAL kill_done';
|
|
|
|
|
|
|
|
connection con1;
|
|
|
|
--error ER_QUERY_INTERRUPTED
|
|
|
|
reap;
|
|
|
|
eval $innodb_metrics_select;
|
|
|
|
|
|
|
|
connection default;
|
|
|
|
CHECK TABLE t1;
|
|
|
|
INSERT INTO t1 SELECT 5 + c1, c2, c3 FROM t1;
|
|
|
|
INSERT INTO t1 SELECT 10 + c1, c2, c3 FROM t1;
|
|
|
|
INSERT INTO t1 SELECT 20 + c1, c2, c3 FROM t1;
|
|
|
|
INSERT INTO t1 SELECT 40 + c1, c2, c3 FROM t1;
|
|
|
|
# Purge may or may not have cleaned up the DELETE FROM t1 WHERE c1 = 7;
|
2017-09-16 16:55:16 +03:00
|
|
|
--replace_column 9 ROWS
|
2017-08-29 11:27:28 +03:00
|
|
|
EXPLAIN SELECT COUNT(*) FROM t1 WHERE c2 > 3;
|
|
|
|
ANALYZE TABLE t1;
|
|
|
|
|
2017-09-16 16:55:16 +03:00
|
|
|
SET @merge_encrypt_0=
|
|
|
|
(SELECT variable_value FROM information_schema.global_status
|
|
|
|
WHERE variable_name = 'innodb_encryption_n_merge_blocks_encrypted');
|
|
|
|
SET @merge_decrypt_0=
|
|
|
|
(SELECT variable_value FROM information_schema.global_status
|
|
|
|
WHERE variable_name = 'innodb_encryption_n_merge_blocks_decrypted');
|
|
|
|
SET @rowlog_encrypt_0=
|
|
|
|
(SELECT variable_value FROM information_schema.global_status
|
|
|
|
WHERE variable_name = 'innodb_encryption_n_rowlog_blocks_encrypted');
|
|
|
|
|
2017-08-29 11:27:28 +03:00
|
|
|
connection con1;
|
|
|
|
SHOW CREATE TABLE t1;
|
2017-09-25 09:29:27 +03:00
|
|
|
ALTER TABLE t1 ROW_FORMAT=REDUNDANT;
|
2017-08-29 11:27:28 +03:00
|
|
|
|
|
|
|
# Exceed the configured innodb_online_alter_log_max_size.
|
|
|
|
# The actual limit is a multiple of innodb_sort_buf_size,
|
|
|
|
# because that is the size of the in-memory log buffers.
|
|
|
|
SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL rebuilt2 WAIT_FOR dml2_done';
|
|
|
|
# Ensure that the ALTER TABLE will be executed even with some concurrent DML.
|
|
|
|
SET lock_wait_timeout = 10;
|
|
|
|
--send
|
2017-10-30 18:47:43 +02:00
|
|
|
ALTER TABLE t1 ROW_FORMAT=COMPACT
|
|
|
|
PAGE_COMPRESSED = YES PAGE_COMPRESSION_LEVEL = 1, ALGORITHM = INPLACE;
|
2017-08-29 11:27:28 +03:00
|
|
|
|
|
|
|
# Generate some log (delete-mark, delete-unmark, insert etc.)
|
2021-11-25 14:03:20 +02:00
|
|
|
# while the index creation is blocked.
|
2017-08-29 11:27:28 +03:00
|
|
|
connection default;
|
2021-11-25 14:03:20 +02:00
|
|
|
SET DEBUG_SYNC = 'now WAIT_FOR rebuilt2';
|
2017-08-29 11:27:28 +03:00
|
|
|
INSERT INTO t1 SELECT 80 + c1, c2, c3 FROM t1;
|
|
|
|
INSERT INTO t1 SELECT 160 + c1, c2, c3 FROM t1;
|
|
|
|
UPDATE t1 SET c2 = c2 + 1;
|
|
|
|
# At this point, the clustered index scan must have completed,
|
|
|
|
# but the modification log keeps accumulating due to the DEBUG_SYNC.
|
|
|
|
eval $innodb_metrics_select;
|
MDEV-15250 UPSERT during ALTER TABLE results in 'Duplicate entry' error for alter
- InnoDB DDL results in `Duplicate entry' if concurrent DML throws
duplicate key error. The following scenario explains the problem
connection con1:
ALTER TABLE t1 FORCE;
connection con2:
INSERT INTO t1(pk, uk) VALUES (2, 2), (3, 2);
In connection con2, InnoDB throws the 'DUPLICATE KEY' error because
of unique index. Alter operation will throw the error when applying
the concurrent DML log.
- Inserting the duplicate key for unique index logs the insert
operation for online ALTER TABLE. When insertion fails,
transaction does rollback and it leads to logging of
delete operation for online ALTER TABLE.
While applying the insert log entries, alter operation
encounters 'DUPLICATE KEY' error.
- To avoid the above fake duplicate scenario, InnoDB should
not write any log for online ALTER TABLE before DML transaction
commit.
- User thread which does DML can apply the online log if
InnoDB ran out of online log and index is marked as completed.
Set online log error if apply phase encountered any error.
It can also clear all other indexes log, marks the newly
added indexes as corrupted.
- Removed the old online code which was a part of DML operations
commit_inplace_alter_table() : Does apply the online log
for the last batch of secondary index log and does frees
the log for the completed index.
trx_t::apply_online_log: Set to true while writing the undo
log if the modified table has active DDL
trx_t::apply_log(): Apply the DML changes to online DDL tables
dict_table_t::is_active_ddl(): Returns true if the table
has an active DDL
dict_index_t::online_log_make_dummy(): Assign dummy value
for clustered index online log to indicate the secondary
indexes are being rebuild.
dict_index_t::online_log_is_dummy(): Check whether the online
log has dummy value
ha_innobase_inplace_ctx::log_failure(): Handle the apply log
failure for online DDL transaction
row_log_mark_other_online_index_abort(): Clear out all other
online index log after encountering the error during
row_log_apply()
row_log_get_error(): Get the error happened during row_log_apply()
row_log_online_op(): Does apply the online log if index is
completed and ran out of memory. Returns false if apply log fails
UndorecApplier: Introduced a class to maintain the undo log
record, latched undo buffer page, parse the undo log record,
maintain the undo record type, info bits and update vector
UndorecApplier::get_old_rec(): Get the correct version of the
clustered index record that was modified by the current undo
log record
UndorecApplier::clear_undo_rec(): Clear the undo log related
information after applying the undo log record
UndorecApplier::log_update(): Handle the update, delete undo
log and apply it on online indexes
UndorecApplier::log_insert(): Handle the insert undo log
and apply it on online indexes
UndorecApplier::is_same(): Check whether the given roll pointer
is generated by the current undo log record information
trx_t::rollback_low(): Set apply_online_log for the transaction
after partially rollbacked transaction has any active DDL
prepare_inplace_alter_table_dict(): After allocating the online
log, InnoDB does create fulltext common tables. Fulltext index
doesn't allow the index to be online. So removed the dead
code of online log removal
Thanks to Marko Mäkelä for providing the initial prototype and
Matthias Leich for testing the issue patiently.
2022-04-25 13:36:56 +05:30
|
|
|
let $c= 8;
|
2017-08-29 11:27:28 +03:00
|
|
|
while ($c)
|
|
|
|
{
|
|
|
|
UPDATE t1 SET c2 = c2 + 1;
|
MDEV-15250 UPSERT during ALTER TABLE results in 'Duplicate entry' error for alter
- InnoDB DDL results in `Duplicate entry' if concurrent DML throws
duplicate key error. The following scenario explains the problem
connection con1:
ALTER TABLE t1 FORCE;
connection con2:
INSERT INTO t1(pk, uk) VALUES (2, 2), (3, 2);
In connection con2, InnoDB throws the 'DUPLICATE KEY' error because
of unique index. Alter operation will throw the error when applying
the concurrent DML log.
- Inserting the duplicate key for unique index logs the insert
operation for online ALTER TABLE. When insertion fails,
transaction does rollback and it leads to logging of
delete operation for online ALTER TABLE.
While applying the insert log entries, alter operation
encounters 'DUPLICATE KEY' error.
- To avoid the above fake duplicate scenario, InnoDB should
not write any log for online ALTER TABLE before DML transaction
commit.
- User thread which does DML can apply the online log if
InnoDB ran out of online log and index is marked as completed.
Set online log error if apply phase encountered any error.
It can also clear all other indexes log, marks the newly
added indexes as corrupted.
- Removed the old online code which was a part of DML operations
commit_inplace_alter_table() : Does apply the online log
for the last batch of secondary index log and does frees
the log for the completed index.
trx_t::apply_online_log: Set to true while writing the undo
log if the modified table has active DDL
trx_t::apply_log(): Apply the DML changes to online DDL tables
dict_table_t::is_active_ddl(): Returns true if the table
has an active DDL
dict_index_t::online_log_make_dummy(): Assign dummy value
for clustered index online log to indicate the secondary
indexes are being rebuild.
dict_index_t::online_log_is_dummy(): Check whether the online
log has dummy value
ha_innobase_inplace_ctx::log_failure(): Handle the apply log
failure for online DDL transaction
row_log_mark_other_online_index_abort(): Clear out all other
online index log after encountering the error during
row_log_apply()
row_log_get_error(): Get the error happened during row_log_apply()
row_log_online_op(): Does apply the online log if index is
completed and ran out of memory. Returns false if apply log fails
UndorecApplier: Introduced a class to maintain the undo log
record, latched undo buffer page, parse the undo log record,
maintain the undo record type, info bits and update vector
UndorecApplier::get_old_rec(): Get the correct version of the
clustered index record that was modified by the current undo
log record
UndorecApplier::clear_undo_rec(): Clear the undo log related
information after applying the undo log record
UndorecApplier::log_update(): Handle the update, delete undo
log and apply it on online indexes
UndorecApplier::log_insert(): Handle the insert undo log
and apply it on online indexes
UndorecApplier::is_same(): Check whether the given roll pointer
is generated by the current undo log record information
trx_t::rollback_low(): Set apply_online_log for the transaction
after partially rollbacked transaction has any active DDL
prepare_inplace_alter_table_dict(): After allocating the online
log, InnoDB does create fulltext common tables. Fulltext index
doesn't allow the index to be online. So removed the dead
code of online log removal
Thanks to Marko Mäkelä for providing the initial prototype and
Matthias Leich for testing the issue patiently.
2022-04-25 13:36:56 +05:30
|
|
|
UPDATE t1 SET c2 = c2 + 2;
|
2017-08-29 11:27:28 +03:00
|
|
|
dec $c;
|
|
|
|
}
|
|
|
|
# Temporary table should exist until the DDL thread notices the overflow.
|
|
|
|
eval $innodb_metrics_select;
|
|
|
|
|
2017-09-16 16:55:16 +03:00
|
|
|
SET @merge_encrypt_1=
|
|
|
|
(SELECT variable_value FROM information_schema.global_status
|
|
|
|
WHERE variable_name = 'innodb_encryption_n_merge_blocks_encrypted');
|
|
|
|
SET @merge_decrypt_1=
|
|
|
|
(SELECT variable_value FROM information_schema.global_status
|
|
|
|
WHERE variable_name = 'innodb_encryption_n_merge_blocks_decrypted');
|
|
|
|
SET @rowlog_encrypt_1=
|
|
|
|
(SELECT variable_value FROM information_schema.global_status
|
|
|
|
WHERE variable_name = 'innodb_encryption_n_rowlog_blocks_encrypted');
|
|
|
|
|
|
|
|
SELECT
|
|
|
|
(@merge_encrypt_1-@merge_encrypt_0)-
|
|
|
|
(@merge_decrypt_1-@merge_decrypt_0) as sort_balance,
|
|
|
|
@merge_encrypt_1>@merge_encrypt_0, @merge_decrypt_1>@merge_decrypt_0,
|
|
|
|
@rowlog_encrypt_1>@rowlog_encrypt_0;
|
|
|
|
|
2017-08-29 11:27:28 +03:00
|
|
|
# Release con1.
|
|
|
|
SET DEBUG_SYNC = 'now SIGNAL dml2_done';
|
|
|
|
|
|
|
|
connection con1;
|
|
|
|
# If the following fails with the wrong error, it probably means that
|
|
|
|
# you should rerun with a larger mtr --debug-sync-timeout.
|
|
|
|
--error ER_INNODB_ONLINE_LOG_TOO_BIG
|
|
|
|
reap;
|
|
|
|
# The table should have been dropped from the data dictionary
|
|
|
|
# when the above error was noticed.
|
|
|
|
eval $innodb_metrics_select;
|
|
|
|
|
2017-09-16 16:55:16 +03:00
|
|
|
SET @merge_encrypt_1=
|
|
|
|
(SELECT variable_value FROM information_schema.global_status
|
|
|
|
WHERE variable_name = 'innodb_encryption_n_merge_blocks_encrypted');
|
|
|
|
SET @merge_decrypt_1=
|
|
|
|
(SELECT variable_value FROM information_schema.global_status
|
|
|
|
WHERE variable_name = 'innodb_encryption_n_merge_blocks_decrypted');
|
|
|
|
SET @rowlog_encrypt_1=
|
|
|
|
(SELECT variable_value FROM information_schema.global_status
|
|
|
|
WHERE variable_name = 'innodb_encryption_n_rowlog_blocks_encrypted');
|
|
|
|
SET @rowlog_decrypt_1=
|
|
|
|
(SELECT variable_value FROM information_schema.global_status
|
|
|
|
WHERE variable_name = 'innodb_encryption_n_rowlog_blocks_decrypted');
|
|
|
|
|
2017-08-29 11:27:28 +03:00
|
|
|
# Accumulate and apply some modification log.
|
|
|
|
SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL rebuilt3 WAIT_FOR dml3_done';
|
|
|
|
--error ER_MULTIPLE_PRI_KEY
|
|
|
|
ALTER TABLE t1 ADD PRIMARY KEY(c22f), CHANGE c2 c22f INT;
|
|
|
|
--error ER_DUP_ENTRY
|
|
|
|
ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY(c22f), CHANGE c2 c22f INT;
|
|
|
|
--send
|
2017-09-17 13:46:51 +03:00
|
|
|
ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY(c22f,c1,c4(5)),
|
2017-09-16 16:55:16 +03:00
|
|
|
CHANGE c2 c22f INT, CHANGE c3 c3 CHAR(255) NULL, CHANGE c1 c1 INT AFTER c22f,
|
|
|
|
ADD COLUMN c4 VARCHAR(6) DEFAULT 'Online', LOCK=NONE;
|
2017-08-29 11:27:28 +03:00
|
|
|
|
|
|
|
connection default;
|
|
|
|
SET DEBUG_SYNC = 'now WAIT_FOR rebuilt3';
|
|
|
|
# Generate some log (delete-mark, delete-unmark, insert etc.)
|
|
|
|
eval $innodb_metrics_select;
|
|
|
|
BEGIN;
|
|
|
|
INSERT INTO t1 SELECT 320 + c1, c2, c3 FROM t1 WHERE c1 > 240;
|
|
|
|
DELETE FROM t1 WHERE c1 > 320;
|
|
|
|
UPDATE t1 SET c2 = c2 + 1;
|
MDEV-15250 UPSERT during ALTER TABLE results in 'Duplicate entry' error for alter
- InnoDB DDL results in `Duplicate entry' if concurrent DML throws
duplicate key error. The following scenario explains the problem
connection con1:
ALTER TABLE t1 FORCE;
connection con2:
INSERT INTO t1(pk, uk) VALUES (2, 2), (3, 2);
In connection con2, InnoDB throws the 'DUPLICATE KEY' error because
of unique index. Alter operation will throw the error when applying
the concurrent DML log.
- Inserting the duplicate key for unique index logs the insert
operation for online ALTER TABLE. When insertion fails,
transaction does rollback and it leads to logging of
delete operation for online ALTER TABLE.
While applying the insert log entries, alter operation
encounters 'DUPLICATE KEY' error.
- To avoid the above fake duplicate scenario, InnoDB should
not write any log for online ALTER TABLE before DML transaction
commit.
- User thread which does DML can apply the online log if
InnoDB ran out of online log and index is marked as completed.
Set online log error if apply phase encountered any error.
It can also clear all other indexes log, marks the newly
added indexes as corrupted.
- Removed the old online code which was a part of DML operations
commit_inplace_alter_table() : Does apply the online log
for the last batch of secondary index log and does frees
the log for the completed index.
trx_t::apply_online_log: Set to true while writing the undo
log if the modified table has active DDL
trx_t::apply_log(): Apply the DML changes to online DDL tables
dict_table_t::is_active_ddl(): Returns true if the table
has an active DDL
dict_index_t::online_log_make_dummy(): Assign dummy value
for clustered index online log to indicate the secondary
indexes are being rebuild.
dict_index_t::online_log_is_dummy(): Check whether the online
log has dummy value
ha_innobase_inplace_ctx::log_failure(): Handle the apply log
failure for online DDL transaction
row_log_mark_other_online_index_abort(): Clear out all other
online index log after encountering the error during
row_log_apply()
row_log_get_error(): Get the error happened during row_log_apply()
row_log_online_op(): Does apply the online log if index is
completed and ran out of memory. Returns false if apply log fails
UndorecApplier: Introduced a class to maintain the undo log
record, latched undo buffer page, parse the undo log record,
maintain the undo record type, info bits and update vector
UndorecApplier::get_old_rec(): Get the correct version of the
clustered index record that was modified by the current undo
log record
UndorecApplier::clear_undo_rec(): Clear the undo log related
information after applying the undo log record
UndorecApplier::log_update(): Handle the update, delete undo
log and apply it on online indexes
UndorecApplier::log_insert(): Handle the insert undo log
and apply it on online indexes
UndorecApplier::is_same(): Check whether the given roll pointer
is generated by the current undo log record information
trx_t::rollback_low(): Set apply_online_log for the transaction
after partially rollbacked transaction has any active DDL
prepare_inplace_alter_table_dict(): After allocating the online
log, InnoDB does create fulltext common tables. Fulltext index
doesn't allow the index to be online. So removed the dead
code of online log removal
Thanks to Marko Mäkelä for providing the initial prototype and
Matthias Leich for testing the issue patiently.
2022-04-25 13:36:56 +05:30
|
|
|
COMMIT;
|
2017-08-29 11:27:28 +03:00
|
|
|
eval $innodb_metrics_select;
|
|
|
|
# Release con1.
|
|
|
|
SET DEBUG_SYNC = 'now SIGNAL dml3_done';
|
|
|
|
|
|
|
|
connection con1;
|
|
|
|
reap;
|
|
|
|
eval $innodb_metrics_select;
|
|
|
|
SELECT COUNT(c22f) FROM t1;
|
|
|
|
CHECK TABLE t1;
|
|
|
|
|
2017-09-16 16:55:16 +03:00
|
|
|
SET @merge_encrypt_2=
|
|
|
|
(SELECT variable_value FROM information_schema.global_status
|
|
|
|
WHERE variable_name = 'innodb_encryption_n_merge_blocks_encrypted');
|
|
|
|
SET @merge_decrypt_2=
|
|
|
|
(SELECT variable_value FROM information_schema.global_status
|
|
|
|
WHERE variable_name = 'innodb_encryption_n_merge_blocks_decrypted');
|
|
|
|
SET @rowlog_encrypt_2=
|
|
|
|
(SELECT variable_value FROM information_schema.global_status
|
|
|
|
WHERE variable_name = 'innodb_encryption_n_rowlog_blocks_encrypted');
|
|
|
|
SET @rowlog_decrypt_2=
|
|
|
|
(SELECT variable_value FROM information_schema.global_status
|
|
|
|
WHERE variable_name = 'innodb_encryption_n_rowlog_blocks_decrypted');
|
|
|
|
|
|
|
|
SELECT
|
|
|
|
(@merge_encrypt_2-@merge_encrypt_1)-
|
|
|
|
(@merge_decrypt_2-@merge_decrypt_1) as sort_balance,
|
|
|
|
(@rowlog_encrypt_2-@rowlog_encrypt_1)-
|
|
|
|
(@rowlog_decrypt_2-@rowlog_decrypt_1) as log_balance;
|
|
|
|
SELECT
|
|
|
|
@merge_encrypt_2-@merge_encrypt_1>0 as sort_encrypted,
|
|
|
|
@merge_decrypt_2-@merge_decrypt_1>0 as sort_decrypted,
|
|
|
|
@rowlog_encrypt_2-@rowlog_encrypt_1>0 as log_encrypted,
|
|
|
|
@rowlog_decrypt_2-@rowlog_decrypt_1>0 as log_decrypted;
|
|
|
|
|
2017-08-29 11:27:28 +03:00
|
|
|
# Create a column prefix index.
|
|
|
|
--error ER_DUP_ENTRY
|
|
|
|
ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY c3p5(c3(5));
|
|
|
|
UPDATE t1 SET c3 = NULL WHERE c3 = '';
|
|
|
|
SET lock_wait_timeout = 1;
|
2021-09-09 11:58:45 +03:00
|
|
|
--error ER_KEY_COLUMN_DOES_NOT_EXIST
|
2017-08-29 11:27:28 +03:00
|
|
|
ALTER TABLE t1 DROP COLUMN c22f, ADD PRIMARY KEY c3p5(c3(5));
|
2019-03-05 12:56:05 +02:00
|
|
|
# NULL -> NOT NULL is only allowed INPLACE without IGNORE.
|
|
|
|
# Adding a PRIMARY KEY will add NOT NULL implicitly!
|
|
|
|
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
|
2018-06-25 14:52:38 +05:30
|
|
|
ALTER IGNORE TABLE t1 DROP COLUMN c22f, DROP PRIMARY KEY, ADD PRIMARY KEY c3p5(c3(5)),
|
2017-08-29 11:27:28 +03:00
|
|
|
ALGORITHM = INPLACE;
|
|
|
|
|
2017-09-16 16:55:16 +03:00
|
|
|
UPDATE t1 SET c3=LEFT(CONCAT(c1,REPEAT('foo',c1)),255) WHERE c3 IS NULL;
|
2017-08-29 11:27:28 +03:00
|
|
|
|
|
|
|
SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL c3p5_created0 WAIT_FOR ins_done0';
|
2019-03-05 12:56:05 +02:00
|
|
|
# NULL -> NOT NULL is allowed INPLACE.
|
2017-08-29 11:27:28 +03:00
|
|
|
--send
|
2017-09-16 16:55:16 +03:00
|
|
|
ALTER TABLE t1 MODIFY c3 CHAR(255) NOT NULL, DROP COLUMN c22f,
|
2017-08-31 09:28:59 +03:00
|
|
|
DROP PRIMARY KEY, ADD PRIMARY KEY(c1,c4(5)),
|
2017-08-29 11:27:28 +03:00
|
|
|
ADD COLUMN c5 CHAR(5) DEFAULT 'tired' FIRST;
|
|
|
|
|
|
|
|
connection default;
|
|
|
|
|
|
|
|
SET DEBUG_SYNC = 'now WAIT_FOR c3p5_created0';
|
|
|
|
BEGIN;
|
|
|
|
INSERT INTO t1 VALUES(347,33101,'Pikku kakkosen posti','YLETV2');
|
|
|
|
INSERT INTO t1 VALUES(33101,347,NULL,'');
|
MDEV-15250 UPSERT during ALTER TABLE results in 'Duplicate entry' error for alter
- InnoDB DDL results in `Duplicate entry' if concurrent DML throws
duplicate key error. The following scenario explains the problem
connection con1:
ALTER TABLE t1 FORCE;
connection con2:
INSERT INTO t1(pk, uk) VALUES (2, 2), (3, 2);
In connection con2, InnoDB throws the 'DUPLICATE KEY' error because
of unique index. Alter operation will throw the error when applying
the concurrent DML log.
- Inserting the duplicate key for unique index logs the insert
operation for online ALTER TABLE. When insertion fails,
transaction does rollback and it leads to logging of
delete operation for online ALTER TABLE.
While applying the insert log entries, alter operation
encounters 'DUPLICATE KEY' error.
- To avoid the above fake duplicate scenario, InnoDB should
not write any log for online ALTER TABLE before DML transaction
commit.
- User thread which does DML can apply the online log if
InnoDB ran out of online log and index is marked as completed.
Set online log error if apply phase encountered any error.
It can also clear all other indexes log, marks the newly
added indexes as corrupted.
- Removed the old online code which was a part of DML operations
commit_inplace_alter_table() : Does apply the online log
for the last batch of secondary index log and does frees
the log for the completed index.
trx_t::apply_online_log: Set to true while writing the undo
log if the modified table has active DDL
trx_t::apply_log(): Apply the DML changes to online DDL tables
dict_table_t::is_active_ddl(): Returns true if the table
has an active DDL
dict_index_t::online_log_make_dummy(): Assign dummy value
for clustered index online log to indicate the secondary
indexes are being rebuild.
dict_index_t::online_log_is_dummy(): Check whether the online
log has dummy value
ha_innobase_inplace_ctx::log_failure(): Handle the apply log
failure for online DDL transaction
row_log_mark_other_online_index_abort(): Clear out all other
online index log after encountering the error during
row_log_apply()
row_log_get_error(): Get the error happened during row_log_apply()
row_log_online_op(): Does apply the online log if index is
completed and ran out of memory. Returns false if apply log fails
UndorecApplier: Introduced a class to maintain the undo log
record, latched undo buffer page, parse the undo log record,
maintain the undo record type, info bits and update vector
UndorecApplier::get_old_rec(): Get the correct version of the
clustered index record that was modified by the current undo
log record
UndorecApplier::clear_undo_rec(): Clear the undo log related
information after applying the undo log record
UndorecApplier::log_update(): Handle the update, delete undo
log and apply it on online indexes
UndorecApplier::log_insert(): Handle the insert undo log
and apply it on online indexes
UndorecApplier::is_same(): Check whether the given roll pointer
is generated by the current undo log record information
trx_t::rollback_low(): Set apply_online_log for the transaction
after partially rollbacked transaction has any active DDL
prepare_inplace_alter_table_dict(): After allocating the online
log, InnoDB does create fulltext common tables. Fulltext index
doesn't allow the index to be online. So removed the dead
code of online log removal
Thanks to Marko Mäkelä for providing the initial prototype and
Matthias Leich for testing the issue patiently.
2022-04-25 13:36:56 +05:30
|
|
|
COMMIT;
|
2017-08-29 11:27:28 +03:00
|
|
|
SET DEBUG_SYNC = 'now SIGNAL ins_done0';
|
|
|
|
|
|
|
|
connection con1;
|
MDEV-15250 UPSERT during ALTER TABLE results in 'Duplicate entry' error for alter
- InnoDB DDL results in `Duplicate entry' if concurrent DML throws
duplicate key error. The following scenario explains the problem
connection con1:
ALTER TABLE t1 FORCE;
connection con2:
INSERT INTO t1(pk, uk) VALUES (2, 2), (3, 2);
In connection con2, InnoDB throws the 'DUPLICATE KEY' error because
of unique index. Alter operation will throw the error when applying
the concurrent DML log.
- Inserting the duplicate key for unique index logs the insert
operation for online ALTER TABLE. When insertion fails,
transaction does rollback and it leads to logging of
delete operation for online ALTER TABLE.
While applying the insert log entries, alter operation
encounters 'DUPLICATE KEY' error.
- To avoid the above fake duplicate scenario, InnoDB should
not write any log for online ALTER TABLE before DML transaction
commit.
- User thread which does DML can apply the online log if
InnoDB ran out of online log and index is marked as completed.
Set online log error if apply phase encountered any error.
It can also clear all other indexes log, marks the newly
added indexes as corrupted.
- Removed the old online code which was a part of DML operations
commit_inplace_alter_table() : Does apply the online log
for the last batch of secondary index log and does frees
the log for the completed index.
trx_t::apply_online_log: Set to true while writing the undo
log if the modified table has active DDL
trx_t::apply_log(): Apply the DML changes to online DDL tables
dict_table_t::is_active_ddl(): Returns true if the table
has an active DDL
dict_index_t::online_log_make_dummy(): Assign dummy value
for clustered index online log to indicate the secondary
indexes are being rebuild.
dict_index_t::online_log_is_dummy(): Check whether the online
log has dummy value
ha_innobase_inplace_ctx::log_failure(): Handle the apply log
failure for online DDL transaction
row_log_mark_other_online_index_abort(): Clear out all other
online index log after encountering the error during
row_log_apply()
row_log_get_error(): Get the error happened during row_log_apply()
row_log_online_op(): Does apply the online log if index is
completed and ran out of memory. Returns false if apply log fails
UndorecApplier: Introduced a class to maintain the undo log
record, latched undo buffer page, parse the undo log record,
maintain the undo record type, info bits and update vector
UndorecApplier::get_old_rec(): Get the correct version of the
clustered index record that was modified by the current undo
log record
UndorecApplier::clear_undo_rec(): Clear the undo log related
information after applying the undo log record
UndorecApplier::log_update(): Handle the update, delete undo
log and apply it on online indexes
UndorecApplier::log_insert(): Handle the insert undo log
and apply it on online indexes
UndorecApplier::is_same(): Check whether the given roll pointer
is generated by the current undo log record information
trx_t::rollback_low(): Set apply_online_log for the transaction
after partially rollbacked transaction has any active DDL
prepare_inplace_alter_table_dict(): After allocating the online
log, InnoDB does create fulltext common tables. Fulltext index
doesn't allow the index to be online. So removed the dead
code of online log removal
Thanks to Marko Mäkelä for providing the initial prototype and
Matthias Leich for testing the issue patiently.
2022-04-25 13:36:56 +05:30
|
|
|
--error ER_INVALID_USE_OF_NULL
|
2017-08-29 11:27:28 +03:00
|
|
|
reap;
|
MDEV-15250 UPSERT during ALTER TABLE results in 'Duplicate entry' error for alter
- InnoDB DDL results in `Duplicate entry' if concurrent DML throws
duplicate key error. The following scenario explains the problem
connection con1:
ALTER TABLE t1 FORCE;
connection con2:
INSERT INTO t1(pk, uk) VALUES (2, 2), (3, 2);
In connection con2, InnoDB throws the 'DUPLICATE KEY' error because
of unique index. Alter operation will throw the error when applying
the concurrent DML log.
- Inserting the duplicate key for unique index logs the insert
operation for online ALTER TABLE. When insertion fails,
transaction does rollback and it leads to logging of
delete operation for online ALTER TABLE.
While applying the insert log entries, alter operation
encounters 'DUPLICATE KEY' error.
- To avoid the above fake duplicate scenario, InnoDB should
not write any log for online ALTER TABLE before DML transaction
commit.
- User thread which does DML can apply the online log if
InnoDB ran out of online log and index is marked as completed.
Set online log error if apply phase encountered any error.
It can also clear all other indexes log, marks the newly
added indexes as corrupted.
- Removed the old online code which was a part of DML operations
commit_inplace_alter_table() : Does apply the online log
for the last batch of secondary index log and does frees
the log for the completed index.
trx_t::apply_online_log: Set to true while writing the undo
log if the modified table has active DDL
trx_t::apply_log(): Apply the DML changes to online DDL tables
dict_table_t::is_active_ddl(): Returns true if the table
has an active DDL
dict_index_t::online_log_make_dummy(): Assign dummy value
for clustered index online log to indicate the secondary
indexes are being rebuild.
dict_index_t::online_log_is_dummy(): Check whether the online
log has dummy value
ha_innobase_inplace_ctx::log_failure(): Handle the apply log
failure for online DDL transaction
row_log_mark_other_online_index_abort(): Clear out all other
online index log after encountering the error during
row_log_apply()
row_log_get_error(): Get the error happened during row_log_apply()
row_log_online_op(): Does apply the online log if index is
completed and ran out of memory. Returns false if apply log fails
UndorecApplier: Introduced a class to maintain the undo log
record, latched undo buffer page, parse the undo log record,
maintain the undo record type, info bits and update vector
UndorecApplier::get_old_rec(): Get the correct version of the
clustered index record that was modified by the current undo
log record
UndorecApplier::clear_undo_rec(): Clear the undo log related
information after applying the undo log record
UndorecApplier::log_update(): Handle the update, delete undo
log and apply it on online indexes
UndorecApplier::log_insert(): Handle the insert undo log
and apply it on online indexes
UndorecApplier::is_same(): Check whether the given roll pointer
is generated by the current undo log record information
trx_t::rollback_low(): Set apply_online_log for the transaction
after partially rollbacked transaction has any active DDL
prepare_inplace_alter_table_dict(): After allocating the online
log, InnoDB does create fulltext common tables. Fulltext index
doesn't allow the index to be online. So removed the dead
code of online log removal
Thanks to Marko Mäkelä for providing the initial prototype and
Matthias Leich for testing the issue patiently.
2022-04-25 13:36:56 +05:30
|
|
|
DELETE FROM t1 WHERE c1= 347 and c22f = 33101;
|
2017-09-16 16:55:16 +03:00
|
|
|
ALTER TABLE t1 MODIFY c3 CHAR(255) NOT NULL;
|
2018-04-24 13:15:35 +05:30
|
|
|
|
2017-08-29 11:27:28 +03:00
|
|
|
SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL c3p5_created WAIT_FOR ins_done';
|
|
|
|
--send
|
|
|
|
ALTER TABLE t1 DROP PRIMARY KEY, DROP COLUMN c22f,
|
|
|
|
ADD COLUMN c6 VARCHAR(1000) DEFAULT
|
|
|
|
'I love tracking down hard-to-reproduce bugs.',
|
|
|
|
ADD PRIMARY KEY c3p5(c3(5), c6(2));
|
|
|
|
|
|
|
|
connection default;
|
|
|
|
SET DEBUG_SYNC = 'now WAIT_FOR c3p5_created';
|
|
|
|
SET DEBUG_SYNC = 'ib_after_row_insert SIGNAL ins_done WAIT_FOR ddl_timed_out';
|
|
|
|
--error ER_BAD_NULL_ERROR
|
|
|
|
INSERT INTO t1 VALUES(347,33101,NULL,'');
|
|
|
|
--send
|
|
|
|
INSERT INTO t1 VALUES(347,33101,'Pikku kakkosen posti','');
|
|
|
|
|
|
|
|
connection con1;
|
|
|
|
--error ER_LOCK_WAIT_TIMEOUT
|
|
|
|
reap;
|
|
|
|
SET DEBUG_SYNC = 'now SIGNAL ddl_timed_out';
|
|
|
|
eval $innodb_metrics_select;
|
|
|
|
|
|
|
|
connection default;
|
|
|
|
reap;
|
|
|
|
SELECT COUNT(*) FROM t1;
|
|
|
|
ALTER TABLE t1 ROW_FORMAT=REDUNDANT;
|
|
|
|
SELECT * FROM t1 LIMIT 10;
|
|
|
|
|
|
|
|
connection con1;
|
|
|
|
ALTER TABLE t1 DISCARD TABLESPACE;
|
|
|
|
|
|
|
|
connection default;
|
|
|
|
SHOW CREATE TABLE t1;
|
|
|
|
SET GLOBAL innodb_monitor_disable = module_ddl;
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
2021-02-04 14:23:01 +05:30
|
|
|
CREATE TABLE t1 (a INT PRIMARY KEY, b blob) ENGINE=InnoDB;
|
2021-11-16 16:30:45 +02:00
|
|
|
INSERT INTO t1 VALUES(0,NULL);
|
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
|
|
|
|
|
|
|
connection con1;
|
|
|
|
SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL created WAIT_FOR ins';
|
|
|
|
send ALTER TABLE t1 FORCE;
|
|
|
|
|
|
|
|
connection default;
|
|
|
|
SET DEBUG_SYNC = 'now WAIT_FOR created';
|
|
|
|
BEGIN;
|
2021-02-04 14:23:01 +05:30
|
|
|
INSERT INTO t1 VALUES(1, repeat('a', 10000));
|
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
|
|
|
ROLLBACK;
|
|
|
|
SET DEBUG_SYNC = 'now SIGNAL ins';
|
|
|
|
|
|
|
|
connection con1;
|
|
|
|
reap;
|
|
|
|
|
|
|
|
connection default;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
DROP TABLE t1;
|
|
|
|
SET DEBUG_SYNC = 'RESET';
|
|
|
|
|
2022-09-22 11:18:00 +03:00
|
|
|
--echo #
|
|
|
|
--echo # MDEV-29600 Memory leak in row_log_table_apply_update()
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
CREATE TABLE t1 (pk INT PRIMARY KEY, f TEXT) ENGINE=InnoDB;
|
|
|
|
INSERT INTO t1 SET pk=1;
|
|
|
|
|
|
|
|
connection con1;
|
|
|
|
SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL created WAIT_FOR updated';
|
|
|
|
send ALTER TABLE t1 FORCE;
|
|
|
|
|
|
|
|
connection default;
|
|
|
|
SET DEBUG_SYNC = 'now WAIT_FOR created';
|
|
|
|
UPDATE t1 SET f = REPEAT('a', 20000);
|
|
|
|
SET DEBUG_SYNC = 'now SIGNAL updated';
|
|
|
|
|
|
|
|
connection con1;
|
|
|
|
reap;
|
|
|
|
disconnect con1;
|
|
|
|
|
|
|
|
connection default;
|
|
|
|
DROP TABLE t1;
|
|
|
|
SET DEBUG_SYNC = 'RESET';
|
|
|
|
|
2017-08-29 11:27:28 +03:00
|
|
|
# Check that all connections opened by test cases in this file are really
|
|
|
|
# gone so execution of other tests won't be affected by their presence.
|
|
|
|
--source include/wait_until_count_sessions.inc
|
|
|
|
|
|
|
|
SET GLOBAL innodb_file_per_table = @global_innodb_file_per_table_orig;
|
|
|
|
--disable_warnings
|
|
|
|
SET GLOBAL innodb_monitor_enable = default;
|
|
|
|
SET GLOBAL innodb_monitor_disable = default;
|
|
|
|
--enable_warnings
|