[Commits] Rev 3363: Fixed bug mdev-473. in file:///home/igor/maria/maria-5.5-mdev473/

Igor Babaev igor at askmonty.org
Wed Aug 22 23:53:06 EEST 2012


At file:///home/igor/maria/maria-5.5-mdev473/

------------------------------------------------------------
revno: 3363
revision-id: igor at askmonty.org-20120822205306-jengmh22ygn2dbm8
parent: igor at askmonty.org-20120820190537-epzo04x3o58ccj6i
committer: Igor Babaev <igor at askmonty.org>
branch nick: maria-5.5-mdev473
timestamp: Wed 2012-08-22 13:53:06 -0700
message:
  Fixed bug mdev-473.
  The function unlock_tables_n_open_system_tables_for_write() should take into
  account possible external locks set for opened tables.
-------------- next part --------------
=== modified file 'mysql-test/r/stat_tables.result'
--- a/mysql-test/r/stat_tables.result	2012-08-17 20:23:49 +0000
+++ b/mysql-test/r/stat_tables.result	2012-08-22 20:53:06 +0000
@@ -342,4 +342,15 @@
 set optimizer_switch=@save_optimizer_switch;
 DROP DATABASE dbt3_s001;
 use test;
+#
+# Bug mdev-473: ANALYZE table locked for write
+# 
+set use_stat_tables='complementary';
+create table t1 (i int);
+lock table t1 write;
+analyze table t1;
+Table	Op	Msg_type	Msg_text
+test.t1	analyze	status	Table is already up to date
+alter table t1 add column a varchar(8);
+drop table t1;
 set use_stat_tables=@save_use_stat_tables;

=== modified file 'mysql-test/r/stat_tables_innodb.result'
--- a/mysql-test/r/stat_tables_innodb.result	2012-08-17 20:23:49 +0000
+++ b/mysql-test/r/stat_tables_innodb.result	2012-08-22 20:53:06 +0000
@@ -369,6 +369,17 @@
 set optimizer_switch=@save_optimizer_switch;
 DROP DATABASE dbt3_s001;
 use test;
+#
+# Bug mdev-473: ANALYZE table locked for write
+# 
+set use_stat_tables='complementary';
+create table t1 (i int);
+lock table t1 write;
+analyze table t1;
+Table	Op	Msg_type	Msg_text
+test.t1	analyze	status	OK
+alter table t1 add column a varchar(8);
+drop table t1;
 set use_stat_tables=@save_use_stat_tables;
 set optimizer_switch=@save_optimizer_switch_for_stat_tables_test;
 SET SESSION STORAGE_ENGINE=DEFAULT;

=== modified file 'mysql-test/t/stat_tables.test'
--- a/mysql-test/t/stat_tables.test	2012-08-17 20:23:49 +0000
+++ b/mysql-test/t/stat_tables.test	2012-08-22 20:53:06 +0000
@@ -152,4 +152,19 @@
 
 use test;
 
+--echo #
+--echo # Bug mdev-473: ANALYZE table locked for write
+--echo # 
+
+set use_stat_tables='complementary';
+
+create table t1 (i int);
+
+lock table t1 write;
+analyze table t1;
+alter table t1 add column a varchar(8);
+
+drop table t1;
+
+
 set use_stat_tables=@save_use_stat_tables;

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2012-08-14 19:42:14 +0000
+++ b/sql/sql_base.cc	2012-08-22 20:53:06 +0000
@@ -9641,7 +9641,9 @@
       backup      Pointer to Open_tables_state instance where
                   information about currently open tables will be
                   saved, and from which will be restored when we will
-                  end work with system tables.
+                  end work with system tables
+      save_lock   Pointer to the returned saved reference to the external
+                  lock (if any)
 
   DESCRIPTION
     The function first unlocks the opened tables, but do not close them.
