List:Commits« Previous MessageNext Message »
From:Andrei Elkin Date:May 9 2006 9:10am
Subject:bk commit into 4.1 tree (aelkin:1.2471) BUG#19188
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of elkin. When elkin does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2471 06/05/09 10:10:48 aelkin@stripped +4 -0
  BUG#19188: incorrect temporary table name of DROP query in replication
  
    A pattern to generate binlog for DROPped temp table in close_temporary_tables
    was buggy: could not deal with a grave-accent-in-name table.
  
    The fix exploits `append_identifier()' for quoting and duplicating accents.
  

  sql/sql_base.cc
    1.268 06/05/09 10:10:42 aelkin@stripped +99 -111
    Utilizing `append_identifier' to quote. `close_temporary_tables' once again recoded
    I hope to become much simplier that previously. No-binlog branch is separated
completely the
    rest that adopts String's methods.

  sql/mysql_priv.h
    1.376 06/05/09 10:10:41 aelkin@stripped +12 -0
    bool is_user_table(TABLE * table) 
    is added to answer wheather temporary table was created explicitly.

  mysql-test/t/rpl_temporary.test
    1.16 06/05/09 10:10:41 aelkin@stripped +3 -1
    more correct internal table emulation

  mysql-test/r/rpl_temporary.result
    1.14 06/05/09 10:10:41 aelkin@stripped +2 -1
    results changed

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	aelkin
# Host:	dsl-hkigw8-feb0de00-199.dhcp.inet.fi
# Root:	/net/nb/home/elkin/MySQL/FIXES/4.1-bug19188_tmp_name

--- 1.375/sql/mysql_priv.h	2006-04-07 22:48:18 +03:00
+++ 1.376/sql/mysql_priv.h	2006-05-09 10:10:41 +03:00
@@ -1275,6 +1275,18 @@
   return -1;
 }
 
+/*
+  is_user_table()
+  return true if the table was created explicitly
+*/
+
+inline bool is_user_table(TABLE * table)
+{
+  const char *name= table->real_name;
+  return strncmp(name, tmp_file_prefix, tmp_file_prefix_length);
+}
+
+
 
 /*
   Some functions that are different in the embedded library and the normal

--- 1.267/sql/sql_base.cc	2006-04-23 19:42:21 +03:00
+++ 1.268/sql/sql_base.cc	2006-05-09 10:10:42 +03:00
@@ -493,135 +493,123 @@
 
 void close_temporary_tables(THD *thd)
 {
-  TABLE *next,
-    *prev_table /* prev link is not maintained in TABLE's double-linked list */,
-    *table;
-  char *query= (gptr) 0, *end;
-  uint query_buf_size, max_names_len; 
-  bool found_user_tables;
-
+  TABLE *table;
   if (!thd->temporary_tables)
     return;
