Fixed that rpl_row_create_table can be run with --ps-protocol

As part of the fix we don't anymore generate a create table statement when doing a
CREATE TABLE IF NOT EXISTS table_that_exist LiKE temporary_table
if the 'table_that_exist' existed.

This is because it's not self evident if we should generate a create statement
matching the existing table or the temporary_table. 
The old code generated a table like the existing table in row based replication and like the temporary table
in statement based replication.
It's better to ensure that both cases works the same way.

mysql-test/suite/rpl/r/rpl_row_create_table.result:
  Updated results
  (Now we don't anymore CREATE TABLE IF NOT EXISTS LIKE if the table existed)
sql/sql_base.cc:
  More DBUG_PRINT
sql/sql_error.cc:
  More DBUG_PRINT
sql/sql_table.cc:
  Don't generate a create table statement when doing a
  CREATE TABLE IF NOT EXISTS table_that_exist like temporary_table if the table existed.
This commit is contained in:
Michael Widenius 2014-02-22 03:11:56 +02:00
parent d12c7adf71
commit 6efa5efa7d
4 changed files with 40 additions and 35 deletions

View File

@ -439,7 +439,6 @@ CREATE TABLE IF NOT EXISTS bug48506_t3 LIKE t7;
CREATE TABLE IF NOT EXISTS bug48506_t4 LIKE t7;
SHOW TABLES LIKE 'bug48506%';
Tables_in_test (bug48506%)
bug48506_t4
DROP VIEW IF EXISTS bug48506_t1, bug48506_t2, bug48506_t3;
DROP TEMPORARY TABLES t7;
DROP TABLES t4, t5;

View File

@ -2369,6 +2369,8 @@ retry_share:
{
if (share->tdc.flushed)
{
DBUG_PRINT("info", ("Found old share version: %lu current: %lu",
share->tdc.version, tdc_refresh_version()));
/*
We already have an MDL lock. But we have encountered an old
version of table in the table definition cache which is possible

View File

@ -464,6 +464,7 @@ Diagnostics_area::set_error_status(uint sql_errno,
const Sql_condition *error_condition)
{
DBUG_ENTER("set_error_status");
DBUG_PRINT("enter", ("error: %d", sql_errno));
/*
Only allowed to report error if has not yet reported a success
The only exception is when we flush the message to the client,

View File

@ -5096,6 +5096,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
bool is_trans= FALSE;
bool do_logging= FALSE;
uint not_used;
int create_res;
DBUG_ENTER("mysql_create_like_table");
/*
@ -5171,9 +5172,10 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
if ((local_create_info.table= thd->lex->query_tables->table))
pos_in_locked_tables= local_create_info.table->pos_in_locked_tables;
res= (mysql_create_table_no_lock(thd, table->db, table->table_name,
&local_create_info, &local_alter_info,
&is_trans, C_ORDINARY_CREATE) > 0);
res= ((create_res=
mysql_create_table_no_lock(thd, table->db, table->table_name,
&local_create_info, &local_alter_info,
&is_trans, C_ORDINARY_CREATE)) > 0);
/* Remember to log if we deleted something */
do_logging= thd->log_current_statement;
if (res)
@ -5232,7 +5234,8 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
Case Target Source Write to binary log
==== ========= ========= ==============================
1 normal normal Original statement
2 normal temporary Generated statement
2 normal temporary Generated statement if the table
was created.
3 temporary normal Nothing
4 temporary temporary Nothing
==== ========= ========= ==============================
@ -5247,39 +5250,39 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
Open_table_context ot_ctx(thd, MYSQL_OPEN_REOPEN);
bool new_table= FALSE; // Whether newly created table is open.
/*
The condition avoids a crash as described in BUG#48506. Other
binlogging problems related to CREATE TABLE IF NOT EXISTS LIKE
when the existing object is a view will be solved by BUG 47442.
*/
if (!table->view)
if (create_res != 0)
{
if (!table->table)
{
TABLE_LIST::enum_open_strategy save_open_strategy;
int open_res;
/* Force the newly created table to be opened */
save_open_strategy= table->open_strategy;
table->open_strategy= TABLE_LIST::OPEN_NORMAL;
/*
Table or view with same name already existed and we where using
IF EXISTS. Continue without logging anything.
*/
goto err;
}
if (!table->table)
{
TABLE_LIST::enum_open_strategy save_open_strategy;
int open_res;
/* Force the newly created table to be opened */
save_open_strategy= table->open_strategy;
table->open_strategy= TABLE_LIST::OPEN_NORMAL;
/*
In order for store_create_info() to work we need to open
destination table if it is not already open (i.e. if it
has not existed before). We don't need acquire metadata
lock in order to do this as we already hold exclusive
lock on this table. The table will be closed by
close_thread_table() at the end of this branch.
*/
open_res= open_table(thd, table, thd->mem_root, &ot_ctx);
/* Restore */
table->open_strategy= save_open_strategy;
if (open_res)
{
res= 1;
goto err;
}
new_table= TRUE;
/*
In order for store_create_info() to work we need to open
destination table if it is not already open (i.e. if it
has not existed before). We don't need acquire metadata
lock in order to do this as we already hold exclusive
lock on this table. The table will be closed by
close_thread_table() at the end of this branch.
*/
open_res= open_table(thd, table, thd->mem_root, &ot_ctx);
/* Restore */
table->open_strategy= save_open_strategy;
if (open_res)
{
res= 1;
goto err;
}
new_table= TRUE;
}
/*
We have to re-test if the table was a view as the view may not