Commit a4a50271 authored by Jon Olav Hauglid's avatar Jon Olav Hauglid

Bug#16385711: HANDLER, CREATE TABLE IF NOT EXISTS,

              PROBLEM AFTER MYSQL_HA_FIND

This problem occured if a prepared statement tried to create a table
for which there already existed a view with the same name while a
SQL handler was opened.

Before DDL statements are executed, mysql_ha_rm_tables() is called
to remove any matching tables from the internal list of opened SQL
handler tables. This match was done on TABLE_LIST::db and 
TABLE_LIST::table_name. This is problematic for views (which use
TABLE_LIST::view_db and TABLE_LIST::view_name) and anonymous
derived tables.

This patch fixes the problem by skipping TABLE_LISTs representing
anonymous derived tables and using get_db_name()/get_table_name()
which handles views when looking for SQL handler tables to remove.
parent 94b1b653
/* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -820,10 +820,15 @@ static TABLE_LIST *mysql_ha_find(THD *thd, TABLE_LIST *tables)
hash_tables= (TABLE_LIST*) my_hash_element(&thd->handler_tables_hash, i);
for (tables= first; tables; tables= tables->next_local)
{
if ((! *tables->db ||
! my_strcasecmp(&my_charset_latin1, hash_tables->db, tables->db)) &&
! my_strcasecmp(&my_charset_latin1, hash_tables->table_name,
tables->table_name))
if (tables->is_anonymous_derived_table())
continue;
if ((! *tables->get_db_name() ||
! my_strcasecmp(&my_charset_latin1,
hash_tables->get_db_name(),
tables->get_db_name())) &&
! my_strcasecmp(&my_charset_latin1,
hash_tables->get_table_name(),
tables->get_table_name()))
break;
}
if (tables)
......
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