#At file:///home/dlenev/src/bzr/mysql-6.1-fix/
2683 Dmitry Lenev 2008-08-20
Follow-up fix for the patch that implements changes in CREATE TABLE
LIKE necessary for the 7th milestone of WL#148 "Foreign keys".
Fixed compile error which occured when server was built without
partitioning support.
Fixed create.test failure in --ps-protocol mode which was
discovered by pushbuild.
Finally fixed couple of coding mistakes which were discovered
while fixing above.
modified:
mysql-test/r/create.result
mysql-test/t/create.test
sql/sql_parse.cc
sql/sql_prepare.cc
sql/sql_table.cc
per-file messages:
mysql-test/r/create.result
Added test case for the case when target table of CREATE TABLE LIKE is "shadowed" by existing temporary table.
Also adjusted test case after changing error which is emitted
when one tries to create non-temporary table with this statement
under LOCK TABLES.
mysql-test/t/create.test
Added test case for the case when target table of CREATE TABLE LIKE is "shadowed" by existing temporary table.
Also adjusted test case after changing error which is emitted
when one tries to create non-temporary table with this statement
under LOCK TABLES.
sql/sql_parse.cc
Ignore temporary tables which has the same name as non-temporary
table to be created when obtaining metadata lock on target table
in CREATE TABLE LIKE.
sql/sql_prepare.cc
mysql_test_create_table():
When validating CREATE TABLE LIKE for non-temporary table
include target table into the table list before opening
tables used by statement as we do it during statement
execution. This properly sets version of metadata for
table list element for target table and thus allows to
avoid errors about required re-prepare during statement
execution.
sql/sql_table.cc
mysql_create_like_table():
There is no need for separate check that we are trying to
create non-temporary table under LOCK TABLES since in this
case later call to open_tables() emits different by still
appropriate error. This also allows us to have consistency
between prepared and ordinary statements since this new error
is the same error which will be emitted in such case during
validation of prepared CREATE TABLE LIKE statement.
Adjusted code to take into account that server can be compiled
without partitioning support.
Added assertion which ensures that we have proper meta-data
lock when creating non-temporary table. Fixed coding mistake
discovered by this assertion.
=== modified file 'mysql-test/r/create.result'
--- a/mysql-test/r/create.result 2008-08-19 12:29:01 +0000
+++ b/mysql-test/r/create.result 2008-08-20 06:39:06 +0000
@@ -386,10 +386,20 @@ drop table t1, t2, t3;
drop table t3;
drop database mysqltest;
create table t1 (i int);
+create temporary table t2 (j int);
+create table t2 like t1;
+drop temporary table t2;
+show create table t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `i` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+drop tables t1, t2;
+create table t1 (i int);
create table t2 (j int);
lock tables t1 read;
create table t3 like t1;
-ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction
+ERROR HY000: Table 't3' was not locked with LOCK TABLES
create temporary table t3 like t1;
drop temporary table t3;
create temporary table t3 like t2;
=== modified file 'mysql-test/t/create.test'
--- a/mysql-test/t/create.test 2008-08-19 12:29:01 +0000
+++ b/mysql-test/t/create.test 2008-08-20 06:39:06 +0000
@@ -331,6 +331,13 @@ create temporary table t3 like t1;
drop table t1, t2, t3;
drop table t3;
drop database mysqltest;
+# Check that existing temporary table does not shadow non-temporary one
+create table t1 (i int);
+create temporary table t2 (j int);
+create table t2 like t1;
+drop temporary table t2;
+show create table t2;
+drop tables t1, t2;
#
# CREATE TABLE LIKE under LOCK TABLES
#
@@ -340,7 +347,7 @@ drop database mysqltest;
create table t1 (i int);
create table t2 (j int);
lock tables t1 read;
---error ER_LOCK_OR_ACTIVE_TRANSACTION
+--error ER_TABLE_NOT_LOCKED
create table t3 like t1;
# OTOH creating of temporary table should be OK
create temporary table t3 like t1;
=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc 2008-08-19 12:29:01 +0000
+++ b/sql/sql_parse.cc 2008-08-20 06:39:06 +0000
@@ -2438,6 +2438,7 @@ mysql_execute_command(THD *thd)
{
lex->link_first_table_back(create_table, link_to_local);
create_table->open_type= TABLE_LIST::OPEN_OR_CREATE;
+ create_table->skip_temporary= TRUE;
}
res= mysql_create_like_table(thd, create_table, select_tables,
=== modified file 'sql/sql_prepare.cc'
--- a/sql/sql_prepare.cc 2008-06-23 13:26:17 +0000
+++ b/sql/sql_prepare.cc 2008-08-20 06:39:06 +0000
@@ -1615,8 +1615,18 @@ static bool mysql_test_create_table(Prep
we validate metadata of all CREATE TABLE statements,
which keeps metadata validation code simple.
*/
+ if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))
+ {
+ lex->link_first_table_back(create_table, link_to_local);
+ create_table->open_type= TABLE_LIST::OPEN_OR_CREATE;
+ create_table->skip_temporary= TRUE;
+ }
+
if (open_normal_and_derived_tables(stmt->thd, lex->query_tables, 0))
DBUG_RETURN(TRUE);
+
+ if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))
+ create_table= lex->unlink_first_table(&link_to_local);
}
/* put tables back for PS rexecuting */
=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc 2008-08-19 12:29:01 +0000
+++ b/sql/sql_table.cc 2008-08-20 06:39:06 +0000
@@ -5055,18 +5055,6 @@ bool mysql_create_like_table(THD* thd, T
uint not_used;
DBUG_ENTER("mysql_create_like_table");
- if (!(create_info->options & HA_LEX_CREATE_TMP_TABLE) &&
- thd->locked_tables_mode)
- {
- /*
- Since under LOCK TABLES attempt to acquire exclusive metadata lock
- on the table to be created (and thus not locked) can lead to deadlock
- we prohibit creation of non-temporary tables under LOCK TABLES.
- */
- my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
- goto err;
- }
-
/*
We the open source table to get its description in HA_CREATE_INFO
and Alter_info objects. This also acquires a shared metadata lock
@@ -5089,9 +5077,11 @@ bool mysql_create_like_table(THD* thd, T
if (mysql_prepare_alter_table(thd, src_table, &local_create_info,
&local_alter_info))
goto err;
+#ifdef WITH_PARTITION_STORAGE_ENGINE
/* Partition info is not handled by mysql_prepare_alter_table() call. */
if (src_table->table->part_info)
thd->work_part_info= src_table->table->part_info->get_clone();
+#endif
/*
Adjust description of source table before using it for creation of
@@ -5116,8 +5106,16 @@ bool mysql_create_like_table(THD* thd, T
if ((res= mysql_create_table_no_lock(thd, table->db, table->table_name,
&local_create_info, &local_alter_info,
FALSE, 0)) ||
- create_info->table_existed)
+ local_create_info.table_existed)
goto err;
+
+ /*
+ Ensure that we have an exclusive lock on target table if we are creating
+ non-temporary table.
+ */
+ DBUG_ASSERT((create_info->options & HA_LEX_CREATE_TMP_TABLE) ||
+ mdl_is_exclusive_lock_owner(&thd->mdl_context, 0, table->db,
+ table->table_name));
/*
We have to write the query before we unlock the tables.
| Thread |
|---|
| • bzr commit into mysql-6.1-fk branch (dlenev:2683) WL#148 | Dmitry Lenev | 20 Aug |