Commit 88b7b819 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-18076/MDEV-18077 Crash on AUTO_INCREMENT column after instant DROP

The fix for MDEV-17901 did not cover cases where the AUTO_INCREMENT
column was not dropped, but some other columns before it were.

commit_cache_norebuild(): Revert the MDEV-17901 fix.

dict_index_t::clear_instant_alter(): Update table->persistent_autoinc.
parent 00372075
...@@ -578,6 +578,15 @@ id f ...@@ -578,6 +578,15 @@ id f
1 NULL 1 NULL
2 NULL 2 NULL
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1(f INT, k INT NOT NULL AUTO_INCREMENT, KEY(k)) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
ALTER TABLE t1 DROP COLUMN f;
INSERT INTO t1 VALUES (1);
DROP TABLE t1;
CREATE TABLE t1(pk INT PRIMARY KEY, f INT, k INT AUTO_INCREMENT, KEY(k))
ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
ALTER TABLE t1 DROP COLUMN f;
INSERT INTO t1 (pk) VALUES (1);
DROP TABLE t1;
CREATE TABLE t1 ( CREATE TABLE t1 (
pk INT PRIMARY KEY, pk INT PRIMARY KEY,
f1 INT, f1 INT,
...@@ -1153,6 +1162,15 @@ id f ...@@ -1153,6 +1162,15 @@ id f
1 NULL 1 NULL
2 NULL 2 NULL
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1(f INT, k INT NOT NULL AUTO_INCREMENT, KEY(k)) ENGINE=InnoDB ROW_FORMAT=COMPACT;
ALTER TABLE t1 DROP COLUMN f;
INSERT INTO t1 VALUES (1);
DROP TABLE t1;
CREATE TABLE t1(pk INT PRIMARY KEY, f INT, k INT AUTO_INCREMENT, KEY(k))
ENGINE=InnoDB ROW_FORMAT=COMPACT;
ALTER TABLE t1 DROP COLUMN f;
INSERT INTO t1 (pk) VALUES (1);
DROP TABLE t1;
CREATE TABLE t1 ( CREATE TABLE t1 (
pk INT PRIMARY KEY, pk INT PRIMARY KEY,
f1 INT, f1 INT,
...@@ -1728,6 +1746,15 @@ id f ...@@ -1728,6 +1746,15 @@ id f
1 NULL 1 NULL
2 NULL 2 NULL
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1(f INT, k INT NOT NULL AUTO_INCREMENT, KEY(k)) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
ALTER TABLE t1 DROP COLUMN f;
INSERT INTO t1 VALUES (1);
DROP TABLE t1;
CREATE TABLE t1(pk INT PRIMARY KEY, f INT, k INT AUTO_INCREMENT, KEY(k))
ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
ALTER TABLE t1 DROP COLUMN f;
INSERT INTO t1 (pk) VALUES (1);
DROP TABLE t1;
CREATE TABLE t1 ( CREATE TABLE t1 (
pk INT PRIMARY KEY, pk INT PRIMARY KEY,
f1 INT, f1 INT,
...@@ -1784,5 +1811,5 @@ SELECT variable_value-@old_instant instants ...@@ -1784,5 +1811,5 @@ SELECT variable_value-@old_instant instants
FROM information_schema.global_status FROM information_schema.global_status
WHERE variable_name = 'innodb_instant_alter_column'; WHERE variable_name = 'innodb_instant_alter_column';
instants instants
125 131
SET GLOBAL innodb_purge_rseg_truncate_frequency= @saved_frequency; SET GLOBAL innodb_purge_rseg_truncate_frequency= @saved_frequency;
...@@ -447,6 +447,18 @@ ALTER TABLE t1 ADD COLUMN id INT NOT NULL AUTO_INCREMENT FIRST, ADD KEY(id); ...@@ -447,6 +447,18 @@ ALTER TABLE t1 ADD COLUMN id INT NOT NULL AUTO_INCREMENT FIRST, ADD KEY(id);
SELECT * FROM t1; SELECT * FROM t1;
DROP TABLE t1; DROP TABLE t1;
# MDEV-18076/MDEV-18077 Crash on AUTO_INCREMENT column after instant DROP
eval CREATE TABLE t1(f INT, k INT NOT NULL AUTO_INCREMENT, KEY(k)) $engine;
ALTER TABLE t1 DROP COLUMN f;
INSERT INTO t1 VALUES (1);
DROP TABLE t1;
eval CREATE TABLE t1(pk INT PRIMARY KEY, f INT, k INT AUTO_INCREMENT, KEY(k))
$engine;
ALTER TABLE t1 DROP COLUMN f;
INSERT INTO t1 (pk) VALUES (1);
DROP TABLE t1;
# MDEV-17763 Assertion `len == 20U' failed in rec_convert_dtuple_to_rec_comp # MDEV-17763 Assertion `len == 20U' failed in rec_convert_dtuple_to_rec_comp
# upon DROP COLUMN # upon DROP COLUMN
eval CREATE TABLE t1 ( eval CREATE TABLE t1 (
......
...@@ -10294,14 +10294,6 @@ commit_cache_norebuild( ...@@ -10294,14 +10294,6 @@ commit_cache_norebuild(
f->fixed_len); f->fixed_len);
} }
} }
DBUG_ASSERT(!ctx->instant_table->persistent_autoinc
|| ctx->new_table->persistent_autoinc
== ctx->instant_table->persistent_autoinc);
if (!ctx->instant_table->persistent_autoinc) {
ctx->new_table->persistent_autoinc = 0;
}
} }
} }
......
...@@ -2218,6 +2218,9 @@ inline void dict_index_t::clear_instant_alter() ...@@ -2218,6 +2218,9 @@ inline void dict_index_t::clear_instant_alter()
DBUG_ASSERT(!fields[i].col->is_nullable()); DBUG_ASSERT(!fields[i].col->is_nullable());
} }
#endif #endif
const dict_col_t* ai_col = table->persistent_autoinc
? fields[table->persistent_autoinc - 1].col
: NULL;
dict_field_t* const begin = &fields[first_user_field()]; dict_field_t* const begin = &fields[first_user_field()];
dict_field_t* end = &fields[n_fields]; dict_field_t* end = &fields[n_fields];
...@@ -2240,6 +2243,12 @@ inline void dict_index_t::clear_instant_alter() ...@@ -2240,6 +2243,12 @@ inline void dict_index_t::clear_instant_alter()
std::sort(begin, end, [](const dict_field_t& a, const dict_field_t& b) std::sort(begin, end, [](const dict_field_t& a, const dict_field_t& b)
{ return a.col->ind < b.col->ind; }); { return a.col->ind < b.col->ind; });
table->instant = NULL; table->instant = NULL;
if (ai_col) {
auto a = std::find_if(begin, end,
[ai_col](const dict_field_t& f)
{ return f.col == ai_col; });
table->persistent_autoinc = (a == end) ? 0 : 1 + (a - fields);
}
} }
/** @return whether the column was instantly dropped /** @return whether the column was instantly dropped
......
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