#At file:///ext/mysql/bzr/backup/bug33574/
2718 Rafal Somla 2008-10-29
BUG#33574, BUG#34903 (Backup: restore failure if temporary table exists)
Before: If a temporary table existed with the same name as a regular one, BACKUP
saved the temporary table.
After: Temporary tables are ignored by BACKUP command.
modified:
sql/backup/be_snapshot.cc
sql/backup/be_thread.cc
sql/backup/kernel.cc
sql/si_objects.cc
per-file messages:
sql/backup/be_snapshot.cc
Pass MYSQL_OPEN_SKIP_TEMPORARY flag when openning and locking tables.
sql/backup/be_thread.cc
Pass MYSQL_OPEN_SKIP_TEMPORARY flag when opening and locking tables.
sql/backup/kernel.cc
Pass MYSQL_OPEN_SKIP_TEMPORARY flag when lcoking tables for restore operation.
sql/si_objects.cc
Pass MYSQL_OPEN_SKIP_TEMPORARY flag when openning a table to get its CREATE statement.
=== modified file 'sql/backup/be_snapshot.cc'
--- a/sql/backup/be_snapshot.cc 2008-08-08 19:58:37 +0000
+++ b/sql/backup/be_snapshot.cc 2008-10-29 07:33:41 +0000
@@ -126,7 +126,15 @@ result_t Backup::get_data(Buffer &buf)
// open_and_lock_tables. Otherwise, open_and_lock_tables will try to open
// previously opened views and crash.
locking_thd->m_thd->lex->cleanup_after_one_table_open();
- open_and_lock_tables(locking_thd->m_thd, locking_thd->tables_in_backup);
+ /*
+ The MYSQL_OPEN_SKIP_TEMPORARY flag is needed so that temporary tables are
+ not opened which would occulde the regular tables selected for backup
+ (BUG#33574).
+ */
+ open_and_lock_tables_derived(locking_thd->m_thd,
+ locking_thd->tables_in_backup,
+ FALSE, /* do not process derived tables */
+ MYSQL_OPEN_SKIP_TEMPORARY);
tables_open= TRUE;
}
if (locking_thd->lock_state == LOCK_ACQUIRED)
=== modified file 'sql/backup/be_thread.cc'
--- a/sql/backup/be_thread.cc 2008-07-09 07:12:43 +0000
+++ b/sql/backup/be_thread.cc 2008-10-29 07:33:41 +0000
@@ -161,7 +161,16 @@ pthread_handler_t backup_thread_for_lock
killing the thread. In this case, we need to close the tables
and exit.
*/
- if (open_and_lock_tables(thd, locking_thd->tables_in_backup))
+
+ /*
+ The MYSQL_OPEN_SKIP_TEMPORARY flag is needed so that temporary tables are
+ not opened which would occulde the regular tables selected for backup
+ (BUG#33574).
+ */
+ if (open_and_lock_tables_derived(thd, locking_thd->tables_in_backup,
+ FALSE, /* do not process derived tables */
+ MYSQL_OPEN_SKIP_TEMPORARY)
+ )
{
DBUG_PRINT("info",("Online backup locking thread dying"));
THD_SET_PROC_INFO(thd, "lock error");
=== modified file 'sql/backup/kernel.cc'
--- a/sql/backup/kernel.cc 2008-10-27 13:06:21 +0000
+++ b/sql/backup/kernel.cc 2008-10-29 07:33:41 +0000
@@ -838,11 +838,18 @@ int Backup_restore_ctx::lock_tables_for_
/*
Open and lock the tables.
- Note: simple_open_n_lock_tables() must be used here since we don't want
- to do derived tables processing. Processing derived tables even leads
- to crashes as those reported in BUG#34758.
+ Note 1: It is important to not do derived tables processing here. Processing
+ derived tables even leads to crashes as those reported in BUG#34758.
+
+ Note 2: Skiping tmp tables is also important because otherwise a tmp table
+ can occlude a regular table with the same name (BUG#33574).
*/
- if (simple_open_n_lock_tables(m_thd,tables))
+ if (open_and_lock_tables_derived(m_thd, tables,
+ FALSE, /* do not process derived tables */
+ MYSQL_OPEN_SKIP_TEMPORARY
+ /* do not open tmp tables */
+ )
+ )
{
fatal_error(ER_BACKUP_OPEN_TABLES,"RESTORE");
return m_error;
=== modified file 'sql/si_objects.cc'
--- a/sql/si_objects.cc 2008-10-27 13:06:21 +0000
+++ b/sql/si_objects.cc 2008-10-29 07:33:41 +0000
@@ -2126,8 +2126,15 @@ bool TableObj::do_serialize(THD *thd, St
/*
Open the view and its base tables or views
- */
- if (open_normal_and_derived_tables(thd, table_list, 0)) {
+
+ The MYSQL_OPEN_SKIP_TEMPORARY flag is needed because TableObj always
+ refers to a regular table, even if a temporary table with the same name
+ exists in the database (see BUG#33574).
+ */
+ if (open_normal_and_derived_tables(thd, table_list,
+ MYSQL_OPEN_SKIP_TEMPORARY)
+ )
+ {
close_thread_tables(thd);
thd->lex->select_lex.table_list.empty();
DBUG_RETURN(TRUE);