Skip to content

Commit ab812c1

Browse files
committed
MDEV-17726: A better fix
THD::close_temporary_tables(): Revert the change. ha_innobase::delete_table(): Move the work-around inside a debug assertion, and check thd_kill_level() instead of thd_killed(), because the latter would not hold for KILL_CONNECTION.
1 parent 705abde commit ab812c1

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

sql/temporary_tables.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2016,2018 MariaDB Corporation
2+
Copyright (c) 2016 MariaDB Corporation
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -476,7 +476,6 @@ bool THD::close_temporary_tables()
476476
}
477477

478478
DBUG_ASSERT(!rgi_slave);
479-
lex->sql_command = SQLCOM_DROP_TABLE;
480479

481480
/*
482481
Ensure we don't have open HANDLERs for tables we are about to close.

storage/innobase/handler/ha_innodb.cc

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13187,17 +13187,25 @@ inline int ha_innobase::delete_table(const char* name, enum_sql_command sqlcom)
1318713187
int ha_innobase::delete_table(const char* name)
1318813188
{
1318913189
enum_sql_command sqlcom = enum_sql_command(thd_sql_command(ha_thd()));
13190-
13191-
if (sqlcom == SQLCOM_TRUNCATE
13192-
&& thd_killed(ha_thd())
13193-
&& (m_prebuilt == NULL
13194-
|| dict_table_is_temporary(m_prebuilt->table))) {
13195-
sqlcom = SQLCOM_DROP_TABLE;
13196-
}
13197-
13198-
/* SQLCOM_TRUNCATE will be passed via ha_innobase::truncate() only. */
13199-
DBUG_ASSERT(sqlcom != SQLCOM_TRUNCATE);
13200-
return delete_table(name, sqlcom);
13190+
/* SQLCOM_TRUNCATE should be passed via ha_innobase::truncate() only.
13191+
13192+
On client disconnect, when dropping temporary tables, the
13193+
previous sqlcom would not be overwritten. In such a case, we
13194+
will have thd_kill_level() != NOT_KILLED, !m_prebuilt can
13195+
hold, and sqlcom could be anything, including TRUNCATE.
13196+
13197+
The sqlcom only matters for persistent tables; no persistent
13198+
metadata or FOREIGN KEY metadata is kept for temporary
13199+
tables. Therefore, we relax the assertion. If there is a bug
13200+
that slips through this assertion due to !m_prebuilt, the
13201+
worst impact should be that on DROP TABLE of a persistent
13202+
table, FOREIGN KEY constraints will be ignored and their
13203+
metadata will not be removed. */
13204+
DBUG_ASSERT(sqlcom != SQLCOM_TRUNCATE
13205+
|| (thd_kill_level(ha_thd()) != NOT_KILLED
13206+
&& (!m_prebuilt
13207+
|| m_prebuilt->table->is_temporary())));
13208+
return delete_table(name, sqlcom);
1320113209
}
1320213210

1320313211
/** Remove all tables in the named database inside InnoDB.

0 commit comments

Comments
 (0)