-  
-  LINT_INIT(end);
-  query_buf_size= 50;   // Enough for DROP ... TABLE IF EXISTS
-
-  /* 
-     insertion sort of temp tables by pseudo_thread_id to build ordered list 
-     of sublists of equal pseudo_thread_id
-  */
-  for (prev_table= thd->temporary_tables, 
-         table= prev_table->next,
-         found_user_tables= (prev_table->real_name[0] != '#'); 
-       table;
-       prev_table= table, table= table->next)
-  {
-    TABLE *prev_sorted /* same as for prev_table */,
-      *sorted;
-    /*
-      table not created directly by the user is moved to the tail. 
-      Fixme/todo: nothing (I checked the manual) prevents user to create temp
-      with `#' 
-    */
-    if (table->real_name[0] == '#')
-      continue;
-    else 
+  else if (!mysql_bin_log.is_open())
+    for (table= thd->temporary_tables; table; table= table->next)
     {
-      found_user_tables = 1;
+      close_temporary(table, 1);
     }
-    for (prev_sorted= NULL, sorted= thd->temporary_tables; sorted != table; 
-         prev_sorted= sorted, sorted= sorted->next)
+  else
+  {
+    TABLE *next,
+      *prev_table /* prev link is not maintained in TABLE's double-linked list */;
+    bool was_quote_show= true; /* to assume thd->options has OPTION_QUOTE_SHOW_CREATE
*/
+    // Better add "if exists", in case a RESET MASTER has been done
+    const char stub[]= "DROP /*!40005 TEMPORARY */ TABLE IF EXISTS ";
+    uint stub_len= sizeof(stub) - 1;
+    char buf[256];
+    memcpy(buf, stub, stub_len);
+    String s_query= String(buf, sizeof(buf), system_charset_info);
+    bool found_user_tables= false;
+    LINT_INIT(next);
+    
+    /* 
+       insertion sort of temp tables by pseudo_thread_id to build ordered list 
+       of sublists of equal pseudo_thread_id
+    */
+    
+    for (prev_table= thd->temporary_tables, table= prev_table->next;
+         table;
+         prev_table= table, table= table->next)
     {
-      if (sorted->real_name[0] == '#' || tmpkeyval(thd, sorted) > tmpkeyval(thd,
table))
+      TABLE *prev_sorted /* same as for prev_table */, *sorted;
+      if (!found_user_tables && is_user_table(table))
       {
-        /* move into the sorted part of the list from the unsorted */
-        prev_table->next= table->next;
-        table->next= sorted;
-        if (prev_sorted) 
-        {
-          prev_sorted->next= table;
-        }
-        else
+        found_user_tables= true;
+      }
+      else 
+        continue;
+      for (prev_sorted= NULL, sorted= thd->temporary_tables; sorted != table; 
+           prev_sorted= sorted, sorted= sorted->next)
+      {
+        if (!is_user_table(sorted) ||
+            tmpkeyval(thd, sorted) > tmpkeyval(thd, table))
         {
-          thd->temporary_tables= table;
+          /* move into the sorted part of the list from the unsorted */
+          prev_table->next= table->next;
+          table->next= sorted;
+          if (prev_sorted) 
+          {
+            prev_sorted->next= table;
+          }
+          else
+          {
+            thd->temporary_tables= table;
+          }
+          table= prev_table;
+          break;
         }
-        table= prev_table;
-        break;
       }
     }
-  }  
-  /* 
-     calc query_buf_size as max per sublists, one sublist per pseudo thread id.
-     Also stop at first occurence of `#'-named table that starts 
-     all implicitly created temp tables
-  */
-  for (max_names_len= 0, table=thd->temporary_tables; 
-       table && table->real_name[0] != '#';
-       table=table->next)
-  {
-    uint tmp_names_len;
-    for (tmp_names_len= table->key_length + 1;
-         table->next && table->real_name[0] != '#' &&
-           tmpkeyval(thd, table) == tmpkeyval(thd, table->next);
-         table=table->next)
+    /* It should be slight overkill but always to quote db,table names */
+    if (found_user_tables &&
+        !(was_quote_show= (thd->options & OPTION_QUOTE_SHOW_CREATE)))
     {
-      /*
-        We are going to add 4 ` around the db/table names, so 1 might not look
-        enough; indeed it is enough, because table->key_length is greater (by 8,
-        because of server_id and thread_id) than db||table.
-      */
-      tmp_names_len += table->next->key_length + 1;
+      thd->options |= OPTION_QUOTE_SHOW_CREATE;
     }
-    if (tmp_names_len > max_names_len) max_names_len= tmp_names_len;
-  }
-  
-  /* allocate */
-  if (found_user_tables && mysql_bin_log.is_open() &&
-      (query = alloc_root(thd->mem_root, query_buf_size+= max_names_len)))
-    // Better add "if exists", in case a RESET MASTER has been done
-    end= strmov(query, "DROP /*!40005 TEMPORARY */ TABLE IF EXISTS ");
-
-  /* scan sorted tmps to generate sequence of DROP */
-  for (table=thd->temporary_tables; table; table= next)
-  {
-    if (query // we might be out of memory, but this is not fatal 
-        && table->real_name[0] != '#') 
+    
+    /* scan sorted tmps to generate sequence of DROP */
+    for (table= thd->temporary_tables; table; table= next)
     {
-      char *end_cur;
-      /* 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 */
-      for (end_cur= end;
-           table && table->real_name[0] != '#' &&
-             tmpkeyval(thd, table) == thd->variables.pseudo_thread_id;
-           table= next)
+      if (is_user_table(table)) 
+      {
+        /* 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 */
+        for (s_query.length(stub_len);
+             table && is_user_table(table) &&
+               tmpkeyval(thd, table) == thd->variables.pseudo_thread_id;
+             table= next)
+        {
+          /*
+            We are going to add 4 ` around the db/table names and possible more
+            due to special characters in the names
+          */
+          append_identifier(thd, &s_query, table->table_cache_key,
strlen(table->table_cache_key));
+          s_query.q_append('.');
+          append_identifier(thd, &s_query, table->real_name,
+                            strlen(table->real_name));
+          s_query.q_append(',');
+          next= table->next;
+          close_temporary(table, 1);
+        }
+        thd->clear_error();
+        Query_log_event qinfo(thd, s_query.ptr(),
+                              s_query.length() - 1 /* to remove trailing ',' */,
+                              0, FALSE);
+        /*
+          Imagine the thread had created a temp table, then was doing a SELECT, and
+          the SELECT was killed. Then it's not clever to mark the statement above as
+          "killed", because it's not really a statement updating data, and there
+          are 99.99% chances it will succeed on slave.
+          If a real update (one updating a persistent table) was killed on the
+          master, then this real update will be logged with error_code=killed,
+          rightfully causing the slave to stop.
+        */
+        qinfo.error_code= 0;
+        mysql_bin_log.write(&qinfo);
+      }
+      else 
       {
-        end_cur= strxmov(end_cur, "`", table->table_cache_key, "`.`",
-                      table->real_name, "`,", NullS);
         next= table->next;
         close_temporary(table, 1);
       }
-      thd->clear_error();
-      /* The -1 is to remove last ',' */
-      Query_log_event qinfo(thd, query, (ulong)(end_cur - query) - 1, 0, FALSE);
-      /*
-        Imagine the thread had created a temp table, then was doing a SELECT, and
-        the SELECT was killed. Then it's not clever to mark the statement above as
-        "killed", because it's not really a statement updating data, and there
-        are 99.99% chances it will succeed on slave.
-        If a real update (one updating a persistent table) was killed on the
-        master, then this real update will be logged with error_code=killed,
-        rightfully causing the slave to stop.
-      */
-      qinfo.error_code= 0;
-      mysql_bin_log.write(&qinfo);
-    }
-    else 
-    {
-      next= table->next;
-      close_temporary(table, 1);
     }
+    if (!was_quote_show)
+      thd->options &= ~OPTION_QUOTE_SHOW_CREATE;
   }
   thd->temporary_tables=0;
 }

