[MDEV-17726]  Assertion `sqlcom != SQLCOM_TRUNCATE' failed in ha_innobase::delete_table after truncating temporary table Created: 2018-11-15  Updated: 2018-11-19  Resolved: 2018-11-15

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - InnoDB
Affects Version/s: 10.4.0, 10.2.19
Fix Version/s: 10.3.11, 10.4.1, 10.2.20

Type: Bug Priority: Blocker
Reporter: Elena Stepanova Assignee: Marko Mäkelä
Resolution: Fixed Votes: 0
Labels: None


 Description   

--source include/have_innodb.inc
 
CREATE TEMPORARY TABLE t1 (a INT) ENGINE=InnoDB;
--send
  TRUNCATE TABLE t1;

10.4 fde5386d16

mysqld: /data/src/10.4/storage/innobase/handler/ha_innodb.cc:12934: virtual int ha_innobase::delete_table(const char*): Assertion `sqlcom != SQLCOM_TRUNCATE' failed.
181115 16:56:33 [ERROR] mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
 
To report this bug, see https://mariadb.com/kb/en/reporting-bugs
 
We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed, 
something is definitely wrong and this may fail.
 
Server version: 10.4.1-MariaDB-debug-log
key_buffer_size=1048576
read_buffer_size=131072
max_used_connections=1
max_threads=153
thread_count=7
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 63331 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.
 
Thread pointer: 0x7f3018000b00
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0x7f307038ee70 thread_stack 0x49000
mysys/stacktrace.c:269(my_print_stacktrace)[0x5589734a72a1]
sql/signal_handler.cc:168(handle_fatal_signal)[0x558972cf3c5c]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x110c0)[0x7f3078b0e0c0]
linux/raise.c:51(__GI_raise)[0x7f307704ffcf]
stdlib/abort.c:91(__GI_abort)[0x7f30770513fa]
assert/assert.c:92(__assert_fail_base)[0x7f3077048e37]
/lib/x86_64-linux-gnu/libc.so.6(+0x2bee2)[0x7f3077048ee2]

That's the end of the error log, and coredump is not produced.

It fails for me pretty much every time, maybe one or two misses from dozens of attempts.

The test can be run as is, it can also be run with --nocheck-testcases, but --nowarnings makes a difference – with it, the failure is not reproducible. However, trying to imitate warnings activity within the test itself doesn't work.



 Comments   
Comment by Marko Mäkelä [ 2018-11-15 ]

I got a core dump by adding a loop inside the test:

--source include/have_innodb.inc
let $N=1000;
while ($N) {
connect (con1,localhost,root,,test);
CREATE TEMPORARY TABLE t1 (a INT) ENGINE=InnoDB;
--send
TRUNCATE TABLE t1;
disconnect con1;
dec $N;
}

The fix seems to be simple, and the assertion failure ought to affect debug builds only. The sqlcom parameter only affects the treatment of FOREIGN KEY constraints, and they do not exist for temporary tables. There already was a work-around for this problem, but apparently thd_killed() does not hold here.

int ha_innobase::delete_table(const char* name)
{
	enum_sql_command sqlcom = enum_sql_command(thd_sql_command(ha_thd()));
 
        if (sqlcom == SQLCOM_TRUNCATE
            && thd_killed(ha_thd())
            && (m_prebuilt == NULL || m_prebuilt->table->is_temporary())) {
                sqlcom = SQLCOM_DROP_TABLE;
        }
 
	/* SQLCOM_TRUNCATE will be passed via ha_innobase::truncate() only. */
        DBUG_ASSERT(sqlcom != SQLCOM_TRUNCATE);
        return delete_table(name, sqlcom);
}

A possible fix is to set sqlcom in the calling function:

diff --git a/sql/temporary_tables.cc b/sql/temporary_tables.cc
index 1c8af5eaf66..e8dadc46718 100644
--- a/sql/temporary_tables.cc
+++ b/sql/temporary_tables.cc
@@ -489,6 +489,7 @@ bool THD::close_temporary_tables()
   }
 
   DBUG_ASSERT(!rgi_slave);
+  lex->sql_command = SQLCOM_DROP_TABLE;
 
   /*
     Ensure we don't have open HANDLERs for tables we are about to close.

An alternative ought to be to ensure that thd_killed(ha_thd()) holds when the temporary tables are being dropped during client disconnection.

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