List:Commits« Previous MessageNext Message »
From:kroki Date:January 23 2007 10:10am
Subject:bk commit into 5.1 tree (kroki:1.2383) BUG#9953
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of tomash. When tomash 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@stripped, 2007-01-23 12:10:32+03:00, kroki@stripped +23 -0
  BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
  
  The problem was that some facilities (like CONVERT_TZ() function or
  server HELP statement) may require implicit access to some tables in
  'mysql' database.  This access was done by ordinary means of adding such
  tables to the list of tables the query is going to open.  However, if
  we issued LOCK TABLES before that, we would get "table was not locked"
  error trying to open such implicit tables.
  
  The solution is to treat certain tables as MySQL system tables, like we
  already do for mysql.proc.  Such tables may be opened for reading at any
  moment regardless of any locks in effect.  The cost of this is that
  system table may be locked for writing only by itself, it is forbidden
  to lock system table for writing and have any other lock on any other
  table.
  
  After this patch the following tables are treated as MySQL system tables:
    mysql.help_category
    mysql.help_keyword
    mysql.help_relation
    mysql.help_topic
    mysql.proc (it already was)
    mysql.time_zone
    mysql.time_zone_leap_second
    mysql.time_zone_name
    mysql.time_zone_transition
    mysql.time_zone_transition_type
  
  These tables are now opened with open_system_tables_for_read() and closed
  with close_system_tables(), or one table may be opened with
  open_system_table_for_update() and closed with close_thread_tables()
  (the latter is used for mysql.proc table, which is updated as part of
  normal MySQL server operation).
  
  TO THE REVIEWER:
    - main changes are in sql_base.cc, tztime.cc:my_tz_find(), table.cc,
      and sql_help.cc.
    - there are two 'KROKI FIXME' entries with questions in the patch.
    - note that inability to open more that one system table for writing
      makes it impossible to use some triggers (already enforced) or
      foreign keys on such tables (time zone and help tables actually have
      conceptual FKs).

  mysql-test/r/timezone2.result@stripped, 2007-01-23 12:10:26+03:00, kroki@stripped +11
-0
    Add result for bug#9953: CONVERT_TZ requires mysql.time_zone_name
    to be locked.

  mysql-test/r/view.result@stripped, 2007-01-23 12:10:26+03:00, kroki@stripped +4 -3
    Update result: use table t3 rather than utilize MySQL system table.

  mysql-test/t/timezone2.test@stripped, 2007-01-23 12:10:26+03:00, kroki@stripped +28 -0
    Add test case for bug#9953: CONVERT_TZ requires mysql.time_zone_name
    to be locked.

  mysql-test/t/view.test@stripped, 2007-01-23 12:10:26+03:00, kroki@stripped +3 -2
    Update test: use table t3 rather that utilize MySQL system table.

  sql/item_create.cc@stripped, 2007-01-23 12:10:26+03:00, kroki@stripped +0 -3
    We no longer have LEX::add_time_zone_tables_to_query_tables().

  sql/item_timefunc.cc@stripped, 2007-01-23 12:10:26+03:00, kroki@stripped +3 -15
    We no longer have LEX::time_zone_tables_used, so
    Item_func_convert_tz::fix_fields() became the same as base
    Item_date_func::fix_fields().
    
    my_tz_find() no longer takes table list, but takes THD pointer now.

  sql/item_timefunc.h@stripped, 2007-01-23 12:10:26+03:00, kroki@stripped +0 -3
    Remove dead field and method.

  sql/log_event.cc@stripped, 2007-01-23 12:10:26+03:00, kroki@stripped +1 -2
    We no longer have my_tz_find_with_opening_tz_tables(), its functions is
    performed by my_tz_find().

  sql/mysql_priv.h@stripped, 2007-01-23 12:10:26+03:00, kroki@stripped +6 -0
    Add functions to work with MySQL system tables.

  sql/set_var.cc@stripped, 2007-01-23 12:10:26+03:00, kroki@stripped +2 -4
    my_tz_find() no longer takes table list, but takes THD pointer now.

  sql/sp.cc@stripped, 2007-01-23 12:10:26+03:00, kroki@stripped +19 -69
    Remove close_proc_table().  Use close_system_tables() instead.
    
    Use open_system_tables_for_read() and open_system_table_for_update().

  sql/sp.h@stripped, 2007-01-23 12:10:26+03:00, kroki@stripped +0 -1
    Remove close_proc_table() declaration.

  sql/sql_base.cc@stripped, 2007-01-23 12:10:27+03:00, kroki@stripped +110 -0
    Add implementation of open_system_tables_for_read(),
    close_system_tables(), open_system_table_for_update().

  sql/sql_help.cc@stripped, 2007-01-23 12:10:27+03:00, kroki@stripped +8 -2
    Operate on MySQL system tables mysql.help_* with
    open_system_tables_for_read() and close_system_tables() to allow the
    usage of HELP statement under LOCK TABLES.

  sql/sql_lex.cc@stripped, 2007-01-23 12:10:27+03:00, kroki@stripped +0 -27
    Remove LEX::time_zone_tables_used and
    LEX::add_time_zone_tables_to_query_tables() which are no longer used.

  sql/sql_lex.h@stripped, 2007-01-23 12:10:27+03:00, kroki@stripped +0 -6
    Remove LEX::time_zone_tables_used and
    LEX::add_time_zone_tables_to_query_tables() which are no longer used.

  sql/sql_parse.cc@stripped, 2007-01-23 12:10:27+03:00, kroki@stripped +4 -9
    Remove references to LEX::time_zone_tables_used and
    my_tz_check_n_skip_implicit_tables() which are no longer used.

  sql/sql_show.cc@stripped, 2007-01-23 12:10:27+03:00, kroki@stripped +1 -1
    Use close_system_tables() instead of removed close_proc_table().

  sql/sql_view.cc@stripped, 2007-01-23 12:10:27+03:00, kroki@stripped +0 -2
    LEX::time_zone_tables_used is no longer there.

  sql/sql_yacc.yy@stripped, 2007-01-23 12:10:27+03:00, kroki@stripped +1 -8
    LEX::add_time_zone_tables_to_query_tables() is no longer there.

  sql/table.cc@stripped, 2007-01-23 12:10:27+03:00, kroki@stripped +38 -5
    Add more tables that should be treated as MySQL system tables.

  sql/tztime.cc@stripped, 2007-01-23 12:10:27+03:00, kroki@stripped +31 -150
    Do not add time zone tables to the list of query tables in
    tz_init_table_list().
    
    Remove fake_time_zone_tables_list and my_tz_get_tables_list().
    
    In my_tz_init(), open mysql.time_zone_leap_second with
    simple_open_n_lock_tables(), but pass time zone name to my_tz_find(),
    which will open and close time zone tables as necessary.
    
    In tz_load_from_open_tables() do not call table->use_all_columns(), as
    this was already done in open_system_tables_for_read().
    
    my_tz_find() takes THD pointer instead of table list, and calls
    open_system_tables_for_read() and close_system_tables() as necessary.
    
    Remove my_tz_find_with_opening_tz_tables().

  sql/tztime.h@stripped, 2007-01-23 12:10:28+03:00, kroki@stripped +1 -34
    Remove declarations of my_tz_get_table_list(),
    my_tz_find_with_opening_tz_tables(), fake_time_zone_tables_list,
    definition of my_tz_check_n_skip_implicit_tables().
    Update prototype for my_tz_find().

