Commit 6efa5efa authored by Michael Widenius's avatar Michael Widenius

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.
parent d12c7adf
...@@ -439,7 +439,6 @@ CREATE TABLE IF NOT EXISTS bug48506_t3 LIKE t7; ...@@ -439,7 +439,6 @@ CREATE TABLE IF NOT EXISTS bug48506_t3 LIKE t7;
CREATE TABLE IF NOT EXISTS bug48506_t4 LIKE t7; CREATE TABLE IF NOT EXISTS bug48506_t4 LIKE t7;
SHOW TABLES LIKE 'bug48506%'; SHOW TABLES LIKE 'bug48506%';
Tables_in_test (bug48506%) Tables_in_test (bug48506%)
bug48506_t4
DROP VIEW IF EXISTS bug48506_t1, bug48506_t2, bug48506_t3; DROP VIEW IF EXISTS bug48506_t1, bug48506_t2, bug48506_t3;
DROP TEMPORARY TABLES t7; DROP TEMPORARY TABLES t7;
DROP TABLES t4, t5; DROP TABLES t4, t5;
......
...@@ -2369,6 +2369,8 @@ retry_share: ...@@ -2369,6 +2369,8 @@ retry_share:
{ {
if (share->tdc.flushed) 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 We already have an MDL lock. But we have encountered an old
version of table in the table definition cache which is possible version of table in the table definition cache which is possible
......
...@@ -464,6 +464,7 @@ Diagnostics_area::set_error_status(uint sql_errno, ...@@ -464,6 +464,7 @@ Diagnostics_area::set_error_status(uint sql_errno,
const Sql_condition *error_condition) const Sql_condition *error_condition)
{ {
DBUG_ENTER("set_error_status"); DBUG_ENTER("set_error_status");
DBUG_PRINT("enter", ("error: %d", sql_errno));
/* /*
Only allowed to report error if has not yet reported a success Only allowed to report error if has not yet reported a success
The only exception is when we flush the message to the client, The only exception is when we flush the message to the client,
......
...@@ -5096,6 +5096,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, ...@@ -5096,6 +5096,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
bool is_trans= FALSE; bool is_trans= FALSE;
bool do_logging= FALSE; bool do_logging= FALSE;
uint not_used; uint not_used;
int create_res;
DBUG_ENTER("mysql_create_like_table"); DBUG_ENTER("mysql_create_like_table");
/* /*
...@@ -5171,9 +5172,10 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* 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)) if ((local_create_info.table= thd->lex->query_tables->table))
pos_in_locked_tables= local_create_info.table->pos_in_locked_tables; pos_in_locked_tables= local_create_info.table->pos_in_locked_tables;
res= (mysql_create_table_no_lock(thd, table->db, table->table_name, res= ((create_res=
&local_create_info, &local_alter_info, mysql_create_table_no_lock(thd, table->db, table->table_name,
&is_trans, C_ORDINARY_CREATE) > 0); &local_create_info, &local_alter_info,
&is_trans, C_ORDINARY_CREATE)) > 0);
/* Remember to log if we deleted something */ /* Remember to log if we deleted something */
do_logging= thd->log_current_statement; do_logging= thd->log_current_statement;
if (res) if (res)
...@@ -5232,7 +5234,8 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, ...@@ -5232,7 +5234,8 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
Case Target Source Write to binary log Case Target Source Write to binary log
==== ========= ========= ============================== ==== ========= ========= ==============================
1 normal normal Original statement 1 normal normal Original statement
2 normal temporary Generated statement 2 normal temporary Generated statement if the table
was created.
3 temporary normal Nothing 3 temporary normal Nothing
4 temporary temporary Nothing 4 temporary temporary Nothing
==== ========= ========= ============================== ==== ========= ========= ==============================
...@@ -5247,39 +5250,39 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, ...@@ -5247,39 +5250,39 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
Open_table_context ot_ctx(thd, MYSQL_OPEN_REOPEN); Open_table_context ot_ctx(thd, MYSQL_OPEN_REOPEN);
bool new_table= FALSE; // Whether newly created table is open. bool new_table= FALSE; // Whether newly created table is open.
/* if (create_res != 0)
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 (!table->table) /*
{ Table or view with same name already existed and we where using
TABLE_LIST::enum_open_strategy save_open_strategy; IF EXISTS. Continue without logging anything.
int open_res; */
/* Force the newly created table to be opened */ goto err;
save_open_strategy= table->open_strategy; }
table->open_strategy= TABLE_LIST::OPEN_NORMAL; 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 In order for store_create_info() to work we need to open
destination table if it is not already open (i.e. if it destination table if it is not already open (i.e. if it
has not existed before). We don't need acquire metadata has not existed before). We don't need acquire metadata
lock in order to do this as we already hold exclusive lock in order to do this as we already hold exclusive
lock on this table. The table will be closed by lock on this table. The table will be closed by
close_thread_table() at the end of this branch. close_thread_table() at the end of this branch.
*/ */
open_res= open_table(thd, table, thd->mem_root, &ot_ctx); open_res= open_table(thd, table, thd->mem_root, &ot_ctx);
/* Restore */ /* Restore */
table->open_strategy= save_open_strategy; table->open_strategy= save_open_strategy;
if (open_res) if (open_res)
{ {
res= 1; res= 1;
goto err; goto err;
}
new_table= TRUE;
} }
new_table= TRUE;
} }
/* /*
We have to re-test if the table was a view as the view may not We have to re-test if the table was a view as the view may not
......
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