From d8da97b09abec8fba2398f6ff6d84285b0752400 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Thu, 5 Apr 2018 15:16:20 +0300 Subject: [PATCH] MDEV-14762 Server crashes in MDL_ticket::has_stronger_or_equal_type upon inserting into temporary sequence Fix is to not upgrade MDL locks for temporary tables --- mysql-test/suite/sql_sequence/temporary.result | 7 +++++++ mysql-test/suite/sql_sequence/temporary.test | 9 +++++++++ sql/ha_sequence.cc | 9 ++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/mysql-test/suite/sql_sequence/temporary.result b/mysql-test/suite/sql_sequence/temporary.result index 4885b5f8a26..69463667210 100644 --- a/mysql-test/suite/sql_sequence/temporary.result +++ b/mysql-test/suite/sql_sequence/temporary.result @@ -10,3 +10,10 @@ select * from s1; next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count 1001 1 9223372036854775806 1 1 1000 0 0 drop temporary sequence s1; +# +# MDEV-14762 Server crashes in MDL_ticket::has_stronger_or_equal_type +# upon inserting into temporary sequence +# +CREATE TEMPORARY SEQUENCE s1 ENGINE=InnoDB; +INSERT INTO s1 VALUES (1, 1, 1000, 1, 1, 1, 1, 0); +DROP TEMPORARY SEQUENCE s1; diff --git a/mysql-test/suite/sql_sequence/temporary.test b/mysql-test/suite/sql_sequence/temporary.test index 158f6b4961e..4943ed66ea4 100644 --- a/mysql-test/suite/sql_sequence/temporary.test +++ b/mysql-test/suite/sql_sequence/temporary.test @@ -14,3 +14,12 @@ alter table s1 engine myisam; select nextval(s1); select * from s1; drop temporary sequence s1; + +--echo # +--echo # MDEV-14762 Server crashes in MDL_ticket::has_stronger_or_equal_type +--echo # upon inserting into temporary sequence +--echo # + +CREATE TEMPORARY SEQUENCE s1 ENGINE=InnoDB; +INSERT INTO s1 VALUES (1, 1, 1000, 1, 1, 1, 1, 0); +DROP TEMPORARY SEQUENCE s1; diff --git a/sql/ha_sequence.cc b/sql/ha_sequence.cc index 93f6f32d473..b500ce3c1f6 100644 --- a/sql/ha_sequence.cc +++ b/sql/ha_sequence.cc @@ -237,9 +237,12 @@ int ha_sequence::write_row(uchar *buf) THD *thd= table->in_use; if (thd->lock->table_count != 1) DBUG_RETURN(ER_WRONG_INSERT_INTO_SEQUENCE); - if (thd->mdl_context.upgrade_shared_lock(table->mdl_ticket, MDL_EXCLUSIVE, - thd->variables.lock_wait_timeout)) - DBUG_RETURN(ER_LOCK_WAIT_TIMEOUT); + if (table->s->tmp_table == NO_TMP_TABLE && + thd->mdl_context.upgrade_shared_lock(table->mdl_ticket, + MDL_EXCLUSIVE, + thd->variables. + lock_wait_timeout)) + DBUG_RETURN(ER_LOCK_WAIT_TIMEOUT); tmp_seq.read_fields(table); if (tmp_seq.check_and_adjust(0))