@@ -9662,40 +9664,50 @@
 bool
 unlock_tables_n_open_system_tables_for_write(THD *thd,
                                              TABLE_LIST *table_list,
-                                             Open_tables_backup *backup)
+                                             Open_tables_backup *backup,
+                                             MYSQL_LOCK **save_lock)
 {
+  bool rc= FALSE;
   Query_tables_list query_tables_list_backup;
   LEX *lex= thd->lex;
 
   DBUG_ENTER("unlock_tables_n_open_system_tables_for_write");
 
-  if (thd->lock)
-    mysql_unlock_tables(thd, thd->lock);
-  thd->lock= 0;
+  *save_lock= 0;
 
   lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
   thd->reset_n_backup_open_tables_state(backup);
-
- if (open_and_lock_tables(thd, table_list, FALSE,
-                          MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT))
- {
-    lex->restore_backup_query_tables_list(&query_tables_list_backup);
-    goto error;
+  if (thd->lock)
+  {
+    *save_lock= thd->lock;
+    mysql_unlock_tables(thd, thd->lock, 0);
+    thd->lock= 0;
   }
 
-  for (TABLE_LIST *tables= table_list; tables; tables= tables->next_global)
+  if (open_and_lock_tables(thd, table_list, FALSE,
+                           MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT))
+    rc= TRUE;
+  else
   {
-    DBUG_ASSERT(tables->table->s->table_category == TABLE_CATEGORY_SYSTEM);
-    tables->table->use_all_columns();
+    for (TABLE_LIST *tables= table_list; tables; tables= tables->next_global)
+    {
+      DBUG_ASSERT(tables->table->s->table_category == TABLE_CATEGORY_SYSTEM);
+      tables->table->use_all_columns();
+    }
   }
   lex->restore_backup_query_tables_list(&query_tables_list_backup);
 
-  DBUG_RETURN(FALSE);
-
-error:
-  close_system_tables(thd, backup);
-
-  DBUG_RETURN(TRUE);
+  if (rc)
+  {
+    if (*save_lock)
+    {
+      thd->lock= *save_lock;
+      mysql_lock_tables(thd, thd->lock, 0);
+    }   
+    close_system_tables(thd, backup);
+  }
+
+  DBUG_RETURN(rc);
 }
 
 

=== modified file 'sql/sql_base.h'
--- a/sql/sql_base.h	2012-07-27 00:50:08 +0000
+++ b/sql/sql_base.h	2012-08-22 20:53:06 +0000
@@ -277,7 +277,8 @@
                                  Open_tables_backup *backup);
 bool unlock_tables_n_open_system_tables_for_write(THD *thd,
                                                   TABLE_LIST *table_list,
-                                                  Open_tables_backup *backup);
+                                                  Open_tables_backup *backup,
+                                                  MYSQL_LOCK **save_lock);
 void close_system_tables(THD *thd, Open_tables_backup *backup);
 void close_mysql_tables(THD *thd);
 TABLE *open_system_table_for_update(THD *thd, TABLE_LIST *one_table);

=== modified file 'sql/sql_statistics.cc'
--- a/sql/sql_statistics.cc	2012-08-18 18:49:14 +0000
+++ b/sql/sql_statistics.cc	2012-08-22 20:53:06 +0000
@@ -24,6 +24,7 @@
 */
 
 #include "sql_base.h"
+#include "lock.h"
 #include "key.h"
 #include "sql_statistics.h"
 #include "my_atomic.h"
@@ -2145,6 +2146,7 @@
 {
   TABLE_LIST tables[STATISTICS_TABLES];
   Open_tables_backup open_tables_backup;
+  MYSQL_LOCK *save_lock;
   uint i;
   int err;
   int rc= 0;
@@ -2157,7 +2159,8 @@
 
   if (unlock_tables_n_open_system_tables_for_write(thd,
                                                    tables,
-                                                   &open_tables_backup))
+                                                   &open_tables_backup,
+                                                   &save_lock))
   {
     thd->clear_error();
     DBUG_RETURN(rc);
@@ -2207,6 +2210,11 @@
     }
   }
 
+  if (save_lock)
+  {
+    thd->lock= save_lock;
+    mysql_lock_tables(thd, thd->lock, 0);
+  }   
   close_system_tables(thd, &open_tables_backup);
 
   DBUG_RETURN(rc);



More information about the commits mailing list