[Commits] 23f3e82: MDEV-5535: Cannot reopen temporary table

Nirbhay Choubey nirbhay at mariadb.com
Sun May 29 06:19:47 EEST 2016


revision-id: 23f3e821960126ea7bd829df0cbfd17f2d84de05 (mariadb-10.1.8-84-g23f3e82)
parent(s): f6920c0963b6a1a82b4c758e55e4ebf73b38fc23
author: Nirbhay Choubey
committer: Nirbhay Choubey
timestamp: 2016-05-28 23:19:46 -0400
message:

MDEV-5535: Cannot reopen temporary table

Fix for main.query_cache test fauilure.

---
 sql/sql_cache.cc        |  8 ++++----
 sql/sql_class.h         |  3 ++-
 sql/temporary_tables.cc | 25 ++++++-------------------
 3 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index 67e3910..4c32a72 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -1979,7 +1979,7 @@ size_t build_normalized_name(char *buff, size_t bufflen,
   for (; block_table != block_table_end; block_table++)
   {
     TABLE_LIST table_list;
-    TABLE *tmptable;
+    TMP_TABLE_SHARE *tmptable;
     Query_cache_table *table = block_table->parent;
 
     /*
@@ -1989,12 +1989,12 @@ size_t build_normalized_name(char *buff, size_t bufflen,
       query in query cache was made.
     */
     if ((tmptable=
-         thd->find_temporary_table_with_base_key((char *) table->data(),
-                                                 table->key_length())))
+         thd->find_tmp_table_share_w_base_key((char *) table->data(),
+                                              table->key_length())))
     {
       DBUG_PRINT("qcache",
                  ("Temporary table detected: '%s.%s'",
-                  tmptable->s->db.str, tmptable->s->table_name.str));
+                  tmptable->db.str, tmptable->table_name.str));
       unlock();
       /*
         We should not store result of this query because it contain
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 137f3d5..1fe53e2 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -4009,8 +4009,9 @@ class THD :public Statement,
 
   TABLE *find_temporary_table(const char *db, const char *table_name);
   TABLE *find_temporary_table(const TABLE_LIST *tl);
-  TABLE *find_temporary_table_with_base_key(const char *key, uint key_length);
 
+  TMP_TABLE_SHARE *find_tmp_table_share_w_base_key(const char *key,
+                                                   uint key_length);
   TMP_TABLE_SHARE *find_tmp_table_share(const char *db,
                                         const char *table_name);
   TMP_TABLE_SHARE *find_tmp_table_share(const TABLE_LIST *tl);
diff --git a/sql/temporary_tables.cc b/sql/temporary_tables.cc
index b3603e8..2b387f8 100644
--- a/sql/temporary_tables.cc
+++ b/sql/temporary_tables.cc
@@ -155,7 +155,7 @@ TABLE *THD::find_temporary_table(const TABLE_LIST *tl)
 
 
 /**
-  Check whether an open table with the specified key is in use.
+  Check whether a temporary table exists with the specified key.
   The key, in this case, is not the usual key used for temporary tables.
   It does not contain server_id & pseudo_thread_id. This function is
   essentially used use to check whether there is any temporary table
@@ -165,14 +165,13 @@ TABLE *THD::find_temporary_table(const TABLE_LIST *tl)
   @return Success                     A pointer to table share object
           Failure                     NULL
 */
-TABLE *THD::find_temporary_table_with_base_key(const char *key,
-                                               uint key_length)
+TMP_TABLE_SHARE *THD::find_tmp_table_share_w_base_key(const char *key,
+                                                      uint key_length)
 {
-  DBUG_ENTER("THD::find_temporary_table_with_base_key");
+  DBUG_ENTER("THD::find_tmp_table_share_w_base_key");
 
   TMP_TABLE_SHARE *share;
-  TABLE *table;
-  TABLE *result= NULL;
+  TMP_TABLE_SHARE *result= NULL;
   bool locked;
 
   locked= lock_temporary_tables();
@@ -183,19 +182,7 @@ TABLE *THD::find_temporary_table_with_base_key(const char *key,
     if ((share->table_cache_key.length - TMP_TABLE_KEY_EXTRA) == key_length
         && !memcmp(share->table_cache_key.str, key, key_length))
     {
-      /*
-        A matching TMP_TABLE_SHARE is found. We now need to find a TABLE
-        instance in use.
-      */
-      All_share_tables_list::Iterator tables_it(share->all_tmp_tables);
-      while ((table= tables_it ++))
-      {
-        if (table->query_id != 0)
-        {
-          result= table;
-          break;
-        }
-      }
+      result= share;
     }
   }
 


More information about the commits mailing list