From d1c1981ba9e774106d99eba373eb79b9b5638f77 Mon Sep 17 00:00:00 2001 From: Jon Olav Hauglid Date: Thu, 28 Feb 2013 14:52:47 +0100 Subject: 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. --- sql/sql_handler.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'sql/sql_handler.cc') diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index e7973850194..5c0a7ec184b 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -1,4 +1,4 @@ -/* 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) -- cgit v1.2.1