MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Alexander Nozdrin Date:August 27 2010 9:21am
Subject:bzr commit into mysql-5.5-runtime branch (alik:3124) Bug#27480
View as plain text  
#At file:///mnt/raid/alik/MySQL/bzr/00/bug27480/mysql-5.5-runtime-bug27480.3/ based on revid:alik@stripped

 3124 Alexander Nozdrin	2010-08-27
      Bug#27480 (Extend CREATE TEMPORARY TABLES privilege
      to allow temp table operations) -- prerequisite patch #2.
          
      Introduce a new form of find_temporary_table() function:
      find_temporary_table() by a table key. It will be used
      in further patches.
      
      Replace find_temporary_table(table_list->db, table_list->name)
      by more appropiate find_temporary_table(table_list) across
      the codebase.

    modified:
      sql/sql_base.cc
      sql/sql_base.h
      sql/sql_parse.cc
      sql/sql_table.cc
      sql/sql_trigger.cc
=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2010-08-27 08:39:01 +0000
+++ b/sql/sql_base.cc	2010-08-27 09:21:38 +0000
@@ -247,7 +247,8 @@ static void check_unused(void)
     Length of key
 */
 
-uint create_table_def_key(THD *thd, char *key, TABLE_LIST *table_list,
+uint create_table_def_key(THD *thd, char *key,
+                          const TABLE_LIST *table_list,
                           bool tmp_table)
 {
   uint key_length= (uint) (strmov(strmov(key, table_list->db)+1,
@@ -1987,39 +1988,60 @@ void update_non_unique_table_error(TABLE
 }
 
 
+/**
+  Find temporary table specified by database and table names in the
+  THD::temporary_tables list.
+
+  @return TABLE instance if a temporary table has been found; NULL otherwise.
+*/
+
 TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name)
 {
-  TABLE_LIST table_list;
+  TABLE_LIST tl;
 
-  table_list.db= (char*) db;
-  table_list.table_name= (char*) table_name;
-  return find_temporary_table(thd, &table_list);
+  tl.db= (char*) db;
+  tl.table_name= (char*) table_name;
+
+  return find_temporary_table(thd, &tl);
 }
 
 
-TABLE *find_temporary_table(THD *thd, TABLE_LIST *table_list)
+/**
+  Find a temporary table specified by TABLE_LIST instance in the
+  THD::temporary_tables list.
+
+  @return TABLE instance if a temporary table has been found; NULL otherwise.
+*/
+
+TABLE *find_temporary_table(THD *thd, const TABLE_LIST *tl)
 {
-  char	key[MAX_DBKEY_LENGTH];
-  uint	key_length;
-  TABLE *table;
-  DBUG_ENTER("find_temporary_table");
-  DBUG_PRINT("enter", ("table: '%s'.'%s'",
-                       table_list->db, table_list->table_name));
+  char key[MAX_DBKEY_LENGTH];
+  uint key_length= create_table_def_key(thd, key, tl, 1);
+
+  return find_temporary_table(thd, key, key_length);
+}
+
+
+/**
+  Find a temporary table specified by a key in the THD::temporary_tables list.
+
+  @return TABLE instance if a temporary table has been found; NULL otherwise.
+*/
 
-  key_length= create_table_def_key(thd, key, table_list, 1);
-  for (table=thd->temporary_tables ; table ; table= table->next)
+TABLE *find_temporary_table(THD *thd,
+                            const char *table_key,
+                            uint table_key_length)
+{
+  for (TABLE *table= thd->temporary_tables; table; table= table->next)
   {
-    if (table->s->table_cache_key.length == key_length &&
-	!memcmp(table->s->table_cache_key.str, key, key_length))
+    if (table->s->table_cache_key.length == table_key_length &&
+        !memcmp(table->s->table_cache_key.str, table_key, table_key_length))
     {
-      DBUG_PRINT("info",
-                 ("Found table. server_id: %u  pseudo_thread_id: %lu",
-                  (uint) thd->server_id,
-                  (ulong) thd->variables.pseudo_thread_id));
-      DBUG_RETURN(table);
+      return table;
     }
   }
-  DBUG_RETURN(0);                               // Not a temporary table
+
+  return NULL;
 }
 
 

=== modified file 'sql/sql_base.h'
--- a/sql/sql_base.h	2010-08-20 08:24:32 +0000
+++ b/sql/sql_base.h	2010-08-27 09:21:38 +0000
@@ -79,7 +79,8 @@ void table_def_start_shutdown(void);
 void assign_new_table_id(TABLE_SHARE *share);
 uint cached_open_tables(void);
 uint cached_table_definitions(void);
-uint create_table_def_key(THD *thd, char *key, TABLE_LIST *table_list,
+uint create_table_def_key(THD *thd, char *key,
+                          const TABLE_LIST *table_list,
                           bool tmp_table);
 TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
                              uint key_length, uint db_flags, int *error,
@@ -159,7 +160,9 @@ TABLE_LIST *find_table_in_list(TABLE_LIS
                                const char *db_name,
                                const char *table_name);
 TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name);
-TABLE *find_temporary_table(THD *thd, TABLE_LIST *table_list);
+TABLE *find_temporary_table(THD *thd, const TABLE_LIST *tl);
+TABLE *find_temporary_table(THD *thd, const char *table_key,
+                            uint table_key_length);
 void close_thread_tables(THD *thd);
 bool fill_record_n_invoke_before_triggers(THD *thd, List<Item> &fields,
                                           List<Item> &values,

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2010-08-18 11:55:37 +0000
+++ b/sql/sql_parse.cc	2010-08-27 09:21:38 +0000
@@ -177,8 +177,7 @@ static bool some_non_temp_table_to_be_up
   for (TABLE_LIST *table= tables; table; table= table->next_global)
   {
     DBUG_ASSERT(table->db && table->table_name);
-    if (table->updating &&
-        !find_temporary_table(thd, table->db, table->table_name))
+    if (table->updating && !find_temporary_table(thd, table))
       return 1;
   }
   return 0;

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2010-08-23 22:31:12 +0000
+++ b/sql/sql_table.cc	2010-08-27 09:21:38 +0000
@@ -2008,7 +2008,7 @@ int mysql_rm_table_part2(THD *thd, TABLE
     {
       for (table= tables; table; table= table->next_local)
         if (table->open_type != OT_BASE_ONLY &&
-	    find_temporary_table(thd, table->db, table->table_name))
+	    find_temporary_table(thd, table))
         {
           /*
             A temporary table.

=== modified file 'sql/sql_trigger.cc'
--- a/sql/sql_trigger.cc	2010-08-09 18:33:47 +0000
+++ b/sql/sql_trigger.cc	2010-08-27 09:21:38 +0000
@@ -458,7 +458,7 @@ bool mysql_create_or_drop_trigger(THD *t
   DBUG_ASSERT(tables->next_global == 0);
 
   /* We do not allow creation of triggers on temporary tables. */
-  if (create && find_temporary_table(thd, tables->db, tables->table_name))
+  if (create && find_temporary_table(thd, tables))
   {
     my_error(ER_TRG_ON_VIEW_OR_TEMP_TABLE, MYF(0), tables->alias);
     goto end;


Attachment: [text/bzr-bundle] bzr/alik@sun.com-20100827092138-f63cvz0sa1vk5cb5.bundle
Thread
bzr commit into mysql-5.5-runtime branch (alik:3124) Bug#27480Alexander Nozdrin27 Aug
  • Re: bzr commit into mysql-5.5-runtime branch (alik:3124) Bug#27480Dmitry Lenev27 Aug