|
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.
|