# 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:	kroki
# Host:	moonlight.home
# Root:	/home/tomash/src/mysql_ab/mysql-5.1-bug9953

--- 1.68/sql/item_create.cc	2007-01-23 12:10:43 +03:00
+++ 1.69/sql/item_create.cc	2007-01-23 12:10:43 +03:00
@@ -2770,9 +2770,6 @@ Create_func_convert_tz Create_func_conve
 Item*
 Create_func_convert_tz::create(THD *thd, Item *arg1, Item *arg2, Item *arg3)
 {
-  if (thd->lex->add_time_zone_tables_to_query_tables(thd))
-    return NULL;
-
   return new (thd->mem_root) Item_func_convert_tz(arg1, arg2, arg3);
 }
 

--- 1.140/sql/item_timefunc.cc	2007-01-23 12:10:43 +03:00
+++ 1.141/sql/item_timefunc.cc	2007-01-23 12:10:43 +03:00
@@ -1948,19 +1948,6 @@ void Item_func_convert_tz::fix_length_an
 }
 
 
-bool
-Item_func_convert_tz::fix_fields(THD *thd_arg, Item **ref)
-{
-  String str;
-  if (Item_date_func::fix_fields(thd_arg, ref))
-    return TRUE;
-
-  tz_tables= thd_arg->lex->time_zone_tables_used;
-
-  return FALSE;
-}
-
-
 String *Item_func_convert_tz::val_str(String *str)
 {
   TIME time_tmp;
@@ -1995,16 +1982,17 @@ bool Item_func_convert_tz::get_date(TIME
 {
   my_time_t my_time_tmp;
   String str;
+  THD *thd= current_thd;
 
   if (!from_tz_cached)
   {
-    from_tz= my_tz_find(args[1]->val_str(&str), tz_tables);
+    from_tz= my_tz_find(thd, args[1]->val_str(&str));
     from_tz_cached= args[1]->const_item();
   }
 
   if (!to_tz_cached)
   {
-    to_tz= my_tz_find(args[2]->val_str(&str), tz_tables);
+    to_tz= my_tz_find(thd, args[2]->val_str(&str));
     to_tz_cached= args[2]->const_item();
   }
 

--- 1.76/sql/item_timefunc.h	2007-01-23 12:10:43 +03:00
+++ 1.77/sql/item_timefunc.h	2007-01-23 12:10:43 +03:00
@@ -602,8 +602,6 @@ class Time_zone;
 */
 class Item_func_convert_tz :public Item_date_func
 {
-  /* Cached pointer to list of pre-opened time zone tables. */
-  TABLE_LIST *tz_tables;
   /*
     If time zone parameters are constants we are caching objects that
     represent them (we use separate from_tz_cached/to_tz_cached members
@@ -619,7 +617,6 @@ class Item_func_convert_tz :public Item_
   double val_real() { return (double) val_int(); }
   String *val_str(String *str);
   const char *func_name() const { return "convert_tz"; }
-  bool fix_fields(THD *, Item **);
   void fix_length_and_dec();
   bool get_date(TIME *res, uint fuzzy_date);
   void cleanup();

--- 1.258/sql/log_event.cc	2007-01-23 12:10:43 +03:00
+++ 1.259/sql/log_event.cc	2007-01-23 12:10:43 +03:00
@@ -1957,8 +1957,7 @@ int Query_log_event::exec_event(struct s
       if (time_zone_len)
       {
         String tmp(time_zone_str, time_zone_len, &my_charset_bin);
-        if (!(thd->variables.time_zone=
-              my_tz_find_with_opening_tz_tables(thd, &tmp)))
+        if (!(thd->variables.time_zone= my_tz_find(thd, &tmp)))
         {
           my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), tmp.c_ptr());
           thd->variables.time_zone= global_system_variables.time_zone;

--- 1.459/sql/mysql_priv.h	2007-01-23 12:10:43 +03:00
+++ 1.460/sql/mysql_priv.h	2007-01-23 12:10:43 +03:00
@@ -1372,6 +1372,12 @@ int abort_and_upgrade_lock(ALTER_PARTITI
 void close_open_tables_and_downgrade(ALTER_PARTITION_PARAM_TYPE *lpt);
 void mysql_wait_completed_table(ALTER_PARTITION_PARAM_TYPE *lpt, TABLE *my_table);
 
+/* Functions to work with system tables. */
+bool open_system_tables_for_read(THD *thd, TABLE_LIST *table_list,
+                                 Open_tables_state *backup);
+void close_system_tables(THD *thd, Open_tables_state *backup);
+TABLE *open_system_table_for_update(THD *thd, TABLE_LIST *one_table);
+
 bool close_cached_tables(THD *thd, bool wait_for_refresh, TABLE_LIST *tables, bool
have_lock = FALSE);
 void copy_field_from_tmp_record(Field *field,int offset);
 bool fill_record(THD *thd, Field **field, List<Item> &values,

--- 1.361/sql/sql_base.cc	2007-01-23 12:10:43 +03:00
+++ 1.362/sql/sql_base.cc	2007-01-23 12:10:43 +03:00
@@ -6590,3 +6590,113 @@ has_two_write_locked_tables_with_auto_in
   }
   return 0;
 }
+
+
+/*
+  Open the system tables for read.
+
+  SYNOPSIS
+    open_system_tables_for_read()
+      thd         Thread context.
+      table_list  List of tables to open.
+      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.
+
+  NOTES
+    Thanks to restrictions which we put on opening and locking of
+    system tables for writing, we can open and lock them for reading
+    even when we already have some other tables open and locked.  One
+    must call close_system_tables() to close systems tables opened
+    with this call.
+
+  RETURN
+    FALSE   Success
+    TRUE    Error
+*/
+
+bool
+open_system_tables_for_read(THD *thd, TABLE_LIST *table_list,
+                            Open_tables_state *backup)
+{
+  DBUG_ENTER("open_system_tables_for_read");
+
+  thd->reset_n_backup_open_tables_state(backup);
+
+  bool not_used;
+  for (TABLE_LIST *tables= table_list; tables; tables= tables->next_global)
+  {
+    TABLE *table= open_table(thd, tables, thd->mem_root, &not_used,
+                             MYSQL_LOCK_IGNORE_FLUSH);
+    if (!table)
+      goto error;
+
+    DBUG_ASSERT(table->s->system_table);
+
+    table->use_all_columns();
+    table->reginfo.lock_type= tables->lock_type;
+    tables->table= table;
+  }
+
+  thd->lock= mysql_lock_tables(thd, &thd->open_tables, 1,
+                               MYSQL_LOCK_IGNORE_FLUSH, &not_used);
+  if (thd->lock)
+    DBUG_RETURN(FALSE);
+
+error:
+  close_system_tables(thd, backup);
+
+  DBUG_RETURN(TRUE);
+}
+
+
+/*
+  Close system tables, opened with open_system_tables_for_read().
+
+  SYNOPSIS
+    close_system_tables()
+      thd     Thread context
+      backup  Pointer to Open_tables_state instance which holds
+              information about tables which were open before we
+              decided to access system tables.
+*/
+
+void
+close_system_tables(THD *thd, Open_tables_state *backup)
+{
+  close_thread_tables(thd);
+  thd->restore_backup_open_tables_state(backup);
+}
+
+
+/*
+  Open one system table for update.
+
+  SYNOPSIS
+    open_system_table_for_update()
+      thd        Thread context.
+      one_table  Table to open.
+
+  NOTES
+    Table opened with this call should closed using close_thread_tables().
+
+  RETURN
+    0	Error
+    #	Pointer to TABLE object of system table
+*/
+
+TABLE *
+open_system_table_for_update(THD *thd, TABLE_LIST *one_table)
+{
+  DBUG_ENTER("open_system_table_for_update");
+
+  TABLE *table= open_ltable(thd, one_table, one_table->lock_type);
+  if (table)
+  {
+    DBUG_ASSERT(table->s->system_table);
+    table->use_all_columns();
+  }
+
+  DBUG_RETURN(table);
+}

--- 1.209/sql/sql_lex.cc	2007-01-23 12:10:43 +03:00
+++ 1.210/sql/sql_lex.cc	2007-01-23 12:10:43 +03:00
@@ -149,7 +149,6 @@ void lex_start(THD *thd, const uchar *bu
   lex->lock_option= TL_READ;
   lex->found_semicolon= 0;
   lex->safe_to_cache_query= 1;
-  lex->time_zone_tables_used= 0;
   lex->leaf_tables_insert= 0;
   lex->empty_field_list_on_rset= 0;
   lex->select_lex.select_number= 1;
@@ -2024,31 +2023,6 @@ void st_lex::first_lists_tables_same()
 
 
 /*
-  Add implicitly used time zone description tables to global table list
-  (if needed).
-
-  SYNOPSYS
-    st_lex::add_time_zone_tables_to_query_tables()
-      thd - pointer to current thread context
-
-  RETURN VALUE
-   TRUE  - error
-   FALSE - success
-*/
-
-bool st_lex::add_time_zone_tables_to_query_tables(THD *thd)
-{
-  /* We should not add these tables twice */
-  if (!time_zone_tables_used)
-  {
-    time_zone_tables_used= my_tz_get_table_list(thd, &query_tables_last);
-    if (time_zone_tables_used == &fake_time_zone_tables_list)
-      return TRUE;
-  }
-  return FALSE;
-}
-
-/*
   Link table back that was unlinked with unlink_first_table()
 
   SYNOPSIS
@@ -2117,7 +2091,6 @@ void st_lex::cleanup_after_one_table_ope
     /* remove underlying units (units of VIEW) subtree */
     select_lex.cut_subtree();
   }
-  time_zone_tables_used= 0;
 }
 
 

--- 1.248/sql/sql_lex.h	2007-01-23 12:10:43 +03:00
+++ 1.249/sql/sql_lex.h	2007-01-23 12:10:43 +03:00
@@ -1060,11 +1060,6 @@ typedef struct st_lex : public Query_tab
   bool prepared_stmt_code_is_varref;
   /* Names of user variables holding parameters (in EXECUTE) */
   List<LEX_STRING> prepared_stmt_params;
-  /*
-    Points to part of global table list which contains time zone tables
-    implicitly used by the statement.
-  */
-  TABLE_LIST *time_zone_tables_used;
   sp_head *sphead;
   sp_name *spname;
   bool sp_lex_in_use;	/* Keep track on lex usage in SPs for error handling */
@@ -1151,7 +1146,6 @@ typedef struct st_lex : public Query_tab
   TABLE_LIST *unlink_first_table(bool *link_to_local);
   void link_first_table_back(TABLE_LIST *first, bool link_to_local);
   void first_lists_tables_same();
-  bool add_time_zone_tables_to_query_tables(THD *thd);
 
   bool can_be_merged();
   bool can_use_merged();

--- 1.598/sql/sql_parse.cc	2007-01-23 12:10:43 +03:00
+++ 1.599/sql/sql_parse.cc	2007-01-23 12:10:43 +03:00
@@ -2568,8 +2568,7 @@ mysql_execute_command(THD *thd)
     Don't reset warnings when executing a stored routine.
   */
   if ((all_tables || &lex->select_lex != lex->all_selects_list ||
-       lex->sroutines.records) && !thd->spcont ||
-      lex->time_zone_tables_used)
+       lex->sroutines.records) && !thd->spcont)
     mysql_reset_errors(thd, 0);
 
 #ifdef HAVE_REPLICATION
