From 2c0a073970cf5f1dc679b34bb13e7fc55109dfd0 Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Mon, 14 Oct 2013 12:36:31 +0400 Subject: [PATCH] MDEV-5042 - Server crashes when accessing incorrect MERGE table from trigger When we open merge children open error is normally handled early during open phase. But there are two exceptions when error is handled later during attach phase: CHECK/REPAIR TABLE and tables added by the pre-locking code. The latter case wasn't considered by assertion in the merge code. This assertion is corrected. Note that in MySQL-5.6 this assertion is removed. --- mysql-test/r/merge.result | 2 ++ mysql-test/t/merge.test | 5 ++--- storage/myisammrg/ha_myisammrg.cc | 8 ++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/merge.result b/mysql-test/r/merge.result index 7cb9e5bb423..f806829b969 100644 --- a/mysql-test/r/merge.result +++ b/mysql-test/r/merge.result @@ -3910,6 +3910,8 @@ CREATE TABLE m1(a INT) ENGINE = MERGE UNION (q1, q2); CREATE TRIGGER trg1 BEFORE DELETE ON t1 FOR EACH ROW INSERT INTO m1 VALUES (1); +DELETE FROM t1; +ERROR HY000: Unable to open underlying table which is differently defined or of non-MyISAM type or doesn't exist DROP TRIGGER trg1; DROP TABLE t1; DROP TABLE m1; diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test index 18ec2b3d62f..959c7258a53 100644 --- a/mysql-test/t/merge.test +++ b/mysql-test/t/merge.test @@ -2945,9 +2945,8 @@ CREATE TRIGGER trg1 BEFORE DELETE ON t1 FOR EACH ROW INSERT INTO m1 VALUES (1); -# Uncomment the following to lines when MDEV-5042 is fixed. -#--error ER_WRONG_MRG_TABLE -#DELETE FROM t1; +--error ER_WRONG_MRG_TABLE +DELETE FROM t1; DROP TRIGGER trg1; DROP TABLE t1; diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc index bb225002dc0..a1fe8a6efb8 100644 --- a/storage/myisammrg/ha_myisammrg.cc +++ b/storage/myisammrg/ha_myisammrg.cc @@ -653,8 +653,12 @@ extern "C" MI_INFO *myisammrg_attach_children_callback(void *callback_param) { DBUG_PRINT("error", ("failed to open underlying table '%s'.'%s'", child_l->db, child_l->table_name)); - /* This should only happen inside of CHECK/REPAIR TABLE. */ - DBUG_ASSERT(current_thd->open_options & HA_OPEN_FOR_REPAIR); + /* + This should only happen inside of CHECK/REPAIR TABLE or + for the tables added by the pre-locking code. + */ + DBUG_ASSERT(current_thd->open_options & HA_OPEN_FOR_REPAIR || + child_l->prelocking_placeholder); goto end; }