Commit ea2b19de authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-20117: Fix another scenario

Thanks to Eugene Kosov for noting that the fix is incomplete.
It turns out that on instant DROP/reorder column (MDEV-15562),
we must always write the metadata record, even though the table
was empty. Alternatively, we should guarantee that all undo
log records for the table have been purged. (Attempting to do
that by updating table_id leads to other problems; see
commit 1b31d885.)

It would be tempting to remove dict_index_t::clear_instant_alter()
altogether, but it turns that we need that when the instant ALTER TABLE
operation of a first-time DROP COLUMN is being rolled back.

innobase_instant_try(): Clarify a comment. Purge never calls
dict_index_t::clear_instant_alter(), but it may invoke
dict_index_t::clear_instant_add(). On first-time instant DROP/reorder,
always write a metadata record, even if the table is empty.
parent 1f4ee3fa
SET @save_frequency= @@GLOBAL.innodb_purge_rseg_truncate_frequency;
SET GLOBAL innodb_purge_rseg_truncate_frequency=1;
#
# MDEV-17821 Assertion `!page_rec_is_supremum(rec)' failed
# in btr_pcur_store_position
......@@ -295,3 +297,16 @@ ALTER TABLE t DROP COLUMN c, ALGORITHM=INSTANT;
SELECT * FROM t;
a b
DROP TABLE t;
CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c INT, d INT, e INT) ENGINE=InnoDB;
INSERT INTO t1 SET a=1;
INSERT INTO t1 SET a=2;
BEGIN;
UPDATE t1 SET b=1;
DELETE FROM t1;
COMMIT;
ALTER TABLE t1 DROP b, DROP c, DROP d, DROP e;
InnoDB 0 transactions not purged
SELECT * FROM t1;
a
DROP TABLE t1;
SET GLOBAL innodb_purge_rseg_truncate_frequency=@save_frequency;
--source include/have_innodb.inc
SET @save_frequency= @@GLOBAL.innodb_purge_rseg_truncate_frequency;
SET GLOBAL innodb_purge_rseg_truncate_frequency=1;
--echo #
--echo # MDEV-17821 Assertion `!page_rec_is_supremum(rec)' failed
--echo # in btr_pcur_store_position
......@@ -313,3 +316,21 @@ ALTER TABLE t ADD COLUMN c INT, ALGORITHM=INSTANT;
ALTER TABLE t DROP COLUMN c, ALGORITHM=INSTANT;
SELECT * FROM t;
DROP TABLE t;
# The following is nondeterministically repeating the bug in a
# different scenario: the table is empty at the time the ALTER TABLE
# is invoked, apparently because purge already processed the records
# for the DELETE, but not the record for the UPDATE.
CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c INT, d INT, e INT) ENGINE=InnoDB;
INSERT INTO t1 SET a=1;
INSERT INTO t1 SET a=2;
BEGIN;
UPDATE t1 SET b=1;
DELETE FROM t1;
COMMIT;
ALTER TABLE t1 DROP b, DROP c, DROP d, DROP e;
--source include/wait_all_purged.inc
SELECT * FROM t1;
DROP TABLE t1;
SET GLOBAL innodb_purge_rseg_truncate_frequency=@save_frequency;
......@@ -5630,7 +5630,7 @@ static bool innobase_instant_try(
dict_index_t* index = dict_table_get_first_index(user_table);
mtr_t mtr;
mtr.start();
/* Prevent purge from calling dict_index_t::clear_instant_alter(),
/* Prevent purge from calling dict_index_t::clear_instant_add(),
to protect index->n_core_fields, index->table->instant and others
from changing during ctx->instant_column(). */
instant_metadata_lock(*index, mtr);
......@@ -5821,6 +5821,7 @@ static bool innobase_instant_try(
if (rec_is_metadata(rec, *index)) {
ut_ad(page_rec_is_user_rec(rec));
if (!rec_is_alter_metadata(rec, *index)
&& !index->table->instant
&& !page_has_next(block->frame)
&& page_rec_is_last(rec, block->frame)) {
goto empty_table;
......@@ -5902,7 +5903,7 @@ static bool innobase_instant_try(
}
btr_pcur_close(&pcur);
goto func_exit;
} else if (page_rec_is_supremum(rec)) {
} else if (page_rec_is_supremum(rec) && !index->table->instant) {
empty_table:
/* The table is empty. */
ut_ad(fil_page_index_page_check(block->frame));
......@@ -5910,7 +5911,9 @@ static bool innobase_instant_try(
ut_ad(block->page.id.page_no() == index->page);
/* MDEV-17383: free metadata BLOBs! */
btr_page_empty(block, NULL, index, 0, &mtr);
index->clear_instant_alter();
if (index->is_instant()) {
index->clear_instant_add();
}
goto func_exit;
} else if (!user_table->is_instant()) {
ut_ad(!user_table->not_redundant());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment