[MDEV-28913] Assertion `thd->mdl_context.is_lock_owner(MDL_key::TABLE, table->s->db.str, table->s->table_name.str, MDL_SHARED)' failed in void close_thread_table(THD*, TABLE**) Created: 2022-06-20  Updated: 2023-11-28

Status: Confirmed
Project: MariaDB Server
Component/s: Data Definition - Alter Table, Data Definition - Temporary, Locking, Sequences
Affects Version/s: 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11, 11.0, 11.1, 11.2, 11.3.0
Fix Version/s: 10.4, 10.5, 10.6, 10.11, 11.0, 11.1, 11.2

Type: Bug Priority: Major
Reporter: Ramesh Sivaraman Assignee: Oleksandr Byelkin
Resolution: Unresolved Votes: 0
Labels: debug, not-10.2


 Description   

CREATE TABLE t0 (a INT KEY,b ENUM ('','b','c'));
ALTER TABLE t0 RENAME TO s0;
CREATE TEMPORARY SEQUENCE s0;
CREATE TABLE t0 (id INT DEFAULT NEXTval (s0),a_p_name CHAR(0),a_p_FIRST_NAME VARCHAR(0),t TIMESTAMP);
ALTER TABLE t0 ADD COLUMN a INT,DROP FOREIGN KEY ibfk_0;

Leads to:

10.9.2 6ec17142dcfb1e9d9f41211ed1b6d82e062d1541 (Debug)

mysqld: /test/10.9_dbg/sql/sql_base.cc:963: void close_thread_table(THD*, TABLE**): Assertion `thd->mdl_context.is_lock_owner(MDL_key::TABLE, table->s->db.str, table->s->table_name.str, MDL_SHARED)' failed.

10.9.2 6ec17142dcfb1e9d9f41211ed1b6d82e062d1541 (Debug)

Core was generated by `/test/MD280522-mariadb-10.9.2-linux-x86_64-dbg/bin/mysqld --no-defaults --core-'.
Program terminated with signal SIGABRT, Aborted.
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
[Current thread is 1 (Thread 0x14e551d82700 (LWP 1833906))]
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x000014e56a706859 in __GI_abort () at abort.c:79
#2  0x000014e56a706729 in __assert_fail_base (fmt=0x14e56a89c588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x5644b2355090 "thd->mdl_context.is_lock_owner(MDL_key::TABLE, table->s->db.str, table->s->table_name.str, MDL_SHARED)", file=0x5644b2354a38 "/test/10.9_dbg/sql/sql_base.cc", line=963, function=<optimized out>) at assert.c:92
#3  0x000014e56a717f36 in __GI___assert_fail (assertion=assertion@entry=0x5644b2355090 "thd->mdl_context.is_lock_owner(MDL_key::TABLE, table->s->db.str, table->s->table_name.str, MDL_SHARED)", file=file@entry=0x5644b2354a38 "/test/10.9_dbg/sql/sql_base.cc", line=line@entry=963, function=function@entry=0x5644b2355040 "void close_thread_table(THD*, TABLE**)") at assert.c:101
#4  0x00005644b16dd94b in close_thread_table (thd=thd@entry=0x14e51c000db8, table_ptr=table_ptr@entry=0x14e51c000ea8) at /test/10.9_dbg/sql/sql_base.cc:963
#5  0x00005644b16ddc9e in close_thread_tables (thd=thd@entry=0x14e51c000db8) at /test/10.9_dbg/sql/sql_base.cc:942
#6  0x00005644b16dde95 in close_thread_tables_for_query (thd=thd@entry=0x14e51c000db8) at /test/10.9_dbg/sql/sql_base.cc:771
#7  0x00005644b1775ef6 in mysql_execute_command (thd=thd@entry=0x14e51c000db8, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/10.9_dbg/sql/sql_parse.cc:6062
#8  0x00005644b175dbca in mysql_parse (thd=thd@entry=0x14e51c000db8, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x14e551d81470) at /test/10.9_dbg/sql/sql_parse.cc:8036
#9  0x00005644b176b198 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x14e51c000db8, packet=packet@entry=0x14e51c00b6c9 "ALTER TABLE t0 ADD COLUMN a INT,DROP FOREIGN KEY ibfk_0", packet_length=packet_length@entry=55, blocking=blocking@entry=true) at /test/10.9_dbg/sql/sql_class.h:1364
#10 0x00005644b176d8a0 in do_command (thd=0x14e51c000db8, blocking=blocking@entry=true) at /test/10.9_dbg/sql/sql_parse.cc:1407
#11 0x00005644b18ccd88 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x5644b45214c8, put_in_cache=put_in_cache@entry=true) at /test/10.9_dbg/sql/sql_connect.cc:1418
#12 0x00005644b18cd291 in handle_one_connection (arg=0x5644b45214c8) at /test/10.9_dbg/sql/sql_connect.cc:1312
#13 0x000014e56ac15609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#14 0x000014e56a803293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.3.36 (dbg), 10.4.26 (dbg), 10.5.17 (dbg), 10.6.9 (dbg), 10.7.5 (dbg), 10.8.4 (dbg), 10.9.2 (dbg)

Bug (or feature/syntax) confirmed not present in:
MariaDB: 10.2.44 (dbg), 10.2.44 (opt), 10.3.35 (opt), 10.4.25 (opt), 10.5.16 (opt), 10.6.8 (opt), 10.7.4 (opt), 10.8.3 (opt)

The assertion is similar to MDEV-26385, but cannot be reproduced on 10.2



 Comments   
Comment by Roel Van de Paar [ 2023-10-07 ]

Reproducible with both MyISAM and InnoDB.

Comment by Roel Van de Paar [ 2023-10-07 ]

Minimal MTR testcase

CREATE TABLE s (c INT);
CREATE TEMPORARY SEQUENCE s;
CREATE TABLE t (c INT DEFAULT NEXTVAL (s));
ALTER TABLE t DROP FOREIGN KEY k;

Comment by Elena Stepanova [ 2023-11-04 ]

Starting from 10.6.16, the assertion changed to

mariadbd: /data/src/10.6/sql/sql_base.cc:978: void close_thread_table(THD*, TABLE**): Assertion `thd->mdl_context.is_lock_owner(MDL_key::TABLE, table->s->db.str, table->s->table_name.str, MDL_SHARED) || thd->mdl_context.is_lock_warrantee(MDL_key::TABLE, table->s->db.str, table->s->table_name.s
tr, MDL_SHARED)' failed.

Generated at Thu Feb 08 10:04:25 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.