Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-26433

assertion: table->get_ref_count() == 0 in dict0dict.cc line 1915

Details

    Description

      step to reproduce:

      CREATE TEMPORARY TABLE v0 ( v1 TEXT ( 15 ) CHAR SET BINARY NOT NULL NOT NULL UNIQUE CHECK ( v1 ) ) REPLACE SELECT NULL AS v3 , 74 AS v2 ;
       SELECT SQL_CALC_FOUND_ROWS * FROM v0 WHERE v1 IN ( SELECT v3 FROM v0 ) LIMIT 16 ;
       DROP PROCEDURE v0 ;
       CREATE TABLE v4 ( v6 INT , v5 INT DEFAULT 27 ) ;
       ROLLBACK TO SAVEPOINT v4 ;
       INSERT INTO v4 VALUES ( + 84 , + 32 , 48 ) ;
      

      report (compiled with ASAN):

      Server version: 10.7.0-MariaDB
      key_buffer_size=134217728
      read_buffer_size=131072
      max_used_connections=1
      max_threads=153
      thread_count=1
      It is possible that mysqld could use up to 
      key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 467956 K  bytes of memory
      Hope that's ok; if not, decrease some variables in the equation.
       
      Thread pointer: 0x62b0000bd218
      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 = 0x7fb65ba7c850 thread_stack 0x5fc00
      sanitizer_common/sanitizer_common_interceptors.inc:4203(__interceptor_backtrace.part.0)[0x7fb67b328c3e]
      mysys/stacktrace.c:213(my_print_stacktrace)[0x55df46af9747]
      sql/signal_handler.cc:222(handle_fatal_signal)[0x55df45ac1120]
      sigaction.c:0(__restore_rt)[0x7fb67ad12870]
      :0(__GI_raise)[0x7fb67a7f1d22]
      :0(__GI_abort)[0x7fb67a7db862]
      include/ut0ut.h:319(ib::logger& ib::logger::operator<< <int>(int const&))[0x55df44f00246]
      dict/dict0dict.cc:1258(dict_sys_t::evict_table_LRU(bool) [clone .cold])[0x55df44f2296e]
      include/dict0dict.h:1578(dict_sys_t::unlock())[0x55df463d955f]
      sql/handler.cc:577(hton_drop_table(handlerton*, char const*))[0x55df45ad0145]
      sql/temporary_tables.cc:703(THD::rm_temporary_table(handlerton*, char const*))[0x55df4594c2c8]
      sql/temporary_tables.cc:1464(THD::free_tmp_table_share(TMP_TABLE_SHARE*, bool))[0x55df4594d237]
      sql/temporary_tables.cc:672(THD::drop_temporary_table(TABLE*, bool*, bool))[0x55df459513f5]
      sql/sql_insert.cc:5203(select_create::abort_result_set())[0x55df452837f5]
      sql/sql_select.cc:563(handle_select(THD*, LEX*, select_result*, unsigned long))[0x55df454f48a5]
      sql/sql_table.cc:11732(Sql_cmd_create_table_like::execute(THD*))[0x55df455d8e27]
      sql/sql_parse.cc:5997(mysql_execute_command(THD*, bool))[0x55df45359180]
      sql/sql_parse.cc:8047(mysql_parse(THD*, char*, unsigned int, Parser_state*))[0x55df453665a1]
      sql/sql_parse.cc:1898(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool))[0x55df4536c60c]
      sql/sql_parse.cc:1406(do_command(THD*, bool))[0x55df4537173d]
      sql/sql_connect.cc:1418(do_handle_one_connection(CONNECT*, bool))[0x55df4572ce57]
      sql/sql_connect.cc:1312(handle_one_connection)[0x55df4572d33d]
      perfschema/pfs.cc:2204(pfs_spawn_thread)[0x55df461bdc2c]
      pthread_create.c:0(start_thread)[0x7fb67ad08259]
      :0(__GI___clone)[0x7fb67a8b35e3]
       
      Trying to get some variables.
      Some pointers may be invalid and cause the dump to abort.
      Query (0x6290000873d0): CREATE TEMPORARY TABLE v0 ( v1 TEXT ( 15 ) CHAR SET BINARY NOT NULL NOT NULL UNIQUE CHECK ( v1 ) ) REPLACE SELECT NULL AS v3 , 74 AS v2
       
      Connection ID (thread ID): 4
      Status: NOT_KILLED
       
      Optimizer switch: index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on,condition_pushdown_from_having=on,not_null_range_scan=off
       
      The manual page at https://mariadb.com/kb/en/how-to-produce-a-full-stack-trace-for-mysqld/ contains
      information that should help you find out what is causing the crash.
      Writing a core file...
      Working directory at /home/fuboat/mariadb-tmp/18
      Resource Limits:
      Limit                     Soft Limit           Hard Limit           Units     
      Max cpu time              unlimited            unlimited            seconds   
      Max file size             unlimited            unlimited            bytes     
      Max data size             unlimited            unlimited            bytes     
      Max stack size            8388608              unlimited            bytes     
      Max core file size        unlimited            unlimited            bytes     
      Max resident set          unlimited            unlimited            bytes     
      Max processes             61608                61608                processes 
      Max open files            524288               524288               files     
      Max locked memory         65536                65536                bytes     
      Max address space         unlimited            unlimited            bytes     
      Max file locks            unlimited            unlimited            locks     
      Max pending signals       61608                61608                signals   
      Max msgqueue size         819200               819200               bytes     
      Max nice priority         0                    0                    
      Max realtime priority     0                    0                    
      Max realtime timeout      unlimited            unlimited            us        
      Core pattern: core
      

      gdb bt:

      Using host libthread_db library "/usr/lib/libthread_db.so.1".
      Core was generated by `/usr/local/mysql/bin//mysqld --port 10018 --datadir=/home/fuboat/mariadb-tmp/18'.
      Program terminated with signal SIGABRT, Aborted.
      #0  0x00007fb67ad0f808 in pthread_kill () from /usr/lib/libpthread.so.0
      #1  0x000055df45ac106b in handle_fatal_signal (sig=<optimized out>) at /experiment/mariadb-server/sql/signal_handler.cc:344
      #2  <signal handler called>
      #3  0x00007fb67a7f1d22 in raise () from /usr/lib/libc.so.6
      #4  0x00007fb67a7db862 in abort () from /usr/lib/libc.so.6
      #5  0x000055df44f00246 in ut_dbg_assertion_failed (expr=expr@entry=0x55df4700bd40 "table->get_ref_count() == 0", file=file@entry=0x55df4700ae60 "/experiment/mariadb-server/storage/innobase/dict/dict0dict.cc", line=line@entry=1890) at /experiment/mariadb-server/storage/innobase/ut/ut0dbg.cc:60
      #6  0x000055df44f2296e in dict_sys_t::remove (this=<optimized out>, this@entry=0x55df478238c0 <dict_sys>, table=0x61700003ff08, lru=<optimized out>, lru@entry=false, keep=<optimized out>, keep@entry=true) at /experiment/mariadb-server/storage/innobase/dict/dict0dict.cc:1890
      #7  0x000055df463d955f in ha_innobase::delete_table (this=<optimized out>, name=<optimized out>) at /experiment/mariadb-server/storage/innobase/handler/ha_innodb.cc:13360
      #8  0x000055df45ad0145 in hton_drop_table (hton=<optimized out>, path=<optimized out>) at /experiment/mariadb-server/sql/handler.cc:576
      #9  0x000055df4594c2c8 in THD::rm_temporary_table (this=<optimized out>, base=<optimized out>, path=0x61a000061d48 "/tmp/#sql-temptable-3021ca-4-0") at /experiment/mariadb-server/sql/temporary_tables.cc:703
      #10 0x000055df4594d237 in THD::free_tmp_table_share (this=<optimized out>, share=0x61a000061898, delete_table=<optimized out>) at /experiment/mariadb-server/sql/temporary_tables.cc:1462
      #11 0x000055df459513f5 in THD::drop_temporary_table (this=0x62b0000bd218, table=<optimized out>, is_trans=is_trans@entry=0x0, delete_table=delete_table@entry=true) at /experiment/mariadb-server/sql/temporary_tables.cc:669
      #12 0x000055df451da338 in drop_open_table (thd=<optimized out>, table=<optimized out>, db_name=<optimized out>, table_name=<optimized out>) at /experiment/mariadb-server/sql/sql_base.cc:1355
      #13 0x000055df452837f5 in select_create::abort_result_set (this=0x6290000890c8) at /experiment/mariadb-server/sql/sql_insert.cc:5202
      #14 0x000055df454f48a5 in handle_select (thd=thd@entry=0x62b0000bd218, lex=lex@entry=0x62b0000c12f8, result=result@entry=0x6290000890c8, setup_tables_done_option=setup_tables_done_option@entry=0) at /experiment/mariadb-server/sql/sql_select.cc:563
      #15 0x000055df455d8e27 in Sql_cmd_create_table_like::execute (this=<optimized out>, thd=0x62b0000bd218) at /experiment/mariadb-server/sql/sql_table.cc:11732
      #16 0x000055df45359180 in mysql_execute_command (thd=0x62b0000bd218, is_called_from_prepared_stmt=<optimized out>) at /experiment/mariadb-server/sql/sql_parse.cc:5997
      #17 0x000055df453665a1 in mysql_parse (thd=0x62b0000bd218, rawbuf=<optimized out>, length=<optimized out>, parser_state=<optimized out>) at /experiment/mariadb-server/sql/sql_parse.cc:8030
      #18 0x000055df4536c60c in dispatch_command (command=<optimized out>, thd=0x62b0000bd218, packet=<optimized out>, packet_length=<optimized out>, blocking=<optimized out>) at /experiment/mariadb-server/sql/sql_parse.cc:1896
      #19 0x000055df4537173d in do_command (thd=0x62b0000bd218, blocking=blocking@entry=true) at /experiment/mariadb-server/sql/sql_parse.cc:1404
      #20 0x000055df4572ce57 in do_handle_one_connection (connect=<optimized out>, put_in_cache=<optimized out>) at /experiment/mariadb-server/sql/sql_connect.cc:1418
      #21 0x000055df4572d33d in handle_one_connection (arg=arg@entry=0x6080000023b8) at /experiment/mariadb-server/sql/sql_connect.cc:1312
      #22 0x000055df461bdc2c in pfs_spawn_thread (arg=0x617000005b98) at /experiment/mariadb-server/storage/perfschema/pfs.cc:2201
      #23 0x00007fb67ad08259 in start_thread () from /usr/lib/libpthread.so.0
      #24 0x00007fb67a8b35e3 in clone () from /usr/lib/libc.so.6
      

      Attachments

        Issue Links

          Activity

            alice Alice Sherepa added a comment -

            Thanks for the report!
            Repeatable on 10.5, 10.6

            --source include/have_innodb.inc
             
            CREATE TEMPORARY TABLE t1 (i TEXT(15) NOT NULL UNIQUE CHECK (i)) engine=innodb
              REPLACE SELECT NULL AS a;
            

            10.5 87ff4ba7c874ccb8a5b1105

            2021-08-27 15:56:14 0x7f41c2918700  InnoDB: Assertion failure in file /10.5/src/storage/innobase/dict/dict0dict.cc line 1915
            InnoDB: Failing assertion: table->get_ref_count() == 0
            InnoDB: We intentionally generate a memory trap.
            InnoDB: Submit a detailed bug report to https://jira.mariadb.org/
            InnoDB: If you get repeated assertion failures or crashes, even
            InnoDB: immediately after the mysqld startup, there may be
            InnoDB: corruption in the InnoDB tablespace. Please refer to
            InnoDB: https://mariadb.com/kb/en/library/innodb-recovery-modes/
            InnoDB: about forcing recovery.
            210827 15:56:14 [ERROR] mysqld got signal 6 ;
             
            linux/raise.c:51(__GI_raise)[0x7f41d1cef18b]
            stdlib/abort.c:81(__GI_abort)[0x7f41d1cce859]
            ut/ut0dbg.cc:60(_sub_D_00099_0)[0x555e28c31207]
            dict/dict0dict.cc:1916(dict_sys_t::remove(dict_table_t*, bool, bool))[0x555e28d99b6a]
            row/row0mysql.cc:3370(row_drop_table_for_mysql(char const*, trx_t*, enum_sql_command, bool, bool))[0x555e28a7a236]
            handler/ha_innodb.cc:13302(ha_innobase::delete_table(char const*, enum_sql_command))[0x555e2871ac97]
            handler/ha_innodb.cc:13430(ha_innobase::delete_table(char const*))[0x555e286e4c83]
            sql/handler.cc:564(hton_drop_table(handlerton*, char const*))[0x555e27b7a8f1]
            sql/temporary_tables.cc:703(THD::rm_temporary_table(handlerton*, char const*))[0x555e279cf76e]
            sql/temporary_tables.cc:1464(THD::free_tmp_table_share(TMP_TABLE_SHARE*, bool))[0x555e279d4814]
            sql/temporary_tables.cc:672(THD::drop_temporary_table(TABLE*, bool*, bool))[0x555e279cf35f]
            sql/sql_base.cc:1353(drop_open_table(THD*, TABLE*, st_mysql_const_lex_string const*, st_mysql_const_lex_string const*))[0x555e271c4f40]
            sql/sql_insert.cc:5130(select_create::abort_result_set())[0x555e272cc846]
            sql/sql_select.cc:463(handle_select(THD*, LEX*, select_result*, unsigned long))[0x555e274167fe]
            sql/sql_table.cc:12158(Sql_cmd_create_table_like::execute(THD*))[0x555e2762d86a]
            sql/sql_parse.cc:6056(mysql_execute_command(THD*))[0x555e2737c88c]
            sql/sql_parse.cc:8100(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x555e2738a154]
            sql/sql_parse.cc:1894(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x555e2735ffec]
            sql/sql_parse.cc:1370(do_command(THD*))[0x555e2735c92b]
            sql/sql_connect.cc:1418(do_handle_one_connection(CONNECT*, bool))[0x555e277a6887]
            sql/sql_connect.cc:1314(handle_one_connection)[0x555e277a60a0]
            perfschema/pfs.cc:2203(pfs_spawn_thread)[0x555e284c2987]
            nptl/pthread_create.c:478(start_thread)[0x7f41d21f6609]
            x86_64/clone.S:97(__GI___clone)[0x7f41d1dcb293]
             
            Query (0x62b0000a12a8): CREATE TEMPORARY TABLE t1 (i TEXT(15) NOT NULL UNIQUE CHECK (i)) engine=innodb
            REPLACE SELECT NULL AS a
            

            alice Alice Sherepa added a comment - Thanks for the report! Repeatable on 10.5, 10.6 --source include/have_innodb.inc   CREATE TEMPORARY TABLE t1 (i TEXT(15) NOT NULL UNIQUE CHECK (i)) engine=innodb REPLACE SELECT NULL AS a; 10.5 87ff4ba7c874ccb8a5b1105 2021-08-27 15:56:14 0x7f41c2918700 InnoDB: Assertion failure in file /10.5/src/storage/innobase/dict/dict0dict.cc line 1915 InnoDB: Failing assertion: table->get_ref_count() == 0 InnoDB: We intentionally generate a memory trap. InnoDB: Submit a detailed bug report to https://jira.mariadb.org/ InnoDB: If you get repeated assertion failures or crashes, even InnoDB: immediately after the mysqld startup, there may be InnoDB: corruption in the InnoDB tablespace. Please refer to InnoDB: https://mariadb.com/kb/en/library/innodb-recovery-modes/ InnoDB: about forcing recovery. 210827 15:56:14 [ERROR] mysqld got signal 6 ;   linux/raise.c:51(__GI_raise)[0x7f41d1cef18b] stdlib/abort.c:81(__GI_abort)[0x7f41d1cce859] ut/ut0dbg.cc:60(_sub_D_00099_0)[0x555e28c31207] dict/dict0dict.cc:1916(dict_sys_t::remove(dict_table_t*, bool, bool))[0x555e28d99b6a] row/row0mysql.cc:3370(row_drop_table_for_mysql(char const*, trx_t*, enum_sql_command, bool, bool))[0x555e28a7a236] handler/ha_innodb.cc:13302(ha_innobase::delete_table(char const*, enum_sql_command))[0x555e2871ac97] handler/ha_innodb.cc:13430(ha_innobase::delete_table(char const*))[0x555e286e4c83] sql/handler.cc:564(hton_drop_table(handlerton*, char const*))[0x555e27b7a8f1] sql/temporary_tables.cc:703(THD::rm_temporary_table(handlerton*, char const*))[0x555e279cf76e] sql/temporary_tables.cc:1464(THD::free_tmp_table_share(TMP_TABLE_SHARE*, bool))[0x555e279d4814] sql/temporary_tables.cc:672(THD::drop_temporary_table(TABLE*, bool*, bool))[0x555e279cf35f] sql/sql_base.cc:1353(drop_open_table(THD*, TABLE*, st_mysql_const_lex_string const*, st_mysql_const_lex_string const*))[0x555e271c4f40] sql/sql_insert.cc:5130(select_create::abort_result_set())[0x555e272cc846] sql/sql_select.cc:463(handle_select(THD*, LEX*, select_result*, unsigned long))[0x555e274167fe] sql/sql_table.cc:12158(Sql_cmd_create_table_like::execute(THD*))[0x555e2762d86a] sql/sql_parse.cc:6056(mysql_execute_command(THD*))[0x555e2737c88c] sql/sql_parse.cc:8100(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x555e2738a154] sql/sql_parse.cc:1894(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x555e2735ffec] sql/sql_parse.cc:1370(do_command(THD*))[0x555e2735c92b] sql/sql_connect.cc:1418(do_handle_one_connection(CONNECT*, bool))[0x555e277a6887] sql/sql_connect.cc:1314(handle_one_connection)[0x555e277a60a0] perfschema/pfs.cc:2203(pfs_spawn_thread)[0x555e284c2987] nptl/pthread_create.c:478(start_thread)[0x7f41d21f6609] x86_64/clone.S:97(__GI___clone)[0x7f41d1dcb293]   Query (0x62b0000a12a8): CREATE TEMPORARY TABLE t1 (i TEXT(15) NOT NULL UNIQUE CHECK (i)) engine=innodb REPLACE SELECT NULL AS a

            InnoDB is only the messenger here. I checked ./mtr --rr of the described SQL preceded with the following:

            --source include/have_innodb.inc
            set default_storage_engine=innodb;
            

            In rr replay on an AMD64 system, I executed

            continue
            # SIGABRT here
            frame 4
            watch -l table->n_ref_count
            disable 1
            break ha_innobase::create
            run
            disable 2
            enable 1
            continue
            …
            

            to find all modifications of the reference-count. After the table was created, I see the reference-count being incremented in:

            #3  0x00005607bd1a4638 in handler::ha_open (this=0x7f7720178bd0, table_arg=table_arg@entry=0x7f77201787c8, name=0x7f77200a1cc8 "/dev/shm/10.6/mysql-test/var/tmp/mysqld.1/#sql-temptable-16ba73-4-e", mode=2, 
                test_if_locked=test_if_locked@entry=4114, mem_root=mem_root@entry=0x0, partitions_to_open=0x0) at /mariadb/10.6/sql/handler.cc:3313
            #4  0x00005607bcfe3145 in open_table_from_share (thd=thd@entry=0x7f7720001a28, share=share@entry=0x7f77200a1718, alias=alias@entry=0x7f7740b5e3a0, db_stat=db_stat@entry=1, prgflag=prgflag@entry=8, ha_open_flags=4114, 
                outparam=0x7f77201787c8, is_create_table=false, partitions_to_open=0x0) at /mariadb/10.6/sql/table.cc:4327
            #5  0x00005607bd101da8 in THD::open_temporary_table (this=this@entry=0x7f7720001a28, share=share@entry=0x7f77200a1718, alias_arg=alias_arg@entry=0x7f7720015020 "v0") at /mariadb/10.6/sql/temporary_tables.cc:1117
            #6  0x00005607bd1039d8 in THD::create_and_open_tmp_table (this=this@entry=0x7f7720001a28, frm=frm@entry=0x7f7740b5ec40, path=<optimized out>, db=<optimized out>, table_name=0x7f7720015020 "v0", 
                open_internal_tables=open_internal_tables@entry=false) at /mariadb/10.6/sql/temporary_tables.cc:74
            #7  0x00005607bcfa6ca0 in create_table_impl (thd=thd@entry=0x7f7720001a28, ddl_log_state_create=0x0, ddl_log_state_create@entry=0x7f7720016b40, ddl_log_state_rm=0x0, ddl_log_state_rm@entry=0x7f7720016b60, orig_db=
                  @0x7f7720015070: {str = 0x7f7720015738 "test", length = 4}, orig_table_name=@0x7f7720015080: {str = 0x7f7720015020 "v0", length = 2}, db=@0x7f7720015070: {str = 0x7f7720015738 "test", length = 4}, table_name=
                  @0x7f7720015080: {str = 0x7f7720015020 "v0", length = 2}, path=@0x7f7740b5ec30: {str = 0x7f7740b5ec50 "/dev/shm/10.6/mysql-test/var/tmp/mysqld.1/#sql-temptable-16ba73-4-e", length = 67}, options=<optimized out>, 
                create_info=0x7f7740b5fd20, alter_info=0x7f7740b5fc30, create_table_mode=2, is_trans=0x0, key_info=0x7f7740b5ec28, key_count=0x7f7740b5ec24, frm=0x7f7740b5ec40) at /mariadb/10.6/sql/sql_table.cc:4461
            #8  0x00005607bcfa6f38 in mysql_create_table_no_lock (thd=thd@entry=0x7f7720001a28, ddl_log_state_create=ddl_log_state_create@entry=0x7f7720016b40, ddl_log_state_rm=ddl_log_state_rm@entry=0x7f7720016b60, db=0x7f7720015070, 
                table_name=0x7f7720015080, create_info=0x7f7740b5fd20, alter_info=0x7f7740b5fc30, is_trans=0x0, create_table_mode=2, table_list=0x7f7720015058) at /mariadb/10.6/sql/sql_table.cc:4546
            #9  0x00005607bce8ca00 in select_create::create_table_from_items (this=this@entry=0x7f7720016a38, thd=0x7f7720001a28, items=items@entry=0x7f7740b5f940, lock=lock@entry=0x7f7740b5f938, hooks=hooks@entry=0x7f7740b5f960)
                at /mariadb/10.6/sql/sql_insert.cc:4498
            #10 0x00005607bce8cfb5 in select_create::prepare (this=0x7f7720016a38, _values=<optimized out>, u=0x7f7720005b90) at /mariadb/10.6/sql/sql_insert.cc:4700
            #11 0x00005607bcf389f4 in JOIN::prepare (this=this@entry=0x7f7720016b80, tables_init=tables_init@entry=0x0, conds_init=conds_init@entry=0x0, og_num=og_num@entry=0, order_init=order_init@entry=0x0, 
                skip_order_by=skip_order_by@entry=false, group_init=<optimized out>, having_init=<optimized out>, proc_param_init=<optimized out>, select_lex_arg=<optimized out>, unit_arg=<optimized out>) at /mariadb/10.6/sql/sql_select.cc:1684
            #12 0x00005607bcf50945 in mysql_select (thd=thd@entry=0x7f7720001a28, tables=0x0, fields=@0x7f7720015d18: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x7f7720015f68, last = 0x7f7720016008, elements = 2}, <No data fields>}, 
                conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2201171004160, result=0x7f7720016a38, unit=0x7f7720005b90, select_lex=0x7f7720015a78) at /mariadb/10.6/sql/sql_select.cc:4969
            #13 0x00005607bcf50be9 in handle_select (thd=thd@entry=0x7f7720001a28, lex=lex@entry=0x7f7720005ac8, result=result@entry=0x7f7720016a38, setup_tables_done_option=setup_tables_done_option@entry=0) at /mariadb/10.6/sql/sql_select.cc:545
            #14 0x00005607bcfa90cf in Sql_cmd_create_table_like::execute (this=0x7f7720014ff8, thd=0x7f7720001a28) at /mariadb/10.6/sql/sql_table.cc:11737
            #15 0x00005607bced826d in mysql_execute_command (thd=thd@entry=0x7f7720001a28, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /mariadb/10.6/sql/sql_parse.cc:5997
            #16 0x00005607bced9299 in mysql_parse (thd=thd@entry=0x7f7720001a28, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x7f7740b604c0) at /mariadb/10.6/sql/sql_parse.cc:8030
            #17 0x00005607bcedb7fc in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x7f7720001a28, packet=0x7f7740b604c0 "\377\377\377\377", 
                packet@entry=0x7f7720087d49 "CREATE TEMPORARY TABLE v0 ( v1 TEXT ( 15 ) CHAR SET BINARY NOT NULL NOT NULL UNIQUE CHECK ( v1 ) ) REPLACE SELECT NULL AS v3 , 74 AS v2 ", packet_length=packet_length@entry=136, 
                blocking=blocking@entry=true) at /mariadb/10.6/sql/sql_parse.cc:1896
            

            and

            #3  0x00005607bd1a4638 in handler::ha_open (this=this@entry=0x7f77200183a0, table_arg=0x7f77201787c8, name=name@entry=0x7f7720112bf0 "mysqld.1/#sql-temptable-16ba73-4-e", mode=1, test_if_locked=test_if_locked@entry=2, 
                mem_root=mem_root@entry=0x7f7720007660, partitions_to_open=0x0) at /mariadb/10.6/sql/handler.cc:3313
            #4  0x00005607bd1a4a79 in handler::clone (this=this@entry=0x7f7720178bd0, name=0x7f7720112bf0 "mysqld.1/#sql-temptable-16ba73-4-e", mem_root=0x7f7720007660) at /mariadb/10.6/sql/handler.cc:3173
            #5  0x00005607bd4cc359 in ha_innobase::clone (this=0x7f7720178bd0, name=<optimized out>, mem_root=<optimized out>) at /mariadb/10.6/storage/innobase/handler/ha_innodb.cc:6216
            #6  0x00005607bd1adcb8 in handler::create_lookup_handler (this=this@entry=0x7f7720178bd0) at /mariadb/10.6/sql/handler.cc:3196
            #7  0x00005607bd1af084 in handler::prepare_for_insert (this=0x7f7720178bd0, do_create=<optimized out>) at /mariadb/10.6/sql/handler.cc:7484
            #8  0x00005607bce8d344 in select_create::prepare (this=0x7f7720016a38, _values=<optimized out>, u=<optimized out>) at /mariadb/10.6/sql/sql_insert.cc:4773
            #9  0x00005607bcf389f4 in JOIN::prepare (this=this@entry=0x7f7720016b80, tables_init=tables_init@entry=0x0, conds_init=conds_init@entry=0x0, og_num=og_num@entry=0, order_init=order_init@entry=0x0, 
                skip_order_by=skip_order_by@entry=false, group_init=<optimized out>, having_init=<optimized out>, proc_param_init=<optimized out>, select_lex_arg=<optimized out>, unit_arg=<optimized out>) at /mariadb/10.6/sql/sql_select.cc:1684
            #10 0x00005607bcf50945 in mysql_select (thd=thd@entry=0x7f7720001a28, tables=0x0, fields=@0x7f7720015d18: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x7f7720015f68, last = 0x7f7720016008, elements = 2}, <No data fields>}, 
                conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2201171004160, result=0x7f7720016a38, unit=0x7f7720005b90, select_lex=0x7f7720015a78) at /mariadb/10.6/sql/sql_select.cc:4969
            #11 0x00005607bcf50be9 in handle_select (thd=thd@entry=0x7f7720001a28, lex=lex@entry=0x7f7720005ac8, result=result@entry=0x7f7720016a38, setup_tables_done_option=setup_tables_done_option@entry=0) at /mariadb/10.6/sql/sql_select.cc:545
            #12 0x00005607bcfa90cf in Sql_cmd_create_table_like::execute (this=0x7f7720014ff8, thd=0x7f7720001a28) at /mariadb/10.6/sql/sql_table.cc:11737
            #13 0x00005607bced826d in mysql_execute_command (thd=thd@entry=0x7f7720001a28, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /mariadb/10.6/sql/sql_parse.cc:5997
            #14 0x00005607bced9299 in mysql_parse (thd=thd@entry=0x7f7720001a28, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x7f7740b604c0) at /mariadb/10.6/sql/sql_parse.cc:8030
            #15 0x00005607bcedb7fc in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x7f7720001a28, packet=0x7f7740b604c0 "\377\377\377\377", 
                packet@entry=0x7f7720087d49 "CREATE TEMPORARY TABLE v0 ( v1 TEXT ( 15 ) CHAR SET BINARY NOT NULL NOT NULL UNIQUE CHECK ( v1 ) ) REPLACE SELECT NULL AS v3 , 74 AS v2 ", packet_length=packet_length@entry=136, 
                blocking=blocking@entry=true) at /mariadb/10.6/sql/sql_parse.cc:1896
            

            After this, the SQL layer will close only one of the 2 handles that it opened:

            #4  0x00005607bd1a4464 in handler::ha_close (this=0x7f7720178bd0) at /mariadb/10.6/sql/handler.cc:3382
            #5  0x00005607bcfd9958 in closefrm (table=table@entry=0x7f77201787c8) at /mariadb/10.6/sql/table.cc:4431
            #6  0x00005607bd101fe7 in THD::close_temporary_table (this=this@entry=0x7f7720001a28, table=table@entry=0x7f77201787c8) at /mariadb/10.6/sql/temporary_tables.cc:1238
            #7  0x00005607bd102b12 in THD::free_temporary_table (this=this@entry=0x7f7720001a28, table=table@entry=0x7f77201787c8) at /mariadb/10.6/sql/temporary_tables.cc:1488
            #8  0x00005607bd10385e in THD::drop_temporary_table (this=0x7f7720001a28, table=<optimized out>, is_trans=is_trans@entry=0x0, delete_table=delete_table@entry=true) at /mariadb/10.6/sql/temporary_tables.cc:660
            #9  0x00005607bce47e56 in drop_open_table (thd=0x7f7720001a28, table=0x7f77201787c8, db_name=<optimized out>, table_name=<optimized out>) at /mariadb/10.6/sql/sql_base.cc:1355
            #10 0x00005607bce869be in select_create::abort_result_set (this=0x7f7720016a38) at /mariadb/10.6/sql/sql_insert.cc:5202
            #11 0x00005607bcf50c40 in handle_select (thd=thd@entry=0x7f7720001a28, lex=lex@entry=0x7f7720005ac8, result=result@entry=0x7f7720016a38, setup_tables_done_option=setup_tables_done_option@entry=0) at /mariadb/10.6/sql/sql_select.cc:563
            #12 0x00005607bcfa90cf in Sql_cmd_create_table_like::execute (this=0x7f7720014ff8, thd=0x7f7720001a28) at /mariadb/10.6/sql/sql_table.cc:11737
            #13 0x00005607bced826d in mysql_execute_command (thd=thd@entry=0x7f7720001a28, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /mariadb/10.6/sql/sql_parse.cc:5997
            #14 0x00005607bced9299 in mysql_parse (thd=thd@entry=0x7f7720001a28, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x7f7740b604c0) at /mariadb/10.6/sql/sql_parse.cc:8030
            #15 0x00005607bcedb7fc in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x7f7720001a28, packet=0x7f7740b604c0 "\377\377\377\377", 
                packet@entry=0x7f7720087d49 "CREATE TEMPORARY TABLE v0 ( v1 TEXT ( 15 ) CHAR SET BINARY NOT NULL NOT NULL UNIQUE CHECK ( v1 ) ) REPLACE SELECT NULL AS v3 , 74 AS v2 ", packet_length=packet_length@entry=136, 
                blocking=blocking@entry=true) at /mariadb/10.6/sql/sql_parse.cc:1896
            

            The assertion will fail, because the table is being dropped even though a handle remains open:

            #4  0x00005607bd4f2776 in ha_innobase::delete_table (this=<optimized out>, name=0x7f77200a1cc8 "/dev/shm/10.6/mysql-test/var/tmp/mysqld.1/#sql-temptable-16ba73-4-e") at /mariadb/10.6/storage/innobase/handler/ha_innodb.cc:13399
            #5  0x00005607bd1a42e2 in hton_drop_table (hton=<optimized out>, path=<optimized out>) at /mariadb/10.6/sql/handler.cc:576
            #6  0x00005607bd101ad7 in THD::rm_temporary_table (this=<optimized out>, base=0x5607bfbb6c48, path=0x7f77200a1cc8 "/dev/shm/10.6/mysql-test/var/tmp/mysqld.1/#sql-temptable-16ba73-4-e") at /mariadb/10.6/sql/temporary_tables.cc:703
            #7  0x00005607bd102175 in THD::free_tmp_table_share (this=this@entry=0x7f7720001a28, share=share@entry=0x7f77200a1718, delete_table=delete_table@entry=true) at /mariadb/10.6/sql/temporary_tables.cc:1462
            #8  0x00005607bd1038df in THD::drop_temporary_table (this=0x7f7720001a28, table=<optimized out>, is_trans=is_trans@entry=0x0, delete_table=delete_table@entry=true) at /mariadb/10.6/sql/temporary_tables.cc:669
            #9  0x00005607bce47e56 in drop_open_table (thd=0x7f7720001a28, table=0x7f77201787c8, db_name=<optimized out>, table_name=<optimized out>) at /mariadb/10.6/sql/sql_base.cc:1355
            #10 0x00005607bce869be in select_create::abort_result_set (this=0x7f7720016a38) at /mariadb/10.6/sql/sql_insert.cc:5202
            #11 0x00005607bcf50c40 in handle_select (thd=thd@entry=0x7f7720001a28, lex=lex@entry=0x7f7720005ac8, result=result@entry=0x7f7720016a38, setup_tables_done_option=setup_tables_done_option@entry=0) at /mariadb/10.6/sql/sql_select.cc:563
            #12 0x00005607bcfa90cf in Sql_cmd_create_table_like::execute (this=0x7f7720014ff8, thd=0x7f7720001a28) at /mariadb/10.6/sql/sql_table.cc:11737
            #13 0x00005607bced826d in mysql_execute_command (thd=thd@entry=0x7f7720001a28, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /mariadb/10.6/sql/sql_parse.cc:5997
            #14 0x00005607bced9299 in mysql_parse (thd=thd@entry=0x7f7720001a28, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x7f7740b604c0) at /mariadb/10.6/sql/sql_parse.cc:8030
            #15 0x00005607bcedb7fc in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x7f7720001a28, packet=0x7f7740b604c0 "\377\377\377\377", 
                packet@entry=0x7f7720087d49 "CREATE TEMPORARY TABLE v0 ( v1 TEXT ( 15 ) CHAR SET BINARY NOT NULL NOT NULL UNIQUE CHECK ( v1 ) ) REPLACE SELECT NULL AS v3 , 74 AS v2 ", packet_length=packet_length@entry=136, 
                blocking=blocking@entry=true) at /mariadb/10.6/sql/sql_parse.cc:1896
            

            Related note: It would be great if the SQL layer did not force storage engines to memorize temporary tables by a generated name string (MDEV-17805).

            If I remember correctly, it was in MariaDB 10.3 where we started to allow multiple handles to a temporary table in a query. It may be that older InnoDB versions are missing an equivalent assertion.

            marko Marko Mäkelä added a comment - InnoDB is only the messenger here. I checked ./mtr --rr of the described SQL preceded with the following: --source include/have_innodb.inc set default_storage_engine=innodb; In rr replay on an AMD64 system, I executed continue # SIGABRT here frame 4 watch -l table->n_ref_count disable 1 break ha_innobase::create run disable 2 enable 1 continue … to find all modifications of the reference-count. After the table was created, I see the reference-count being incremented in: #3 0x00005607bd1a4638 in handler::ha_open (this=0x7f7720178bd0, table_arg=table_arg@entry=0x7f77201787c8, name=0x7f77200a1cc8 "/dev/shm/10.6/mysql-test/var/tmp/mysqld.1/#sql-temptable-16ba73-4-e", mode=2, test_if_locked=test_if_locked@entry=4114, mem_root=mem_root@entry=0x0, partitions_to_open=0x0) at /mariadb/10.6/sql/handler.cc:3313 #4 0x00005607bcfe3145 in open_table_from_share (thd=thd@entry=0x7f7720001a28, share=share@entry=0x7f77200a1718, alias=alias@entry=0x7f7740b5e3a0, db_stat=db_stat@entry=1, prgflag=prgflag@entry=8, ha_open_flags=4114, outparam=0x7f77201787c8, is_create_table=false, partitions_to_open=0x0) at /mariadb/10.6/sql/table.cc:4327 #5 0x00005607bd101da8 in THD::open_temporary_table (this=this@entry=0x7f7720001a28, share=share@entry=0x7f77200a1718, alias_arg=alias_arg@entry=0x7f7720015020 "v0") at /mariadb/10.6/sql/temporary_tables.cc:1117 #6 0x00005607bd1039d8 in THD::create_and_open_tmp_table (this=this@entry=0x7f7720001a28, frm=frm@entry=0x7f7740b5ec40, path=<optimized out>, db=<optimized out>, table_name=0x7f7720015020 "v0", open_internal_tables=open_internal_tables@entry=false) at /mariadb/10.6/sql/temporary_tables.cc:74 #7 0x00005607bcfa6ca0 in create_table_impl (thd=thd@entry=0x7f7720001a28, ddl_log_state_create=0x0, ddl_log_state_create@entry=0x7f7720016b40, ddl_log_state_rm=0x0, ddl_log_state_rm@entry=0x7f7720016b60, orig_db= @0x7f7720015070: {str = 0x7f7720015738 "test", length = 4}, orig_table_name=@0x7f7720015080: {str = 0x7f7720015020 "v0", length = 2}, db=@0x7f7720015070: {str = 0x7f7720015738 "test", length = 4}, table_name= @0x7f7720015080: {str = 0x7f7720015020 "v0", length = 2}, path=@0x7f7740b5ec30: {str = 0x7f7740b5ec50 "/dev/shm/10.6/mysql-test/var/tmp/mysqld.1/#sql-temptable-16ba73-4-e", length = 67}, options=<optimized out>, create_info=0x7f7740b5fd20, alter_info=0x7f7740b5fc30, create_table_mode=2, is_trans=0x0, key_info=0x7f7740b5ec28, key_count=0x7f7740b5ec24, frm=0x7f7740b5ec40) at /mariadb/10.6/sql/sql_table.cc:4461 #8 0x00005607bcfa6f38 in mysql_create_table_no_lock (thd=thd@entry=0x7f7720001a28, ddl_log_state_create=ddl_log_state_create@entry=0x7f7720016b40, ddl_log_state_rm=ddl_log_state_rm@entry=0x7f7720016b60, db=0x7f7720015070, table_name=0x7f7720015080, create_info=0x7f7740b5fd20, alter_info=0x7f7740b5fc30, is_trans=0x0, create_table_mode=2, table_list=0x7f7720015058) at /mariadb/10.6/sql/sql_table.cc:4546 #9 0x00005607bce8ca00 in select_create::create_table_from_items (this=this@entry=0x7f7720016a38, thd=0x7f7720001a28, items=items@entry=0x7f7740b5f940, lock=lock@entry=0x7f7740b5f938, hooks=hooks@entry=0x7f7740b5f960) at /mariadb/10.6/sql/sql_insert.cc:4498 #10 0x00005607bce8cfb5 in select_create::prepare (this=0x7f7720016a38, _values=<optimized out>, u=0x7f7720005b90) at /mariadb/10.6/sql/sql_insert.cc:4700 #11 0x00005607bcf389f4 in JOIN::prepare (this=this@entry=0x7f7720016b80, tables_init=tables_init@entry=0x0, conds_init=conds_init@entry=0x0, og_num=og_num@entry=0, order_init=order_init@entry=0x0, skip_order_by=skip_order_by@entry=false, group_init=<optimized out>, having_init=<optimized out>, proc_param_init=<optimized out>, select_lex_arg=<optimized out>, unit_arg=<optimized out>) at /mariadb/10.6/sql/sql_select.cc:1684 #12 0x00005607bcf50945 in mysql_select (thd=thd@entry=0x7f7720001a28, tables=0x0, fields=@0x7f7720015d18: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x7f7720015f68, last = 0x7f7720016008, elements = 2}, <No data fields>}, conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2201171004160, result=0x7f7720016a38, unit=0x7f7720005b90, select_lex=0x7f7720015a78) at /mariadb/10.6/sql/sql_select.cc:4969 #13 0x00005607bcf50be9 in handle_select (thd=thd@entry=0x7f7720001a28, lex=lex@entry=0x7f7720005ac8, result=result@entry=0x7f7720016a38, setup_tables_done_option=setup_tables_done_option@entry=0) at /mariadb/10.6/sql/sql_select.cc:545 #14 0x00005607bcfa90cf in Sql_cmd_create_table_like::execute (this=0x7f7720014ff8, thd=0x7f7720001a28) at /mariadb/10.6/sql/sql_table.cc:11737 #15 0x00005607bced826d in mysql_execute_command (thd=thd@entry=0x7f7720001a28, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /mariadb/10.6/sql/sql_parse.cc:5997 #16 0x00005607bced9299 in mysql_parse (thd=thd@entry=0x7f7720001a28, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x7f7740b604c0) at /mariadb/10.6/sql/sql_parse.cc:8030 #17 0x00005607bcedb7fc in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x7f7720001a28, packet=0x7f7740b604c0 "\377\377\377\377", packet@entry=0x7f7720087d49 "CREATE TEMPORARY TABLE v0 ( v1 TEXT ( 15 ) CHAR SET BINARY NOT NULL NOT NULL UNIQUE CHECK ( v1 ) ) REPLACE SELECT NULL AS v3 , 74 AS v2 ", packet_length=packet_length@entry=136, blocking=blocking@entry=true) at /mariadb/10.6/sql/sql_parse.cc:1896 and #3 0x00005607bd1a4638 in handler::ha_open (this=this@entry=0x7f77200183a0, table_arg=0x7f77201787c8, name=name@entry=0x7f7720112bf0 "mysqld.1/#sql-temptable-16ba73-4-e", mode=1, test_if_locked=test_if_locked@entry=2, mem_root=mem_root@entry=0x7f7720007660, partitions_to_open=0x0) at /mariadb/10.6/sql/handler.cc:3313 #4 0x00005607bd1a4a79 in handler::clone (this=this@entry=0x7f7720178bd0, name=0x7f7720112bf0 "mysqld.1/#sql-temptable-16ba73-4-e", mem_root=0x7f7720007660) at /mariadb/10.6/sql/handler.cc:3173 #5 0x00005607bd4cc359 in ha_innobase::clone (this=0x7f7720178bd0, name=<optimized out>, mem_root=<optimized out>) at /mariadb/10.6/storage/innobase/handler/ha_innodb.cc:6216 #6 0x00005607bd1adcb8 in handler::create_lookup_handler (this=this@entry=0x7f7720178bd0) at /mariadb/10.6/sql/handler.cc:3196 #7 0x00005607bd1af084 in handler::prepare_for_insert (this=0x7f7720178bd0, do_create=<optimized out>) at /mariadb/10.6/sql/handler.cc:7484 #8 0x00005607bce8d344 in select_create::prepare (this=0x7f7720016a38, _values=<optimized out>, u=<optimized out>) at /mariadb/10.6/sql/sql_insert.cc:4773 #9 0x00005607bcf389f4 in JOIN::prepare (this=this@entry=0x7f7720016b80, tables_init=tables_init@entry=0x0, conds_init=conds_init@entry=0x0, og_num=og_num@entry=0, order_init=order_init@entry=0x0, skip_order_by=skip_order_by@entry=false, group_init=<optimized out>, having_init=<optimized out>, proc_param_init=<optimized out>, select_lex_arg=<optimized out>, unit_arg=<optimized out>) at /mariadb/10.6/sql/sql_select.cc:1684 #10 0x00005607bcf50945 in mysql_select (thd=thd@entry=0x7f7720001a28, tables=0x0, fields=@0x7f7720015d18: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x7f7720015f68, last = 0x7f7720016008, elements = 2}, <No data fields>}, conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2201171004160, result=0x7f7720016a38, unit=0x7f7720005b90, select_lex=0x7f7720015a78) at /mariadb/10.6/sql/sql_select.cc:4969 #11 0x00005607bcf50be9 in handle_select (thd=thd@entry=0x7f7720001a28, lex=lex@entry=0x7f7720005ac8, result=result@entry=0x7f7720016a38, setup_tables_done_option=setup_tables_done_option@entry=0) at /mariadb/10.6/sql/sql_select.cc:545 #12 0x00005607bcfa90cf in Sql_cmd_create_table_like::execute (this=0x7f7720014ff8, thd=0x7f7720001a28) at /mariadb/10.6/sql/sql_table.cc:11737 #13 0x00005607bced826d in mysql_execute_command (thd=thd@entry=0x7f7720001a28, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /mariadb/10.6/sql/sql_parse.cc:5997 #14 0x00005607bced9299 in mysql_parse (thd=thd@entry=0x7f7720001a28, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x7f7740b604c0) at /mariadb/10.6/sql/sql_parse.cc:8030 #15 0x00005607bcedb7fc in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x7f7720001a28, packet=0x7f7740b604c0 "\377\377\377\377", packet@entry=0x7f7720087d49 "CREATE TEMPORARY TABLE v0 ( v1 TEXT ( 15 ) CHAR SET BINARY NOT NULL NOT NULL UNIQUE CHECK ( v1 ) ) REPLACE SELECT NULL AS v3 , 74 AS v2 ", packet_length=packet_length@entry=136, blocking=blocking@entry=true) at /mariadb/10.6/sql/sql_parse.cc:1896 After this, the SQL layer will close only one of the 2 handles that it opened: #4 0x00005607bd1a4464 in handler::ha_close (this=0x7f7720178bd0) at /mariadb/10.6/sql/handler.cc:3382 #5 0x00005607bcfd9958 in closefrm (table=table@entry=0x7f77201787c8) at /mariadb/10.6/sql/table.cc:4431 #6 0x00005607bd101fe7 in THD::close_temporary_table (this=this@entry=0x7f7720001a28, table=table@entry=0x7f77201787c8) at /mariadb/10.6/sql/temporary_tables.cc:1238 #7 0x00005607bd102b12 in THD::free_temporary_table (this=this@entry=0x7f7720001a28, table=table@entry=0x7f77201787c8) at /mariadb/10.6/sql/temporary_tables.cc:1488 #8 0x00005607bd10385e in THD::drop_temporary_table (this=0x7f7720001a28, table=<optimized out>, is_trans=is_trans@entry=0x0, delete_table=delete_table@entry=true) at /mariadb/10.6/sql/temporary_tables.cc:660 #9 0x00005607bce47e56 in drop_open_table (thd=0x7f7720001a28, table=0x7f77201787c8, db_name=<optimized out>, table_name=<optimized out>) at /mariadb/10.6/sql/sql_base.cc:1355 #10 0x00005607bce869be in select_create::abort_result_set (this=0x7f7720016a38) at /mariadb/10.6/sql/sql_insert.cc:5202 #11 0x00005607bcf50c40 in handle_select (thd=thd@entry=0x7f7720001a28, lex=lex@entry=0x7f7720005ac8, result=result@entry=0x7f7720016a38, setup_tables_done_option=setup_tables_done_option@entry=0) at /mariadb/10.6/sql/sql_select.cc:563 #12 0x00005607bcfa90cf in Sql_cmd_create_table_like::execute (this=0x7f7720014ff8, thd=0x7f7720001a28) at /mariadb/10.6/sql/sql_table.cc:11737 #13 0x00005607bced826d in mysql_execute_command (thd=thd@entry=0x7f7720001a28, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /mariadb/10.6/sql/sql_parse.cc:5997 #14 0x00005607bced9299 in mysql_parse (thd=thd@entry=0x7f7720001a28, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x7f7740b604c0) at /mariadb/10.6/sql/sql_parse.cc:8030 #15 0x00005607bcedb7fc in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x7f7720001a28, packet=0x7f7740b604c0 "\377\377\377\377", packet@entry=0x7f7720087d49 "CREATE TEMPORARY TABLE v0 ( v1 TEXT ( 15 ) CHAR SET BINARY NOT NULL NOT NULL UNIQUE CHECK ( v1 ) ) REPLACE SELECT NULL AS v3 , 74 AS v2 ", packet_length=packet_length@entry=136, blocking=blocking@entry=true) at /mariadb/10.6/sql/sql_parse.cc:1896 The assertion will fail, because the table is being dropped even though a handle remains open: #4 0x00005607bd4f2776 in ha_innobase::delete_table (this=<optimized out>, name=0x7f77200a1cc8 "/dev/shm/10.6/mysql-test/var/tmp/mysqld.1/#sql-temptable-16ba73-4-e") at /mariadb/10.6/storage/innobase/handler/ha_innodb.cc:13399 #5 0x00005607bd1a42e2 in hton_drop_table (hton=<optimized out>, path=<optimized out>) at /mariadb/10.6/sql/handler.cc:576 #6 0x00005607bd101ad7 in THD::rm_temporary_table (this=<optimized out>, base=0x5607bfbb6c48, path=0x7f77200a1cc8 "/dev/shm/10.6/mysql-test/var/tmp/mysqld.1/#sql-temptable-16ba73-4-e") at /mariadb/10.6/sql/temporary_tables.cc:703 #7 0x00005607bd102175 in THD::free_tmp_table_share (this=this@entry=0x7f7720001a28, share=share@entry=0x7f77200a1718, delete_table=delete_table@entry=true) at /mariadb/10.6/sql/temporary_tables.cc:1462 #8 0x00005607bd1038df in THD::drop_temporary_table (this=0x7f7720001a28, table=<optimized out>, is_trans=is_trans@entry=0x0, delete_table=delete_table@entry=true) at /mariadb/10.6/sql/temporary_tables.cc:669 #9 0x00005607bce47e56 in drop_open_table (thd=0x7f7720001a28, table=0x7f77201787c8, db_name=<optimized out>, table_name=<optimized out>) at /mariadb/10.6/sql/sql_base.cc:1355 #10 0x00005607bce869be in select_create::abort_result_set (this=0x7f7720016a38) at /mariadb/10.6/sql/sql_insert.cc:5202 #11 0x00005607bcf50c40 in handle_select (thd=thd@entry=0x7f7720001a28, lex=lex@entry=0x7f7720005ac8, result=result@entry=0x7f7720016a38, setup_tables_done_option=setup_tables_done_option@entry=0) at /mariadb/10.6/sql/sql_select.cc:563 #12 0x00005607bcfa90cf in Sql_cmd_create_table_like::execute (this=0x7f7720014ff8, thd=0x7f7720001a28) at /mariadb/10.6/sql/sql_table.cc:11737 #13 0x00005607bced826d in mysql_execute_command (thd=thd@entry=0x7f7720001a28, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /mariadb/10.6/sql/sql_parse.cc:5997 #14 0x00005607bced9299 in mysql_parse (thd=thd@entry=0x7f7720001a28, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x7f7740b604c0) at /mariadb/10.6/sql/sql_parse.cc:8030 #15 0x00005607bcedb7fc in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x7f7720001a28, packet=0x7f7740b604c0 "\377\377\377\377", packet@entry=0x7f7720087d49 "CREATE TEMPORARY TABLE v0 ( v1 TEXT ( 15 ) CHAR SET BINARY NOT NULL NOT NULL UNIQUE CHECK ( v1 ) ) REPLACE SELECT NULL AS v3 , 74 AS v2 ", packet_length=packet_length@entry=136, blocking=blocking@entry=true) at /mariadb/10.6/sql/sql_parse.cc:1896 Related note: It would be great if the SQL layer did not force storage engines to memorize temporary tables by a generated name string ( MDEV-17805 ). If I remember correctly, it was in MariaDB 10.3 where we started to allow multiple handles to a temporary table in a query. It may be that older InnoDB versions are missing an equivalent assertion.

            Original test suite has an error:

            CREATE TEMPORARY TABLE v0 ( v1 TEXT ( 15 ) CHAR SET BINARY NOT NULL NOT NULL UNIQUE CHECK ( v1 ) ) REPLACE SELECT NULL AS v3 , 74 AS v2 ;
            main.test                                [ fail ]
                    Test ended at 2022-07-06 14:26:26
             
            CURRENT_TEST: main.test
            mysqltest: At line 1: query 'CREATE TEMPORARY TABLE v0 ( v1 TEXT ( 15 ) CHAR SET BINARY NOT NULL NOT NULL UNIQUE CHECK ( v1 ) ) REPLACE SELECT NULL AS v3 , 74 AS v2 ' failed: 1364: Field 'v1' doesn't have a default value
            

            sanja Oleksandr Byelkin added a comment - Original test suite has an error: CREATE TEMPORARY TABLE v0 ( v1 TEXT ( 15 ) CHAR SET BINARY NOT NULL NOT NULL UNIQUE CHECK ( v1 ) ) REPLACE SELECT NULL AS v3 , 74 AS v2 ; main.test [ fail ] Test ended at 2022-07-06 14:26:26   CURRENT_TEST: main.test mysqltest: At line 1: query 'CREATE TEMPORARY TABLE v0 ( v1 TEXT ( 15 ) CHAR SET BINARY NOT NULL NOT NULL UNIQUE CHECK ( v1 ) ) REPLACE SELECT NULL AS v3 , 74 AS v2 ' failed: 1364: Field 'v1' doesn't have a default value
            Mingli-Yu Mingli-Yu added a comment -

            Does the version 10.8.3 have the issue? Thanks!

            Mingli-Yu Mingli-Yu added a comment - Does the version 10.8.3 have the issue? Thanks!

            Mingli-Yu very probably.

            sanja Oleksandr Byelkin added a comment - Mingli-Yu very probably.

            commit 5a48ba6ac493d760934172c4733840729355a01b (HEAD -> bb-10.5-MDEV-26433, origin/bb-10.5-MDEV-26433)
            Author: Oleksandr Byelkin <sanja@mariadb.com>
            Date:   Fri Jul 8 11:38:45 2022 +0200
             
                MDEV-26433 assertion: table->get_ref_count() == 0 in dict0dict.cc line 1915
                
                Close handlers in THD::drop_temporary_table.
            

            sanja Oleksandr Byelkin added a comment - commit 5a48ba6ac493d760934172c4733840729355a01b (HEAD -> bb-10.5-MDEV-26433, origin/bb-10.5-MDEV-26433) Author: Oleksandr Byelkin <sanja@mariadb.com> Date: Fri Jul 8 11:38:45 2022 +0200   MDEV-26433 assertion: table->get_ref_count() == 0 in dict0dict.cc line 1915 Close handlers in THD::drop_temporary_table.

            5a48ba6ac493d is ok to push

            serg Sergei Golubchik added a comment - 5a48ba6ac493d is ok to push

            People

              sanja Oleksandr Byelkin
              fuboat Jingzhou Fu
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.