• unknown's avatar
    Bug#31397 Inconsistent drop table behavior of handler tables. · 4d6543a6
    unknown authored
    The problem is that DROP TABLE and other DDL statements failed to
    automatically close handlers associated with tables that were marked
    for reopen (FLUSH TABLES).
    
    The current implementation fails to properly discard handlers of
    dropped tables (that were marked for reopen) because it searches
    on the open handler tables list and using the current alias of the
    table being dropped. The problem is that it must not use the open
    handler tables list to search because the table might have been
    closed (marked for reopen) by a flush tables command and also it
    must not use the current table alias at all since multiple different
    aliases may be associated with a single table. This is specially
    visible when a user has two open handlers (using alias) of a same
    table and a flush tables command is issued before the table is
    dropped (see test case). Scanning the handler table list is also
    useless for dropping handlers associated with temporary tables,
    because temporary tables are not kept in the THD::handler_tables
    list.
    
    The solution is to simple scan the handlers hash table searching
    for, and deleting all handlers with matching table names if the
    reopen flag is not passed to the flush function, indicating that
    the handlers should be deleted. All matching handlers are deleted
    even if the associated the table is not open.
    
    
    mysql-test/include/handler.inc:
      Add test case for Bug#31397
    mysql-test/r/handler_innodb.result:
      Add test case result for Bug#31397
    mysql-test/r/handler_myisam.result:
      Add test case result for Bug#31397
    sql/mysql_priv.h:
      Rename flush functions to better match the intent of the caller and
      update functions prototypes and remove unused flags.
    sql/sql_base.cc:
      Rename flush functions to better match the intent of the caller.
    sql/sql_class.cc:
      Rename the flush functions to better match the intent of the caller.
      The hash_free function is moved to the cleanup.
    sql/sql_handler.cc:
      When dropping tables for a final close, scan the handler's hash table since
      the table might not be in the handlers open table list because the table was
      marked for reopen or because it's a temporary table.
    sql/sql_rename.cc:
      Drop handlers associated with tables that are being renamed.
    sql/sql_table.cc:
      Now that temporary tables are properly removed even when opened
      by a SQL HANDLER, enable the assert since this branch can't be taken
      outside of SF/trigger/prelocked mode.
    4d6543a6
sql_base.cc 242 KB