Commit 315380a4 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-26052 Assertion prebuilt->trx_id < table->def_trx_id failed

ha_innobase::truncate(): If the operation fails, preserve
also dict_table_t::def_trx_id.

This fixes a regression that had been introduced in
commit 1bd681c8 (MDEV-25506).
parent ed6b2307
......@@ -68,3 +68,21 @@ TRUNCATE TABLE t1;
ALTER TABLE t1 ADD c INT;
UNLOCK TABLES;
DROP TABLE t1;
#
# MDEV-26052 Assertion prebuilt->trx_id < table->def_trx_id failed
#
call mtr.add_suppression("InnoDB: In ALTER TABLE `test`\\.`t1` has or is");
CREATE TABLE t1 (pk INT, a INT, PRIMARY KEY (pk), KEY (a)) ENGINE=InnoDB;
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE t1 ADD FOREIGN KEY (a) REFERENCES t1 (a), ALGORITHM=COPY;
INSERT INTO t1 VALUES (1,1);
LOCK TABLES t1 WRITE;
TRUNCATE t1;
ERROR HY000: Cannot add foreign key constraint for `t1`
INSERT INTO t1 VALUES (2,2);
SELECT * FROM t1;
pk a
1 1
2 2
DROP TABLE t1;
# End of 10.6 tests
......@@ -80,3 +80,22 @@ TRUNCATE TABLE t1;
ALTER TABLE t1 ADD c INT;
UNLOCK TABLES;
DROP TABLE t1;
--echo #
--echo # MDEV-26052 Assertion prebuilt->trx_id < table->def_trx_id failed
--echo #
call mtr.add_suppression("InnoDB: In ALTER TABLE `test`\\.`t1` has or is");
CREATE TABLE t1 (pk INT, a INT, PRIMARY KEY (pk), KEY (a)) ENGINE=InnoDB;
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE t1 ADD FOREIGN KEY (a) REFERENCES t1 (a), ALGORITHM=COPY;
INSERT INTO t1 VALUES (1,1);
LOCK TABLES t1 WRITE;
--error ER_CANNOT_ADD_FOREIGN
TRUNCATE t1;
INSERT INTO t1 VALUES (2,2);
SELECT * FROM t1;
DROP TABLE t1;
--echo # End of 10.6 tests
......@@ -13707,6 +13707,7 @@ int ha_innobase::truncate()
} else {
const auto update_time = ib_table->update_time;
const auto stored_lock = m_prebuilt->stored_select_lock_type;
const auto def_trx_id = ib_table->def_trx_id;
ib_table->release();
m_prebuilt->table = nullptr;
......@@ -13721,6 +13722,7 @@ int ha_innobase::truncate()
reload:
m_prebuilt->table = dict_table_open_on_name(
name, false, false, DICT_ERR_IGNORE_NONE);
m_prebuilt->table->def_trx_id = def_trx_id;
} else {
row_prebuilt_t* prebuilt = m_prebuilt;
uchar* upd_buf = m_upd_buf;
......
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