--- 1.13/mysql-test/r/rpl_temporary.result	2006-04-23 11:55:04 +03:00
+++ 1.14/mysql-test/r/rpl_temporary.result	2006-05-09 10:10:41 +03:00
@@ -94,7 +94,8 @@
 create temporary table t102 (id int);
 set @session.pseudo_thread_id=200;
 create temporary table t201 (id int);
-create temporary table `#not_user_table_prefixed_with_hash_sign_no_harm` (id int);
+create temporary table `t``201` (id int);
+create temporary table `#sql_not_user_table` (id int);
 set @con1_id=connection_id();
 kill @con1_id;
 create table t1(f int);

--- 1.15/mysql-test/t/rpl_temporary.test	2006-04-23 11:55:04 +03:00
+++ 1.16/mysql-test/t/rpl_temporary.test	2006-05-09 10:10:41 +03:00
@@ -140,7 +140,9 @@
 create temporary table t102 (id int);
 set @session.pseudo_thread_id=200;
 create temporary table t201 (id int);
-create temporary table `#not_user_table_prefixed_with_hash_sign_no_harm` (id int);
+create temporary table `t``201` (id int);
+# emulate internal temp table not to come to binlog
+create temporary table `#sql_not_user_table` (id int);
 set @con1_id=connection_id();
 kill @con1_id;
 
Thread
bk commit into 4.1 tree (aelkin:1.2471) BUG#19188Andrei Elkin9 May