From 1355fadb59693ba0ecbf544b9ff23083e610c8f7 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Sat, 14 Oct 2017 17:31:57 +0300 Subject: [PATCH] MDEV-13720 Server crashes in SEQUENCE::write_lock for temporary tables This happens when doing NEXT VALUE for a temporary table Fixed by giving ER_NOT_SEQUENCE when trying to use normal temporary table with sequence functions Signed-off-by: Monty --- mysql-test/suite/sql_sequence/next.result | 7 +++++++ mysql-test/suite/sql_sequence/next.test | 9 +++++++++ sql/sql_base.cc | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/mysql-test/suite/sql_sequence/next.result b/mysql-test/suite/sql_sequence/next.result index a10c131e0e1..d138c342c9d 100644 --- a/mysql-test/suite/sql_sequence/next.result +++ b/mysql-test/suite/sql_sequence/next.result @@ -512,3 +512,10 @@ def PREVIOUS VALUE FOR s1 8 20 1 Y 32896 0 63 NEXT VALUE FOR s1 PREVIOUS VALUE FOR s1 1 1 DROP SEQUENCE s1; +# +# MDEV-13720 ER_NOT_SEQUENCE for temporary table +# +create temporary table tmp (i int); +select next value for tmp; +ERROR 42S02: 'test.tmp' is not a SEQUENCE +drop table tmp; diff --git a/mysql-test/suite/sql_sequence/next.test b/mysql-test/suite/sql_sequence/next.test index 271c4a6558a..79249002d8f 100644 --- a/mysql-test/suite/sql_sequence/next.test +++ b/mysql-test/suite/sql_sequence/next.test @@ -260,3 +260,12 @@ SELECT DROP SEQUENCE s1; --enable_ps_protocol --disable_metadata + +--echo # +--echo # MDEV-13720 ER_NOT_SEQUENCE for temporary table +--echo # + +create temporary table tmp (i int); +--error ER_NOT_SEQUENCE +select next value for tmp; +drop table tmp; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 1a9f7ba6ebf..9c5fc23af8e 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -3341,6 +3341,11 @@ open_and_process_table(THD *thd, LEX *lex, TABLE_LIST *tables, temporary table or SEQUENCE (see sequence_insert()). */ DBUG_ASSERT(is_temporary_table(tables) || tables->table->s->sequence); + if (tables->sequence && tables->table->s->table_type != TABLE_TYPE_SEQUENCE) + { + my_error(ER_NOT_SEQUENCE, MYF(0), tables->db, tables->alias); + DBUG_RETURN(true); + } } else if (tables->open_type == OT_TEMPORARY_ONLY) {