[MDEV-17167] InnoDB: Failing assertion: table->get_ref_count() == 0 upon truncating a temporary table Created: 2018-09-10  Updated: 2019-05-14  Resolved: 2018-10-02

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Temporary, Prepared Statements, Storage Engine - InnoDB
Affects Version/s: 10.3
Fix Version/s: 10.3.10, 10.4.0, 10.2.25

Type: Bug Priority: Blocker
Reporter: Elena Stepanova Assignee: Sergey Vojtovich
Resolution: Fixed Votes: 0
Labels: affects-tests, regression

Issue Links:
Relates
relates to MDEV-19449 1030: Got error 168 "Unknown (generic... Closed

 Description   

Note: I have no idea why PREPARE is important in the scenario below, but it doesn't crash without it.

--source include/have_innodb.inc
 
CREATE TEMPORARY TABLE t ENGINE=InnoDB SELECT 1 AS a;
PREPARE stmt FROM 'CREATE TEMPORARY TABLE t SELECT 1 AS b FROM t';
TRUNCATE TABLE t;

10.3 6b61f1bbad1a ASAN build

2018-09-10 18:14:41 0x7f558e7de700  InnoDB: Assertion failure in file /data/src/10.3/storage/innobase/dict/dict0dict.cc line 1986
InnoDB: Failing assertion: table->get_ref_count() == 0
 
ut/ut0dbg.cc:62(__static_initialization_and_destruction_0(int, int))[0x557f0b975f47]
dict/dict0dict.cc:1987(dict_table_remove_from_cache_low(dict_table_t*, unsigned long))[0x557f0babc2a5]
dict/dict0dict.cc:2070(dict_table_remove_from_cache(dict_table_t*))[0x557f0babd33a]
row/row0mysql.cc:3470(row_drop_table_for_mysql(char const*, trx_t*, enum_sql_command, bool, bool))[0x557f0b801e15]
handler/ha_innodb.cc:12833(ha_innobase::delete_table(char const*, enum_sql_command))[0x557f0b5a9c18]
handler/ha_innodb.cc:13224(ha_innobase::truncate())[0x557f0b57f8ca]
sql/handler.cc:4306(handler::ha_truncate())[0x557f0adb42ff]
sql/sql_truncate.cc:242(Sql_cmd_truncate_table::handler_truncate(THD*, TABLE_LIST*, bool))[0x557f0b20ab7e]
sql/sql_truncate.cc:404(Sql_cmd_truncate_table::truncate_table(THD*, TABLE_LIST*))[0x557f0b20bb7d]
sql/sql_truncate.cc:502(Sql_cmd_truncate_table::execute(THD*))[0x557f0b20c1dd]
sql/sql_parse.cc:6285(mysql_execute_command(THD*))[0x557f0a6b06c8]
sql/sql_parse.cc:8089(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x557f0a6bb55d]
sql/sql_parse.cc:1852(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x557f0a6957e8]
sql/sql_parse.cc:1395(do_command(THD*))[0x557f0a692870]
sql/sql_connect.cc:1402(do_handle_one_connection(CONNECT*))[0x557f0aa02b2c]
sql/sql_connect.cc:1309(handle_one_connection)[0x557f0aa02538]
perfschema/pfs.cc:1864(pfs_spawn_thread)[0x557f0b51c51c]
nptl/pthread_create.c:333(start_thread)[0x7f84f666d494]
x86_64/clone.S:99(clone)[0x7f84f4a5393f]
 
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (0x62b000000288): TRUNCATE TABLE t
Connection ID (thread ID): 9
Status: NOT_KILLED

The failure starting happening in 10.3 from this commit:

commit 5a1868b58d26b286b6ad433096e7184895953311
Merge: 4901f31 980d1bf
Author: Marko Mäkelä <marko.makela@mariadb.com>
Date:   Fri Sep 7 22:15:06 2018 +0300
 
    MDEV-13564 Mariabackup does not work with TRUNCATE



 Comments   
Comment by Marko Mäkelä [ 2018-09-10 ]

The test seems to work without crashes on the 10.2-based branch that I merged to 10.3, but it does crash in 10.3.
The InnoDB code in this area should be similar between the two branches, so I would suspect something in the SQL layer.

Comment by Sergey Vojtovich [ 2018-09-12 ]

serg, please review fix for this bug. I'm not completely sure on replication and LOCK TABLES impact, however basic tests passed.

Patch: https://github.com/MariaDB/server/commit/e11e0e6c8b9a85ca7f16c6b9b28fb505d464a96e

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