Commit a7dd24cd authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-8299: MyISAM or Aria table gets corrupted after EXPLAIN INSERT and INSERT

[EXPLAIN] INSERT .. SELECT creates a select_insert object.
select_insert calls handler->start_bulk_insert() during
initialization.

For MyISAM/Aria this requires that a matching call to
handler->end_bulk_insert() call is made.

Regular INSERT .. SELECT accomplishes this by calling either
select_result->send_eof() or select_result->abort_result_set().

EXPLAIN INSERT ... SELECT didn't call either, which resulted in
improper de-initializaiton of handler object. Make it call
abort_result_set(), which invokes handler->end_bulk_insert().
parent bb22eb55
......@@ -232,3 +232,18 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE user index NULL PRIMARY 420 NULL 4 Using index
DROP TABLE t1;
DROP VIEW v1;
#
# MDEV-8299: MyISAM or Aria table gets corrupted after EXPLAIN INSERT and INSERT
#
CREATE TABLE t1 (pk INT NOT NULL AUTO_INCREMENT PRIMARY KEY, i INT, KEY(i)) ENGINE=MyISAM;
INSERT INTO t1 (i) VALUES (100),(200);
CREATE TABLE t2 (j INT) ENGINE=MyISAM;
INSERT INTO t2 VALUES (10),(20);
EXPLAIN INSERT INTO t1 (i) SELECT j FROM t2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
INSERT INTO t1 (i) VALUES (300);
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
DROP TABLE t1, t2;
......@@ -208,3 +208,19 @@ INSERT INTO t1 VALUES (1),(2);
EXPLAIN UPDATE v1, mysql.user SET v1.a = v1.a + 1;
DROP TABLE t1;
DROP VIEW v1;
--echo #
--echo # MDEV-8299: MyISAM or Aria table gets corrupted after EXPLAIN INSERT and INSERT
--echo #
CREATE TABLE t1 (pk INT NOT NULL AUTO_INCREMENT PRIMARY KEY, i INT, KEY(i)) ENGINE=MyISAM;
INSERT INTO t1 (i) VALUES (100),(200);
CREATE TABLE t2 (j INT) ENGINE=MyISAM;
INSERT INTO t2 VALUES (10),(20);
EXPLAIN INSERT INTO t1 (i) SELECT j FROM t2;
INSERT INTO t1 (i) VALUES (300);
CHECK TABLE t1;
DROP TABLE t1, t2;
......@@ -3549,6 +3549,16 @@ end_with_restore_list:
query_cache_invalidate3(thd, first_table, 1);
first_table->next_local= save_table;
}
if (explain)
{
/*
sel_result needs to be cleaned up properly.
INSERT... SELECT statement will call either send_eof() or
abort_result_set(). EXPLAIN doesn't call either, so we need
to cleanup manually.
*/
sel_result->abort_result_set();
}
delete sel_result;
}
......
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