Skip to content

Commit a3c980b

Browse files
committed
MDEV-10824 - Crash in CREATE OR REPLACE TABLE t1 AS SELECT spfunc()
Code flow hit incorrect branch while closing table instances before removal. This branch expects thread to hold open table instance, whereas CREATE OR REPLACE doesn't actually hold open table instance. Before CREATE OR REPLACE TABLE it was impossible to hit this condition in LTM_PRELOCKED mode, thus the problem didn't expose itself during DROP TABLE or DROP DATABASE. Fixed by adjusting condition to take into account LTM_PRELOCKED mode, which can be set during CREATE OR REPLACE TABLE.
1 parent 9155cc7 commit a3c980b

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

mysql-test/r/create_or_replace.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,14 @@ KILL QUERY con_id;
442442
ERROR 70100: Query execution was interrupted
443443
drop table t1;
444444
DROP TABLE t2;
445+
#
446+
# MDEV-10824 - Crash in CREATE OR REPLACE TABLE t1 AS SELECT spfunc()
447+
#
448+
CREATE TABLE t1(a INT);
449+
CREATE FUNCTION f1() RETURNS VARCHAR(16383) RETURN 'test';
450+
CREATE OR REPLACE TABLE t1 AS SELECT f1();
451+
LOCK TABLE t1 WRITE;
452+
CREATE OR REPLACE TABLE t1 AS SELECT f1();
453+
UNLOCK TABLES;
454+
DROP FUNCTION f1;
455+
DROP TABLE t1;

mysql-test/t/create_or_replace.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,15 @@ drop table t1;
386386
# Cleanup
387387
#
388388
DROP TABLE t2;
389+
390+
--echo #
391+
--echo # MDEV-10824 - Crash in CREATE OR REPLACE TABLE t1 AS SELECT spfunc()
392+
--echo #
393+
CREATE TABLE t1(a INT);
394+
CREATE FUNCTION f1() RETURNS VARCHAR(16383) RETURN 'test';
395+
CREATE OR REPLACE TABLE t1 AS SELECT f1();
396+
LOCK TABLE t1 WRITE;
397+
CREATE OR REPLACE TABLE t1 AS SELECT f1();
398+
UNLOCK TABLES;
399+
DROP FUNCTION f1;
400+
DROP TABLE t1;

sql/sql_table.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,8 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
24642464
if (table_type && table_type != view_pseudo_hton)
24652465
ha_lock_engine(thd, table_type);
24662466

2467-
if (thd->locked_tables_mode)
2467+
if (thd->locked_tables_mode == LTM_LOCK_TABLES ||
2468+
thd->locked_tables_mode == LTM_PRELOCKED_UNDER_LOCK_TABLES)
24682469
{
24692470
if (wait_while_table_is_used(thd, table->table, HA_EXTRA_NOT_USED))
24702471
{

0 commit comments

Comments
 (0)