@@ -5595,9 +5594,7 @@ check_table_access(THD *thd, ulong want_
      */
     tables->grant.orig_want_privilege= (want_access & ~SHOW_VIEW_ACL);
     if (tables->derived || tables->schema_table ||
-        (tables->table && (int)tables->table->s->tmp_table) ||
-        my_tz_check_n_skip_implicit_tables(&tables,
-                                           thd->lex->time_zone_tables_used))
+        (tables->table && (int)tables->table->s->tmp_table))
       continue;
     thd->security_ctx= sctx;
     if ((sctx->master_access & want_access) ==
@@ -7370,14 +7367,12 @@ bool multi_update_precheck(THD *thd, TAB
   /*
     Is there tables of subqueries?
   */
-  if (&lex->select_lex != lex->all_selects_list ||
lex->time_zone_tables_used)
+  if (&lex->select_lex != lex->all_selects_list)
   {
     DBUG_PRINT("info",("Checking sub query list"));
     for (table= tables; table; table= table->next_global)
     {
-      if (!my_tz_check_n_skip_implicit_tables(&table,
-                                              lex->time_zone_tables_used) &&
-          !table->table_in_first_from_clause)
+      if (!table->table_in_first_from_clause)
       {
 	if (check_access(thd, SELECT_ACL, table->db,
 			 &table->grant.privilege, 0, 0,

--- 1.374/sql/sql_show.cc	2007-01-23 12:10:43 +03:00
+++ 1.375/sql/sql_show.cc	2007-01-23 12:10:43 +03:00
@@ -3472,7 +3472,7 @@ int fill_schema_proc(THD *thd, TABLE_LIS
 
 err:
   proc_table->file->ha_index_end();
-  close_proc_table(thd, &open_tables_state_backup);
+  close_system_tables(thd, &open_tables_state_backup);
   DBUG_RETURN(res);
 }
 

--- 1.516/sql/sql_yacc.yy	2007-01-23 12:10:43 +03:00
+++ 1.517/sql/sql_yacc.yy	2007-01-23 12:10:43 +03:00
@@ -9892,14 +9892,7 @@ internal_variable_name:
 	      YYABORT;
 	    $$.var= tmp;
 	    $$.base_name= null_lex_str;
-            /*
-              If this is time_zone variable we should open time zone
-              describing tables 
-            */
-            if (tmp == &sys_time_zone &&
-                lex->add_time_zone_tables_to_query_tables(YYTHD))
-              YYABORT;
-            else if (spc && tmp == &sys_autocommit)
+            if (spc && tmp == &sys_autocommit)
             {
               /*
                 We don't allow setting AUTOCOMMIT from a stored function

--- 1.255/sql/table.cc	2007-01-23 12:10:44 +03:00
+++ 1.256/sql/table.cc	2007-01-23 12:10:44 +03:00
@@ -372,11 +372,44 @@ int open_table_def(THD *thd, TABLE_SHARE
         allow to lock such tables for writing with any other tables (even with
         other system tables) and some privilege tables need this.
       */
-      if (!(lower_case_table_names ?
-            my_strcasecmp(system_charset_info, share->table_name.str, "proc") :
-            strcmp(share->table_name.str, "proc")))
-        share->system_table= 1;
-      else
+      /*
+        KROKI FIXME: The code below probably should be more
+        sophisticated: copy table name and down case it first, then
+        lookup in the hash(?).  The first idea was to compare table
+        name prefix, but we have procs_priv table already, and prefix
+        comparrison is hard to maintain (plus we lack my_strncasecmp()
+        :-/).
+      */
+      static const char *system_table[]=
+        {
+          "help_category",
+          "help_keyword",
+          "help_relation",
+          "help_topic",
+          "proc",
+          "time_zone",
+          "time_zone_leap_second",
+          "time_zone_name",
+          "time_zone_transition",
+          "time_zone_transition_type",
+        };
+      static const int system_table_count=
+        sizeof(system_table) / sizeof(*system_table);
+      for (int i= 0; i < system_table_count; ++i)
+      {
+        bool equal;
+        if (lower_case_table_names)
+          equal= (my_strcasecmp(system_charset_info, share->table_name.str,
+                                system_table[i]) == 0);
+        else
+          equal= (strcmp(share->table_name.str, system_table[i]) == 0);
+        if (equal)
+        {
+          share->system_table= 1;
+          break;
+        }
+      }
+      if (!share->system_table)
       {
         share->log_table= check_if_log_table(share->db.length, share->db.str,
                                              share->table_name.length,

--- 1.193/mysql-test/r/view.result	2007-01-23 12:10:44 +03:00
+++ 1.194/mysql-test/r/view.result	2007-01-23 12:10:44 +03:00
@@ -898,6 +898,7 @@ drop view v1;
 drop table t1;
 create table t1 (col1 int);
 create table t2 (col1 int);
+create table t3 (col1 datetime not null);
 create view v1 as select * from t1;
 create view v2 as select * from v1;
 create view v3 as select v2.col1 from v2,t2 where v2.col1 = t2.col1;
@@ -1002,8 +1003,8 @@ ERROR HY000: The definition of table 'v2
 insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from v2));
 ERROR HY000: The definition of table 'v2' prevents operation INSERT on table 'v3'.
 insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from t2));
-insert into mysql.time_zone values ('', (select CONVERT_TZ('20050101000000','UTC','MET')
from t2));
-ERROR 23000: Column 'Use_leap_seconds' cannot be null
+insert into t3 values ((select CONVERT_TZ('20050101000000','UTC','MET') from t2));
+ERROR 23000: Column 'col1' cannot be null
 create algorithm=temptable view v4 as select * from t1;
 insert into t1 values (1),(2),(3);
 insert into t1 (col1) values ((select max(col1) from v4));
@@ -1015,7 +1016,7 @@ NULL
 3
 3
 drop view v4,v3,v2,v1;
-drop table t1,t2;
+drop table t1,t2,t3;
 create table t1 (s1 int);
 create view v1 as select * from t1;
 handler v1 open as xx;

--- 1.175/mysql-test/t/view.test	2007-01-23 12:10:44 +03:00
+++ 1.176/mysql-test/t/view.test	2007-01-23 12:10:44 +03:00
@@ -830,6 +830,7 @@ drop table t1;
 #
 create table t1 (col1 int);
 create table t2 (col1 int);
+create table t3 (col1 datetime not null);
 create view v1 as select * from t1;
 create view v2 as select * from v1;
 create view v3 as select v2.col1 from v2,t2 where v2.col1 = t2.col1;
@@ -936,7 +937,7 @@ insert into v3 (col1) values ((select ma
 insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from v2));
 insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from t2));
 -- error 1048
-insert into mysql.time_zone values ('', (select CONVERT_TZ('20050101000000','UTC','MET')
from t2));
+insert into t3 values ((select CONVERT_TZ('20050101000000','UTC','MET') from t2));
 # temporary table algorithm view should be equal to subquery in the from clause
 create algorithm=temptable view v4 as select * from t1;
 insert into t1 values (1),(2),(3);
@@ -944,7 +945,7 @@ insert into t1 (col1) values ((select ma
 select * from t1;
 
 drop view v4,v3,v2,v1;
-drop table t1,t2;
+drop table t1,t2,t3;
 
 #
 # HANDLER with VIEW

--- 1.114/sql/sql_view.cc	2007-01-23 12:10:44 +03:00
+++ 1.115/sql/sql_view.cc	2007-01-23 12:10:44 +03:00
@@ -1300,8 +1300,6 @@ ok:
     (st_select_lex_node**)&old_lex->all_selects_list;
 
 ok2:
-  if (!old_lex->time_zone_tables_used &&
thd->lex->time_zone_tables_used)
-    old_lex->time_zone_tables_used= thd->lex->time_zone_tables_used;
   DBUG_ASSERT(lex == thd->lex);
   thd->lex= old_lex;                            // Needed for prepare_security
   result= !table->prelocking_placeholder && table->prepare_security(thd);

--- 1.17/mysql-test/r/timezone2.result	2007-01-23 12:10:44 +03:00
+++ 1.18/mysql-test/r/timezone2.result	2007-01-23 12:10:44 +03:00
@@ -283,3 +283,14 @@ ldt	ldt2
 2006-04-19 16:30:00	2006-04-19 16:30:00
 drop table t1;
 drop function f1;
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (t TIMESTAMP);
+INSERT INTO t1 VALUES (NULL), (NULL);
+LOCK TABLES t1 WRITE;
+SELECT CONVERT_TZ(NOW(), 'UTC', 'Europe/Moscow') IS NULL;
+CONVERT_TZ(NOW(), 'UTC', 'Europe/Moscow') IS NULL
+0
+UPDATE t1 SET t = CONVERT_TZ(t, 'UTC', 'Europe/Moscow');
+UNLOCK TABLES;
+DROP TABLE t1;
+End of 5.1 tests

--- 1.12/mysql-test/t/timezone2.test	2007-01-23 12:10:44 +03:00
+++ 1.13/mysql-test/t/timezone2.test	2007-01-23 12:10:44 +03:00
@@ -242,3 +242,31 @@ drop table t1;
 drop function f1;
 
 # End of 5.0 tests
+
+
+#
+# BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
+# BUG#19339: CONVERT_TZ(): overly aggressive in locking time_zone_name
+# table
+#
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1 (t TIMESTAMP);
+INSERT INTO t1 VALUES (NULL), (NULL);
+
+LOCK TABLES t1 WRITE;
+
+# The following two queries should not return error that time zone
+# tables aren't locked.  We use IS NULL below to supress timestamp
+# result.
+SELECT CONVERT_TZ(NOW(), 'UTC', 'Europe/Moscow') IS NULL;
+UPDATE t1 SET t = CONVERT_TZ(t, 'UTC', 'Europe/Moscow');
+
+UNLOCK TABLES;
+
+DROP TABLE t1;
+
+
+--echo End of 5.1 tests

--- 1.43/sql/tztime.cc	2007-01-23 12:10:44 +03:00
+++ 1.44/sql/tztime.cc	2007-01-23 12:10:44 +03:00
@@ -1489,26 +1489,20 @@ extern "C" byte* my_offset_tzs_get_key(T
 
 
 /*
-  Prepare table list with time zone related tables from preallocated array
-  and add to global table list.
+  Prepare table list with time zone related tables from preallocated array.
 
   SYNOPSIS
     tz_init_table_list()
       tz_tabs         - pointer to preallocated array of MY_TZ_TABLES_COUNT
                         TABLE_LIST objects
-      global_next_ptr - pointer to variable which points to global_next member
-                        of last element of global table list (or list root
-                        then list is empty) (in/out).
 
   DESCRIPTION
     This function prepares list of TABLE_LIST objects which can be used
-    for opening of time zone tables from preallocated array. It also links
-    this list to the end of global table list (it will read and update
-    accordingly variable pointed by global_next_ptr for this).
+    for opening of time zone tables from preallocated array.
 */
 
 static void
-tz_init_table_list(TABLE_LIST *tz_tabs, TABLE_LIST ***global_next_ptr)
+tz_init_table_list(TABLE_LIST *tz_tabs)
 {
   bzero(tz_tabs, sizeof(TABLE_LIST) * MY_TZ_TABLES_COUNT);
 
@@ -1525,64 +1519,6 @@ tz_init_table_list(TABLE_LIST *tz_tabs, 
     if (i != 0)
       tz_tabs[i].prev_global= &tz_tabs[i-1].next_global;
   }
-
-  /* Link into global list */
-  tz_tabs[0].prev_global= *global_next_ptr;
-  **global_next_ptr= tz_tabs;
-  /* Update last-global-pointer to point to pointer in last table */
-  *global_next_ptr= &tz_tabs[MY_TZ_TABLES_COUNT-1].next_global;
-}
-
-
-/*
-  Fake table list object, pointer to which is returned by
-  my_tz_get_tables_list() as indication of error.
-*/
-TABLE_LIST fake_time_zone_tables_list;
-
-/*
-  Create table list with time zone related tables and add it to the end
-  of global table list.
-
-  SYNOPSIS
-    my_tz_get_table_list()
-      thd             - current thread object
-      global_next_ptr - pointer to variable which points to global_next member
-                        of last element of global table list (or list root
-                        then list is empty) (in/out).
-
-  DESCRIPTION
-    This function creates list of TABLE_LIST objects allocated in thd's
-    memroot, which can be used for opening of time zone tables. It will also
-    link this list to the end of global table list (it will read and update
-    accordingly variable pointed by global_next_ptr for this).
-
-  NOTE
-    my_tz_check_n_skip_implicit_tables() function depends on fact that
-    elements of list created are allocated as TABLE_LIST[MY_TZ_TABLES_COUNT]
-    array.
-
-  RETURN VALUES
-    Returns pointer to first TABLE_LIST object, (could be 0 if time zone
-    tables don't exist) and &fake_time_zone_tables_list in case of error.
-*/
-
-TABLE_LIST *
-my_tz_get_table_list(THD *thd, TABLE_LIST ***global_next_ptr)
-{
-  TABLE_LIST *tz_tabs;
-  DBUG_ENTER("my_tz_get_table_list");
-
-  if (!time_zone_tables_exist)
-    DBUG_RETURN(0);
-
-  if (!(tz_tabs= (TABLE_LIST *)thd->alloc(sizeof(TABLE_LIST) *
-                                          MY_TZ_TABLES_COUNT)))
-    DBUG_RETURN(&fake_time_zone_tables_list);
-
-  tz_init_table_list(tz_tabs, global_next_ptr);
-
-  DBUG_RETURN(tz_tabs);
 }
 
 
@@ -1615,8 +1551,7 @@ my_bool
 my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap)
 {
   THD *thd;
-  TABLE_LIST *tables= 0;
-  TABLE_LIST tables_buff[1+MY_TZ_TABLES_COUNT], **last_global_next_ptr;
+  TABLE_LIST leap_table;
   TABLE *table;
   Tz_names_entry *tmp_tzname;
   my_bool return_val= 1;
@@ -1678,19 +1613,13 @@ my_tz_init(THD *org_thd, const char *def
   */
 
   thd->set_db(db, sizeof(db)-1);
-  bzero((char*) &tables_buff, sizeof(TABLE_LIST));
-  tables_buff[0].alias= tables_buff[0].table_name=
+  bzero((char*) &leap_table, sizeof(TABLE_LIST));
+  leap_table.alias= leap_table.table_name=
     (char*)"time_zone_leap_second";
-  tables_buff[0].lock_type= TL_READ;
-  tables_buff[0].db= db;
-  /*
-    Fill TABLE_LIST for the rest of the time zone describing tables
-    and link it to first one.
-  */
-  last_global_next_ptr= &(tables_buff[0].next_global);
-  tz_init_table_list(tables_buff + 1, &last_global_next_ptr);
+  leap_table.lock_type= TL_READ;
+  leap_table.db= db;
 
-  if (simple_open_n_lock_tables(thd, tables_buff))
+  if (simple_open_n_lock_tables(thd, &leap_table))
   {
     sql_print_warning("Can't open and lock time zone table: %s "
                       "trying to live without them", thd->net.last_error);
@@ -1698,7 +1627,6 @@ my_tz_init(THD *org_thd, const char *def
     return_val= time_zone_tables_exist= 0;
     goto end_with_setting_default_tz;
   }
-  tables= tables_buff + 1;
 
   /*
     Now we are going to load leap seconds descriptions that are shared
@@ -1714,7 +1642,7 @@ my_tz_init(THD *org_thd, const char *def
     goto end_with_close;
   }
 
-  table= tables_buff[0].table;
+  table= leap_table.table;
   /*
     It is OK to ignore ha_index_init()/ha_index_end() return values since
     mysql.time_zone* tables are MyISAM and these operations always succeed
@@ -1771,7 +1699,7 @@ end_with_setting_default_tz:
   if (default_tzname)
   {
     String tmp_tzname(default_tzname, &my_charset_latin1);
-    if (!(global_system_variables.time_zone= my_tz_find(&tmp_tzname, tables)))
+    if (!(global_system_variables.time_zone= my_tz_find(thd, &tmp_tzname)))
     {
       sql_print_error("Fatal error: Illegal or unknown default time zone '%s'",
                       default_tzname);
@@ -1780,6 +1708,7 @@ end_with_setting_default_tz:
   }
 
 end_with_close:
+  /* KROKI FIXME: does freeing of memory works above in my_tz_find()? */
   thd->version--; /* Force close to free memory */
   close_thread_tables(thd);
 
@@ -1890,7 +1819,6 @@ tz_load_from_open_tables(const String *t
   */
   table= tz_tables->table;
   tz_tables= tz_tables->next_local;
-  table->use_all_columns();
   table->field[0]->store(tz_name->ptr(), tz_name->length(),
                          &my_charset_latin1);
   /*
@@ -1923,7 +1851,6 @@ tz_load_from_open_tables(const String *t
     using the only index in this table).
   */
   table= tz_tables->table;
-  table->use_all_columns();
   tz_tables= tz_tables->next_local;
   table->field[0]->store((longlong) tzid, TRUE);
   (void)table->file->ha_index_init(0, 1);
@@ -1951,7 +1878,6 @@ tz_load_from_open_tables(const String *t
     Right - using special index.
   */
   table= tz_tables->table;
-  table->use_all_columns();
   tz_tables= tz_tables->next_local;
   table->field[0]->store((longlong) tzid, TRUE);
   (void)table->file->ha_index_init(0, 1);
@@ -2025,7 +1951,6 @@ tz_load_from_open_tables(const String *t
     in ascending order by index scan also satisfies us.
   */
   table= tz_tables->table; 
-  table->use_all_columns();
   table->field[0]->store((longlong) tzid, TRUE);
   (void)table->file->ha_index_init(0, 1);
 
@@ -2235,8 +2160,8 @@ str_to_offset(const char *str, uint leng
 
   SYNOPSIS
     my_tz_find()
+      thd  - pointer to thread THD structure
       name - time zone specification
-      tz_tables - list of opened'n'locked time zone describing tables
 
   DESCRIPTION
     This function checks if name is one of time zones described in db,
@@ -2258,11 +2183,10 @@ str_to_offset(const char *str, uint leng
     values as parameter without additional external check and this property
     is used by @@time_zone variable handling code).
 
-    It will perform lookup in system tables (mysql.time_zone*) if needed
-    using tz_tables as list of already opened tables (for info about this
-    list look at tz_load_from_open_tables() description). It won't perform
-    such lookup if no time zone describing tables were found during server
-    start up.
+    It will perform lookup in system tables (mysql.time_zone*),
+    opening and locking them, and closing afterwards. It won't perform
+    such lookup if no time zone describing tables were found during
+    server start up.
 
   RETURN VALUE
     Pointer to corresponding Time_zone object. 0 - in case of bad time zone
@@ -2270,7 +2194,7 @@ str_to_offset(const char *str, uint leng
 
 */
 Time_zone *
-my_tz_find(const String * name, TABLE_LIST *tz_tables)
+my_tz_find(THD *thd, const String *name)
 {
   Tz_names_entry *tmp_tzname;
   Time_zone *result_tz= 0;
@@ -2278,8 +2202,6 @@ my_tz_find(const String * name, TABLE_LI
   DBUG_ENTER("my_tz_find");
   DBUG_PRINT("enter", ("time zone name='%s'",
                        name ? ((String *)name)->c_ptr_safe() : "NULL"));
-  DBUG_ASSERT(!time_zone_tables_exist || tz_tables ||
-              current_thd->slave_thread);
 
   if (!name)
     DBUG_RETURN(0);
@@ -2311,8 +2233,19 @@ my_tz_find(const String * name, TABLE_LI
                                                    (const byte *)name->ptr(),
                                                    name->length())))
       result_tz= tmp_tzname->tz;
-    else if (time_zone_tables_exist && tz_tables)
-      result_tz= tz_load_from_open_tables(name, tz_tables);
+    else if (time_zone_tables_exist)
+    {
+      TABLE_LIST tz_tables[MY_TZ_TABLES_COUNT];
+      Open_tables_state open_tables_state_backup;
+
+      tz_init_table_list(tz_tables);
+      if (!open_system_tables_for_read(thd, tz_tables,
+                                       &open_tables_state_backup))
+      {
+        result_tz= tz_load_from_open_tables(name, tz_tables);
+        close_system_tables(thd, &open_tables_state_backup);
+      }
+    }
   }
 
   VOID(pthread_mutex_unlock(&tz_LOCK));
@@ -2320,58 +2253,6 @@ my_tz_find(const String * name, TABLE_LI
   DBUG_RETURN(result_tz);
 }
 
-
-/*
-  A more standalone version of my_tz_find(): will open tz tables if needed.
-  This is so far only used by replication, where time zone setting does not
-  happen in the usual query context.
-
-  SYNOPSIS
-    my_tz_find_with_opening_tz_tables()
-      thd  - pointer to thread's THD structure
-      name - time zone specification
-
-  DESCRIPTION
-    This function tries to find a time zone which matches the named passed in
-    argument. If it fails, it will open time zone tables and re-try the
-    search.
-    This function is needed for the slave SQL thread, which does not do the
-    addition of time zone tables which is usually done during query parsing
-    (as time zone setting by slave does not happen in mysql_parse() but
-    before). So it needs to open tz tables by itself if needed.
-    See notes of my_tz_find() as they also apply here.
-
-  RETURN VALUE
-    Pointer to corresponding Time_zone object. 0 - in case of bad time zone
-    specification or other error.
-*/
-
-Time_zone *my_tz_find_with_opening_tz_tables(THD *thd, const String *name)
-{
-  Time_zone *tz;
-  DBUG_ENTER("my_tz_find_with_opening_tables");
-  DBUG_ASSERT(thd);
-  DBUG_ASSERT(thd->slave_thread); // intended for use with slave thread only
-
-  if (!(tz= my_tz_find(name, 0)) && time_zone_tables_exist)
-  {
-    /*
-      Probably we have not loaded this time zone yet so let us look it up in
-      our time zone tables. Note that if we don't have tz tables on this
-      slave, we don't even try.
-    */
-    TABLE_LIST tables[MY_TZ_TABLES_COUNT];
-    TABLE_LIST *dummy;
-    TABLE_LIST **dummyp= &dummy;
-    tz_init_table_list(tables, &dummyp);
-    if (simple_open_n_lock_tables(thd, tables))
-      DBUG_RETURN(0);
-    tz= my_tz_find(name, tables);
-    /* We need to close tables _now_ to not pollute coming query */
-    close_thread_tables(thd);
-  }
-  DBUG_RETURN(tz);
-}
 
 #endif /* !defined(TESTTIME) && !defined(TZINFO2SQL) */
 

--- 1.17/sql/tztime.h	2007-01-23 12:10:44 +03:00
+++ 1.18/sql/tztime.h	2007-01-23 12:10:44 +03:00
@@ -60,15 +60,11 @@ public:
 
 extern Time_zone * my_tz_UTC;
 extern Time_zone * my_tz_SYSTEM;
-extern TABLE_LIST * my_tz_get_table_list(THD *thd, TABLE_LIST ***global_next_ptr);
-extern Time_zone * my_tz_find(const String *name, TABLE_LIST *tz_tables);
-extern Time_zone * my_tz_find_with_opening_tz_tables(THD *thd, const String *name);
+extern Time_zone * my_tz_find(THD *thd, const String *name);
 extern my_bool     my_tz_init(THD *org_thd, const char *default_tzname, my_bool
bootstrap);
 extern void        my_tz_free();
 extern my_time_t   sec_since_epoch_TIME(TIME *t);
 
-extern TABLE_LIST fake_time_zone_tables_list;
-
 /*
   Number of elements in table list produced by my_tz_get_table_list()
   (this table list contains tables which are needed for dynamical loading
@@ -78,34 +74,5 @@ extern TABLE_LIST fake_time_zone_tables_
 
 static const int MY_TZ_TABLES_COUNT= 4;
 
-/*
-  Check if we have pointer to the begining of list of implicitly used time
-  zone tables, set SELECT_ACL for them and fast-forward to its end.
-
-  SYNOPSIS
-    my_tz_check_n_skip_implicit_tables()
-      table     - (in/out) pointer to element of table list to check
-      tz_tables - list of implicitly used time zone tables received
-                  from my_tz_get_table_list() function.
-
-  NOTE
-    This function relies on my_tz_get_table_list() implementation.
-
-  RETURN VALUE
-    TRUE  - if table points to the beggining of tz_tables list
-    FALSE - otherwise.
-*/
-inline bool my_tz_check_n_skip_implicit_tables(TABLE_LIST **table,
-                                               TABLE_LIST *tz_tables)
-{
-  if (*table == tz_tables)
-  {
-    for (int i= 0; i < MY_TZ_TABLES_COUNT; i++)
-      (*table)[i].grant.privilege= SELECT_ACL;
-    (*table)+= MY_TZ_TABLES_COUNT - 1;
-    return TRUE;
-  }
-  return FALSE;
-}
 
 #endif /* !defined(TESTTIME) && !defined(TZINFO2SQL) */

--- 1.202/sql/set_var.cc	2007-01-23 12:10:44 +03:00
+++ 1.203/sql/set_var.cc	2007-01-23 12:10:44 +03:00
@@ -2881,8 +2881,7 @@ bool sys_var_thd_time_zone::check(THD *t
   String str(buff, sizeof(buff), &my_charset_latin1);
   String *res= var->value->val_str(&str);
 
-  if (!(var->save_result.time_zone=
-        my_tz_find(res, thd->lex->time_zone_tables_used)))
+  if (!(var->save_result.time_zone= my_tz_find(thd, res)))
   {
     my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
     return 1;
@@ -2943,8 +2942,7 @@ void sys_var_thd_time_zone::set_default(
        We are guaranteed to find this time zone since its existence
        is checked during start-up.
      */
-     global_system_variables.time_zone=
-       my_tz_find(&str, thd->lex->time_zone_tables_used);
+     global_system_variables.time_zone= my_tz_find(thd, &str);
    }
    else
      global_system_variables.time_zone= my_tz_SYSTEM;

--- 1.131/sql/sp.cc	2007-01-23 12:10:44 +03:00
+++ 1.132/sql/sp.cc	2007-01-23 12:10:44 +03:00
@@ -70,24 +70,6 @@ enum
 
 
 /*
-  Close mysql.proc, opened with open_proc_table_for_read().
-
-  SYNOPSIS
-    close_proc_table()
-      thd     Thread context
-      backup  Pointer to Open_tables_state instance which holds
-              information about tables which were open before we
-              decided to access mysql.proc.
-*/
-
-void close_proc_table(THD *thd, Open_tables_state *backup)
-{
-  close_thread_tables(thd);
-  thd->restore_backup_open_tables_state(backup);
-}
-
-
-/*
   Open the mysql.proc table for read.
 
   SYNOPSIS
@@ -97,13 +79,6 @@ void close_proc_table(THD *thd, Open_tab
               currently open tables will be saved, and from which will be
               restored when we will end work with mysql.proc.
 
-  NOTES
-    Thanks to restrictions which we put on opening and locking of
-    this table for writing, we can open and lock it for reading
-    even when we already have some other tables open and locked.
-    One must call close_proc_table() to close table opened with
-    this call.
-
   RETURN
     0	Error
     #	Pointer to TABLE object of mysql.proc
@@ -111,38 +86,18 @@ void close_proc_table(THD *thd, Open_tab
 
 TABLE *open_proc_table_for_read(THD *thd, Open_tables_state *backup)
 {
-  TABLE_LIST tables;
-  TABLE *table;
-  bool not_used;
-  DBUG_ENTER("open_proc_table");
-
-  thd->reset_n_backup_open_tables_state(backup);
-
-  bzero((char*) &tables, sizeof(tables));
-  tables.db= (char*) "mysql";
-  tables.table_name= tables.alias= (char*)"proc";
-  if (!(table= open_table(thd, &tables, thd->mem_root, &not_used,
-                          MYSQL_LOCK_IGNORE_FLUSH)))
-  {
-    thd->restore_backup_open_tables_state(backup);
-    DBUG_RETURN(0);
-  }
-  table->use_all_columns();
+  DBUG_ENTER("open_proc_table_for_read");
 
-  DBUG_ASSERT(table->s->system_table);
+  TABLE_LIST table;
+  bzero((char*) &table, sizeof(table));
+  table.db= (char*) "mysql";
+  table.table_name= table.alias= (char*)"proc";
+  table.lock_type= TL_READ;
 
-  table->reginfo.lock_type= TL_READ;
-  /*
-    We have to ensure we are not blocked by a flush tables, as this
-    could lead to a deadlock if we have other tables opened.
-  */
-  if (!(thd->lock= mysql_lock_tables(thd, &table, 1,
-                                     MYSQL_LOCK_IGNORE_FLUSH, &not_used)))
-  {
-    close_proc_table(thd, backup);
+  if (!open_system_tables_for_read(thd, &table, backup))
+    DBUG_RETURN(table.table);
+  else
     DBUG_RETURN(0);
-  }
-  DBUG_RETURN(table);
 }
 
 
@@ -163,20 +118,15 @@ TABLE *open_proc_table_for_read(THD *thd
 
 static TABLE *open_proc_table_for_update(THD *thd)
 {
-  TABLE_LIST tables;
-  TABLE *table;
-  DBUG_ENTER("open_proc_table");
-
-  bzero((char*) &tables, sizeof(tables));
-  tables.db= (char*) "mysql";
-  tables.table_name= tables.alias= (char*)"proc";
-  tables.lock_type= TL_WRITE;
+  DBUG_ENTER("open_proc_table_for_update");
 
-  table= open_ltable(thd, &tables, TL_WRITE);
-  if (table)
-    table->use_all_columns();
+  TABLE_LIST table;
+  bzero((char*) &table, sizeof(table));
+  table.db= (char*) "mysql";
+  table.table_name= table.alias= (char*)"proc";
+  table.lock_type= TL_WRITE;
 
-  DBUG_RETURN(table);
+  DBUG_RETURN(open_system_table_for_update(thd, &table));
 }
 
 
@@ -365,7 +315,7 @@ db_find_routine(THD *thd, int type, sp_n
   chistics.comment.str= ptr;
   chistics.comment.length= length;
 
-  close_proc_table(thd, &open_tables_state_backup);
+  close_system_tables(thd, &open_tables_state_backup);
   table= 0;
 
   ret= db_load_routine(thd, type, name, sphp,
@@ -374,7 +324,7 @@ db_find_routine(THD *thd, int type, sp_n
                        
  done:
   if (table)
-    close_proc_table(thd, &open_tables_state_backup);
+    close_system_tables(thd, &open_tables_state_backup);
   DBUG_RETURN(ret);
 }
 
@@ -1138,7 +1088,7 @@ sp_routine_exists_in_table(THD *thd, int
   {
     if ((ret= db_find_routine_aux(thd, type, name, table)) != SP_OK)
       ret= SP_KEY_NOT_FOUND;
-    close_proc_table(thd, &open_tables_state_backup);
+    close_system_tables(thd, &open_tables_state_backup);
   }
   return ret;
 }

--- 1.36/sql/sp.h	2007-01-23 12:10:44 +03:00
+++ 1.37/sql/sp.h	2007-01-23 12:10:44 +03:00
@@ -101,7 +101,6 @@ extern "C" byte* sp_sroutine_key(const b
   we already have some tables open and locked.
 */
 TABLE *open_proc_table_for_read(THD *thd, Open_tables_state *backup);
-void close_proc_table(THD *thd, Open_tables_state *backup);
 
 
 /*

--- 1.53/sql/sql_help.cc	2007-01-23 12:10:44 +03:00
+++ 1.54/sql/sql_help.cc	2007-01-23 12:10:44 +03:00
@@ -656,8 +656,9 @@ bool mysqld_help(THD *thd, const char *m
   tables[3].lock_type= TL_READ;
   tables[0].db= tables[1].db= tables[2].db= tables[3].db= (char*) "mysql";
 
-  if (open_and_lock_tables(thd, tables))
-    goto error;
+  Open_tables_state open_tables_state_backup;
+  if (open_system_tables_for_read(thd, tables, &open_tables_state_backup))
+    goto error2;
 
   /*
     Init tables and fields to be usable from items
@@ -780,8 +781,13 @@ bool mysqld_help(THD *thd, const char *m
   }
   send_eof(thd);
 
+  close_system_tables(thd, &open_tables_state_backup);
   DBUG_RETURN(FALSE);
+
 error:
+  close_system_tables(thd, &open_tables_state_backup);
+
+error2:
   DBUG_RETURN(TRUE);
 }
 
Thread
bk commit into 5.1 tree (kroki:1.2383) BUG#9953kroki23 Jan