summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorAlfranio Correia <alfranio.correia@sun.com>2009-08-27 17:28:09 +0100
committerAlfranio Correia <alfranio.correia@sun.com>2009-08-27 17:28:09 +0100
commitea06bbd2b0cc4e33b3350ef0bff25b0c1d1c2e95 (patch)
treeb3e2858d1b1f5722d567856af28174a95f2529b0 /sql
parent3e625f987b5d1027ae4db4bc9e66559f8e2eec12 (diff)
downloadmariadb-git-ea06bbd2b0cc4e33b3350ef0bff25b0c1d1c2e95.tar.gz
BUG#46861 Auto-closing of temporary tables broken by replicate-rewrite-db
When a connection is dropped any remaining temporary table is also automatically dropped and the SQL statement of this operation is written to the binary log in order to drop such tables on the slave and keep the slave in sync. Specifically, the current code base creates the following type of statement: DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `db`.`table`; Unfortunately, appending the database to the table name in this manner circumvents the replicate-rewrite-db option (and any options that check the current database). To solve the issue, we started writing the statement to the binary as follows: use `db`; DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `table`;
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_base.cc19
1 files changed, 12 insertions, 7 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index d969c837891..bc9aa50cb82 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -769,19 +769,23 @@ void close_temporary_tables(THD *thd)
{
/* Set pseudo_thread_id to be that of the processed table */
thd->variables.pseudo_thread_id= tmpkeyval(thd, table);
- /* Loop forward through all tables within the sublist of
- common pseudo_thread_id to create single DROP query */
+ String db;
+ db.append(table->s->db);
+ /* Loop forward through all tables that belong to a common database
+ within the sublist of common pseudo_thread_id to create single
+ DROP query
+ */
for (s_query.length(stub_len);
table && is_user_table(table) &&
- tmpkeyval(thd, table) == thd->variables.pseudo_thread_id;
+ tmpkeyval(thd, table) == thd->variables.pseudo_thread_id &&
+ strlen(table->s->db) == db.length() &&
+ strcmp(table->s->db, db.ptr()) == 0;
table= next)
{
/*
- We are going to add 4 ` around the db/table names and possible more
- due to special characters in the names
+ We are going to add ` around the table names and possible more
+ due to special characters
*/
- append_identifier(thd, &s_query, table->s->db, strlen(table->s->db));
- s_query.q_append('.');
append_identifier(thd, &s_query, table->s->table_name,
strlen(table->s->table_name));
s_query.q_append(',');
@@ -794,6 +798,7 @@ void close_temporary_tables(THD *thd)
Query_log_event qinfo(thd, s_query.ptr(),
s_query.length() - 1 /* to remove trailing ',' */,
0, FALSE);
+ qinfo.db= db.ptr();
thd->variables.character_set_client= cs_save;
/*
Imagine the thread had created a temp table, then was doing a SELECT, and