Commit fb9ba373 authored by Ramil Kalimullin's avatar Ramil Kalimullin

Fix for bug #46456 [Ver->Prg]: HANDLER OPEN + TRUNCATE + DROP

(temporary) TABLE, crash

Problem: if one has an open "HANDLER t1", further "TRUNCATE t1" 
doesn't close the handler and leaves handler table hash in an 
inconsistent state, that may lead to a server crash.

Fix: TRUNCATE should implicitly close all open handlers.

Doc. request: the fact should be described in the manual accordingly.


mysql-test/r/handler_myisam.result:
  Fix for bug #46456 [Ver->Prg]: HANDLER OPEN + TRUNCATE + DROP
  (temporary) TABLE, crash
    - test result.
mysql-test/t/handler_myisam.test:
  Fix for bug #46456 [Ver->Prg]: HANDLER OPEN + TRUNCATE + DROP
  (temporary) TABLE, crash
    - test case.
sql/sql_delete.cc:
  Fix for bug #46456 [Ver->Prg]: HANDLER OPEN + TRUNCATE + DROP
   (temporary) TABLE, crash
    - remove all truncated tables from the HANDLER's hash.
parent 1317d24b
...@@ -741,3 +741,19 @@ USE information_schema; ...@@ -741,3 +741,19 @@ USE information_schema;
HANDLER COLUMNS OPEN; HANDLER COLUMNS OPEN;
ERROR HY000: Incorrect usage of HANDLER OPEN and information_schema ERROR HY000: Incorrect usage of HANDLER OPEN and information_schema
USE test; USE test;
#
# BUG #46456: HANDLER OPEN + TRUNCATE + DROP (temporary) TABLE, crash
#
CREATE TABLE t1 AS SELECT 1 AS f1;
HANDLER t1 OPEN;
TRUNCATE t1;
HANDLER t1 READ FIRST;
ERROR 42S02: Unknown table 't1' in HANDLER
DROP TABLE t1;
CREATE TEMPORARY TABLE t1 AS SELECT 1 AS f1;
HANDLER t1 OPEN;
TRUNCATE t1;
HANDLER t1 READ FIRST;
ERROR 42S02: Unknown table 't1' in HANDLER
DROP TABLE t1;
End of 5.1 tests
...@@ -19,3 +19,22 @@ let $other_engine_type= MEMORY; ...@@ -19,3 +19,22 @@ let $other_engine_type= MEMORY;
let $other_handler_engine_type= MyISAM; let $other_handler_engine_type= MyISAM;
--source include/handler.inc --source include/handler.inc
--echo #
--echo # BUG #46456: HANDLER OPEN + TRUNCATE + DROP (temporary) TABLE, crash
--echo #
CREATE TABLE t1 AS SELECT 1 AS f1;
HANDLER t1 OPEN;
TRUNCATE t1;
--error ER_UNKNOWN_TABLE
HANDLER t1 READ FIRST;
DROP TABLE t1;
CREATE TEMPORARY TABLE t1 AS SELECT 1 AS f1;
HANDLER t1 OPEN;
TRUNCATE t1;
--error ER_UNKNOWN_TABLE
HANDLER t1 READ FIRST;
DROP TABLE t1;
--echo End of 5.1 tests
...@@ -1066,6 +1066,10 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) ...@@ -1066,6 +1066,10 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
DBUG_ENTER("mysql_truncate"); DBUG_ENTER("mysql_truncate");
bzero((char*) &create_info,sizeof(create_info)); bzero((char*) &create_info,sizeof(create_info));
/* Remove tables from the HANDLER's hash. */
mysql_ha_rm_tables(thd, table_list, FALSE);
/* If it is a temporary table, close and regenerate it */ /* If it is a temporary table, close and regenerate it */
if (!dont_send_ok && (table= find_temporary_table(thd, table_list))) if (!dont_send_ok && (table= find_temporary_table(thd, table_list)))
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment