List:Internals« Previous MessageNext Message »
From:dlenev Date:July 13 2005 10:20am
Subject:bk commit into 5.0 tree (dlenev:1.1917)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of dlenev. When dlenev 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.1917 05/07/13 14:20:42 dlenev@stripped +9 -0
  Merge bk-internal.mysql.com:/home/bk/mysql-5.0
  into  mysql.com:/home/dlenev/src/mysql-5.0-mysqlproc

  sql/sp.cc
    1.82 05/07/13 14:20:38 dlenev@stripped +1 -3
    Manual merge.

  sql/share/errmsg.txt
    1.39 05/07/13 14:20:38 dlenev@stripped +2 -2
    Manual merge.

  sql/sql_lex.h
    1.188 05/07/13 13:57:01 dlenev@stripped +0 -0
    Auto merged

  sql/sql_lex.cc
    1.155 05/07/13 13:57:01 dlenev@stripped +0 -0
    Auto merged

  sql/sql_base.cc
    1.267 05/07/13 13:57:01 dlenev@stripped +0 -0
    Auto merged

  sql/sp.h
    1.24 05/07/13 13:57:01 dlenev@stripped +0 -0
    Auto merged

  sql/mysql_priv.h
    1.325 05/07/13 13:57:01 dlenev@stripped +0 -0
    Auto merged

  mysql-test/t/sp-error.test
    1.79 05/07/13 13:57:01 dlenev@stripped +0 -0
    Auto merged

  mysql-test/r/sp-error.result
    1.76 05/07/13 13:57:01 dlenev@stripped +0 -0
    Auto merged

# 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:	dlenev
# Host:	brandersnatch.localdomain
# Root:	/home/dlenev/src/mysql-5.0-mysqlproc/RESYNC

--- 1.324/sql/mysql_priv.h	2005-07-13 03:50:38 +04:00
+++ 1.325/sql/mysql_priv.h	2005-07-13 13:57:01 +04:00
@@ -735,7 +735,7 @@
 bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create);
 TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update);
 TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT* mem,
-		  bool *refresh);
+		  bool *refresh, uint flags);
 TABLE *reopen_name_locked_table(THD* thd, TABLE_LIST* table);
 TABLE *find_locked_table(THD *thd, const char *db,const char *table_name);
 bool reopen_table(TABLE *table,bool locked);

--- 1.266/sql/sql_base.cc	2005-07-12 18:26:16 +04:00
+++ 1.267/sql/sql_base.cc	2005-07-13 13:57:01 +04:00
@@ -542,10 +542,9 @@
 
 bool close_thread_table(THD *thd, TABLE **table_ptr)
 {
-  DBUG_ENTER("close_thread_table");
-
   bool found_old_table= 0;
   TABLE *table= *table_ptr;
+  DBUG_ENTER("close_thread_table");
   DBUG_ASSERT(table->key_read == 0);
   DBUG_ASSERT(table->file->inited == handler::NONE);
 
@@ -972,18 +971,34 @@
 }
 
 
-/******************************************************************************
-** open a table
-** Uses a cache of open tables to find a table not in use.
-** If refresh is a NULL pointer, then the is no version number checking and
-** the table is not put in the thread-open-list
-** If the return value is NULL and refresh is set then one must close
-** all tables and retry the open
-******************************************************************************/
+/*
+  Open a table.
+
+  SYNOPSIS
+    open_table()
+      thd         Thread context
+      table_list  Open first table in list
+      refresh     Pointer to memory that will be set to 1 if
+                  we need to close all tables and reopen them
+                  If this is a NULL pointer, then the is no version
+                  number checking and the table is not put in the
+                  thread-open-list
+      flags       Bitmap of flags to modify how open works:
+                    MYSQL_LOCK_IGNORE_FLUSH - Open table even if someone
+                    has done a flush or namelock on it.
+
+  IMPLEMENTATION
+    Uses a cache of open tables to find a table not in use.
+
+  RETURN
+    NULL  Open failed.  If refresh is set then one should close
+          all other tables and retry the open
+    #     Success. Pointer to TABLE object for open table.
+*/
 
 
 TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
-		  bool *refresh)
+		  bool *refresh, uint flags)
 {
   reg1	TABLE *table;
   char	key[MAX_DBKEY_LENGTH];
@@ -1096,9 +1111,16 @@
   {
     if (table->s->version != refresh_version)
     {
+      if (flags & MYSQL_LOCK_IGNORE_FLUSH)
+      {
+        /* Force close at once after usage */
+        thd->version= table->s->version;
+        continue;
+      }
+
       /*
-      ** There is a refresh in progress for this table
-      ** Wait until the table is freed or the thread is killed.
+        There is a refresh in progress for this table
+        Wait until the table is freed or the thread is killed.
       */
       close_old_data_files(thd,thd->open_tables,0,0);
       if (table->in_use != thd)
@@ -1681,6 +1703,15 @@
   if (error == 5)
     DBUG_RETURN(0);	// we have just opened VIEW
 
+  /*
+    We can't mark all tables in 'mysql' database as system since we don't
+    allow to lock such tables for writing with any other tables (even with
+    other system tables) and some privilege tables need this.
+  */
+  if (!my_strcasecmp(system_charset_info, db, "mysql") &&
+      !my_strcasecmp(system_charset_info, name, "proc"))
+    entry->s->system_table= 1;
+
   if (Table_triggers_list::check_n_load(thd, db, name, entry))
     goto err;
 
@@ -1832,7 +1863,7 @@
     }
     (*counter)++;
     if (!tables->table &&
-	!(tables->table= open_table(thd, tables, &new_frm_mem, &refresh)))
+	!(tables->table= open_table(thd, tables, &new_frm_mem, &refresh, 0)))
     {
       free_root(&new_frm_mem, MYF(MY_KEEP_PREALLOC));
       if (tables->view)
@@ -2003,7 +2034,7 @@
   thd->current_tablenr= 0;
   /* open_ltable can be used only for BASIC TABLEs */
   table_list->required_type= FRMTYPE_TABLE;
-  while (!(table= open_table(thd, table_list, thd->mem_root, &refresh)) &&
+  while (!(table= open_table(thd, table_list, thd->mem_root, &refresh, 0)) &&
          refresh)
     ;
 

--- 1.154/sql/sql_lex.cc	2005-07-09 23:11:02 +04:00
+++ 1.155/sql/sql_lex.cc	2005-07-13 13:57:01 +04:00
@@ -145,7 +145,7 @@
   lex->found_semicolon= 0;
   lex->safe_to_cache_query= 1;
   lex->time_zone_tables_used= 0;
-  lex->leaf_tables_insert= lex->proc_table= lex->query_tables= 0;
+  lex->leaf_tables_insert= lex->query_tables= 0;
   lex->query_tables_last= &lex->query_tables;
   lex->variables_used= 0;
   lex->select_lex.parent_lex= lex;

--- 1.187/sql/sql_lex.h	2005-07-09 21:55:09 +04:00
+++ 1.188/sql/sql_lex.h	2005-07-13 13:57:01 +04:00
@@ -719,7 +719,6 @@
     function)
   */
   TABLE_LIST **query_tables_last;
-  TABLE_LIST *proc_table; /* refer to mysql.proc if it was opened by VIEW */
   /* store original leaf_tables for INSERT SELECT and PS/SP */
   TABLE_LIST *leaf_tables_insert;
 

--- 1.38/sql/share/errmsg.txt	2005-07-07 20:47:13 +04:00
+++ 1.39/sql/share/errmsg.txt	2005-07-13 14:20:38 +04:00
@@ -5368,3 +5368,5 @@
         eng "Too big precision %d specified for column '%-.64s'. Maximum is %d."
 ER_SCALE_BIGGER_THAN_PRECISION 42000 S1009
         eng "Scale may not be larger than the precision (column '%-.64s')."
+ER_WRONG_LOCK_OF_SYSTEM_TABLE
+        eng "You can't combine write-locking of system '%-.64s.%-.64s' table with other tables"

--- 1.75/mysql-test/r/sp-error.result	2005-07-11 14:46:32 +04:00
+++ 1.76/mysql-test/r/sp-error.result	2005-07-13 13:57:01 +04:00
@@ -286,6 +286,19 @@
 call p(42, @tmp_y, 43)|
 ERROR 42000: OUT or INOUT argument 3 for routine test.p is not a variable
 drop procedure p|
+create procedure p() begin end|
+lock table t1 read|
+call p()|
+unlock tables|
+drop procedure p|
+lock tables t1 read, mysql.proc write|
+ERROR HY000: You can't combine write-locking of system 'mysql.proc' table with other tables
+lock tables mysql.proc write, mysql.user write|
+ERROR HY000: You can't combine write-locking of system 'mysql.proc' table with other tables
+lock tables t1 read, mysql.proc read|
+unlock tables|
+lock tables mysql.proc write|
+unlock tables|
 create procedure bug1965()
 begin
 declare c cursor for select val from t1 order by valname;
@@ -477,7 +490,7 @@
 select * from t1;
 end|
 lock table t1 read|
-call bug9566()|
+alter procedure bug9566 comment 'Some comment'|
 ERROR HY000: Table 'proc' was not locked with LOCK TABLES
 unlock tables|
 drop procedure bug9566|

--- 1.78/mysql-test/t/sp-error.test	2005-07-11 14:46:33 +04:00
+++ 1.79/mysql-test/t/sp-error.test	2005-07-13 13:57:01 +04:00
@@ -387,6 +387,29 @@
 
 
 #
+# Let us test that we can access mysql.proc table for routines
+# definitions lookup without locking it explicitly.
+#
+create procedure p() begin end|
+lock table t1 read|
+# This should succeed
+call p()|
+unlock tables|
+drop procedure p|
+# Let us check restrictions which this ability puts on mysql.proc locking.
+--error ER_WRONG_LOCK_OF_SYSTEM_TABLE
+lock tables t1 read, mysql.proc write|
+--error ER_WRONG_LOCK_OF_SYSTEM_TABLE
+lock tables mysql.proc write, mysql.user write|
+# Locking for read should be OK
+lock tables t1 read, mysql.proc read|
+unlock tables|
+# You also should be able lock only mysql.proc for write
+lock tables mysql.proc write|
+unlock tables|
+
+
+#
 # BUG#1965
 #
 create procedure bug1965()
@@ -676,9 +699,7 @@
 # BUG#9566: explicit LOCK TABLE and store procedures result in illegal state
 #
 # We should not think that mysql.proc table does not exist if we are unable
-# to open it under LOCK TABLE or in prelocked mode. Probably this test
-# should be removed when Monty will allow access to mysql.proc without
-# locking it.
+# to open it under LOCK TABLE or in prelocked mode.
 #
 --disable_warnings
 drop procedure if exists bug9566|
@@ -688,9 +709,11 @@
   select * from t1;
 end|
 lock table t1 read|
-# This should fail because we forgot to lock mysql.proc table explicitly
+# This should fail since we forgot to lock mysql.proc for writing
+# explicitly, and we can't open mysql.proc for _writing_ if there
+# are locked tables.
 --error 1100
-call bug9566()|
+alter procedure bug9566 comment 'Some comment'|
 unlock tables|
 # This should succeed
 drop procedure bug9566|

--- 1.81/sql/sp.cc	2005-07-11 14:46:33 +04:00
+++ 1.82/sql/sp.cc	2005-07-13 14:20:38 +04:00
@@ -62,57 +62,152 @@
 /* Tells what SP_DEFAULT_ACCESS should be mapped to */
 #define SP_DEFAULT_ACCESS_MAPPING SP_CONTAINS_SQL
 
-/* *opened=true means we opened ourselves */
-static int
-db_find_routine_aux(THD *thd, int type, sp_name *name,
-		    enum thr_lock_type ltype, TABLE **tablep, bool *opened)
+
+/*
+  Close mysql.proc, opened with open_proc_table_for_read().
+
+  SYNOPSIS
+    close_proc_table()
+      thd  Thread context
+*/
+
+static void close_proc_table(THD *thd)
 {
-  TABLE *table;
-  byte key[MAX_KEY_LENGTH];	// db, name, optional key length type
-  DBUG_ENTER("db_find_routine_aux");
-  DBUG_PRINT("enter", ("type: %d name: %*s",
-		       type, name->m_name.length, name->m_name.str));
+  close_thread_tables(thd);
+  thd->pop_open_tables_state();
+}
 
-  *opened= FALSE;
-  *tablep= 0;
+
+/*
+  Open the mysql.proc table for read.
+
+  SYNOPSIS
+    open_proc_table_for_read()
+      thd  Thread context
+
+  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
+*/
+
+static TABLE *open_proc_table_for_read(THD *thd)
+{
+  TABLE_LIST tables;
+  TABLE *table;
+  bool old_open_tables= thd->open_tables != 0;
+  bool refresh;
+  DBUG_ENTER("open_proc_table");
 
   /*
     Speed up things if mysql.proc doesn't exists. mysql_proc_table_exists
     is set when we create or read stored procedure or on flush privileges.
   */
-  if (!mysql_proc_table_exists && ltype == TL_READ)
-    DBUG_RETURN(SP_OPEN_TABLE_FAILED);
+  if (!mysql_proc_table_exists)
+    DBUG_RETURN(0);
 
-  if (thd->lex->proc_table)
-    table= thd->lex->proc_table->table;
-  else
+  if (thd->push_open_tables_state())
+    DBUG_RETURN(0);
+
+  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, &refresh,
+                          MYSQL_LOCK_IGNORE_FLUSH)))
   {
-    for (table= thd->open_tables ; table ; table= table->next)
-      if (strcmp(table->s->db, "mysql") == 0 &&
-          strcmp(table->s->table_name, "proc") == 0)
-        break;
-  }
-  if (!table)
-  {
-    TABLE_LIST tables;
-
-    memset(&tables, 0, sizeof(tables));
-    tables.db= (char*)"mysql";
-    tables.table_name= tables.alias= (char*)"proc";
-    if (! (table= open_ltable(thd, &tables, ltype)))
-    {
-      /*
-        Under explicit LOCK TABLES or in prelocked mode we should not
-        say that mysql.proc table does not exist if we are unable to
-        open it since this condition may be transient.
-      */
-      if (!(thd->locked_tables || thd->prelocked_mode))
-        mysql_proc_table_exists= 0;
-      DBUG_RETURN(SP_OPEN_TABLE_FAILED);
-    }
-    *opened= TRUE;
+    thd->pop_open_tables_state();
+    mysql_proc_table_exists= 0;
+    DBUG_RETURN(0);
+  }
+
+  DBUG_ASSERT(table->s->system_table);
+
+  table->reginfo.lock_type= TL_READ;
+  /*
+    If we have other tables opened, we have to ensure we are not blocked
+    by a flush tables or global read lock, as this could lead to a deadlock
+  */
+  if (!(thd->lock= mysql_lock_tables(thd, &table, 1,
+                                     old_open_tables ?
+                                     (MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK |
+                                      MYSQL_LOCK_IGNORE_FLUSH) : 0)))
+  {
+    close_proc_table(thd);
+    DBUG_RETURN(0);
   }
-  mysql_proc_table_exists= 1;
+  DBUG_RETURN(table);
+}
+
+
+/*
+  Open the mysql.proc table for update.
+
+  SYNOPSIS
+    open_proc_table_for_update()
+      thd  Thread context
+
+  NOTES
+    Table opened with this call should closed using close_thread_tables().
+
+  RETURN
+    0	Error
+    #	Pointer to TABLE object of mysql.proc
+*/
+
+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;
+
+  table= open_ltable(thd, &tables, TL_WRITE);
+
+  /*
+    Under explicit LOCK TABLES or in prelocked mode we should not
+    say that mysql.proc table does not exist if we are unable to
+    open and lock it for writing since this condition may be
+    transient.
+  */
+  if (!(thd->locked_tables || thd->prelocked_mode) || table)
+    mysql_proc_table_exists= test(table);
+
+  DBUG_RETURN(table);
+}
+
+
+/*
+  Find row in open mysql.proc table representing stored routine.
+
+  SYNOPSIS
+    db_find_routine_aux()
+      thd    Thread context
+      type   Type of routine to find (function or procedure)
+      name   Name of routine
+      table  TABLE object for open mysql.proc table.
+
+  RETURN VALUE
+    SP_OK           - Routine found
+    SP_KEY_NOT_FOUND- No routine with given name
+*/
+
+static int
+db_find_routine_aux(THD *thd, int type, sp_name *name, TABLE *table)
+{
+  byte key[MAX_KEY_LENGTH];	// db, name, optional key length type
+  DBUG_ENTER("db_find_routine_aux");
+  DBUG_PRINT("enter", ("type: %d name: %*s",
+		       type, name->m_name.length, name->m_name.str));
 
   /*
     Create key to find row. We have to use field->store() to be able to
@@ -122,9 +217,7 @@
     same fields.
   */
   if (name->m_name.length > table->field[1]->field_length)
-  {
     DBUG_RETURN(SP_KEY_NOT_FOUND);
-  }
   table->field[0]->store(name->m_db.str, name->m_db.length, &my_charset_bin);
   table->field[1]->store(name->m_name.str, name->m_name.length,
                          &my_charset_bin);
@@ -135,15 +228,33 @@
   if (table->file->index_read_idx(table->record[0], 0,
 				  key, table->key_info->key_length,
 				  HA_READ_KEY_EXACT))
-  {
     DBUG_RETURN(SP_KEY_NOT_FOUND);
-  }
-  *tablep= table;
 
   DBUG_RETURN(SP_OK);
 }
 
 
+/*
+  Find routine definition in mysql.proc table and create corresponding
+  sp_head object for it.
+
+  SYNOPSIS
+    db_find_routine()
+      thd   Thread context
+      type  Type of routine (TYPE_ENUM_PROCEDURE/...)
+      name  Name of routine
+      sphp  Out parameter in which pointer to created sp_head
+            object is returned (0 in case of error).
+
+  NOTE
+    This function may damage current LEX during execution, so it is good
+    idea to create temporary LEX and make it active before calling it.
+
+  RETURN VALUE
+    0     - Success
+    non-0 - Error (may be one of special codes like SP_KEY_NOT_FOUND)
+*/
+
 static int
 db_find_routine(THD *thd, int type, sp_name *name, sp_head **sphp)
 {
@@ -151,7 +262,6 @@
   TABLE *table;
   const char *params, *returns, *body;
   int ret;
-  bool opened;
   const char *definer;
   longlong created;
   longlong modified;
@@ -165,8 +275,11 @@
   DBUG_PRINT("enter", ("type: %d name: %*s",
 		       type, name->m_name.length, name->m_name.str));
 
-  ret= db_find_routine_aux(thd, type, name, TL_READ, &table, &opened);
-  if (ret != SP_OK)
+  *sphp= 0;                                     // In case of errors
+  if (!(table= open_proc_table_for_read(thd)))
+    DBUG_RETURN(SP_OPEN_TABLE_FAILED);
+
+  if ((ret= db_find_routine_aux(thd, type, name, table)) != SP_OK)
     goto done;
 
   if (table->s->fields != MYSQL_PROC_FIELD_COUNT)
@@ -258,11 +371,8 @@
   chistics.comment.str= ptr;
   chistics.comment.length= length;
 
-  if (opened)
-  {
-    opened= FALSE;
-    close_thread_tables(thd, 0, 1);
-  }
+  close_proc_table(thd);
+  table= 0;
 
   {
     String defstr;
@@ -338,9 +448,8 @@
   }
 
  done:
-
-  if (opened)
-    close_thread_tables(thd);
+  if (table)
+    close_proc_table(thd);
   DBUG_RETURN(ret);
 }
 
@@ -363,7 +472,6 @@
 {
   int ret;
   TABLE *table;
-  TABLE_LIST tables;
   char definer[HOSTNAME_LENGTH+USERNAME_LENGTH+2];
   char olddb[128];
   bool dbchanged;
@@ -378,11 +486,7 @@
     goto done;
   }
 
-  memset(&tables, 0, sizeof(tables));
-  tables.db= (char*)"mysql";
-  tables.table_name= tables.alias= (char*)"proc";
-
-  if (! (table= open_ltable(thd, &tables, TL_WRITE)))
+  if (!(table= open_proc_table_for_update(thd)))
     ret= SP_OPEN_TABLE_FAILED;
   else
   {
@@ -492,20 +596,18 @@
 {
   TABLE *table;
   int ret;
-  bool opened;
   DBUG_ENTER("db_drop_routine");
   DBUG_PRINT("enter", ("type: %d name: %*s",
 		       type, name->m_name.length, name->m_name.str));
 
-  ret= db_find_routine_aux(thd, type, name, TL_WRITE, &table, &opened);
-  if (ret == SP_OK)
+  if (!(table= open_proc_table_for_update(thd)))
+    DBUG_RETURN(SP_OPEN_TABLE_FAILED);
+  if ((ret= db_find_routine_aux(thd, type, name, table)) == SP_OK)
   {
     if (table->file->delete_row(table->record[0]))
       ret= SP_DELETE_ROW_FAILED;
   }
-
-  if (opened)
-    close_thread_tables(thd);
+  close_thread_tables(thd);
   DBUG_RETURN(ret);
 }
 
@@ -520,8 +622,9 @@
   DBUG_PRINT("enter", ("type: %d name: %*s",
 		       type, name->m_name.length, name->m_name.str));
 
-  ret= db_find_routine_aux(thd, type, name, TL_WRITE, &table, &opened);
-  if (ret == SP_OK)
+  if (!(table= open_proc_table_for_update(thd)))
+    DBUG_RETURN(SP_OPEN_TABLE_FAILED);
+  if ((ret= db_find_routine_aux(thd, type, name, table)) == SP_OK)
   {
     store_record(table,record[1]);
     table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
@@ -539,8 +642,7 @@
     if ((table->file->update_row(table->record[1],table->record[0])))
       ret= SP_WRITE_ROW_FAILED;
   }
-  if (opened)
-    close_thread_tables(thd);
+  close_thread_tables(thd);
   DBUG_RETURN(ret);
 }
 
@@ -742,20 +844,9 @@
   memset(key+keylen, (int)' ', 64-keylen); // Pad with space
   keylen= sizeof(key);
 
-  for (table= thd->open_tables ; table ; table= table->next)
-    if (strcmp(table->s->db, "mysql") == 0 &&
-	strcmp(table->s->table_name, "proc") == 0)
-      break;
-  if (! table)
-  {
-    TABLE_LIST tables;
-
-    memset(&tables, 0, sizeof(tables));
-    tables.db= (char*)"mysql";
-    tables.table_name= tables.alias= (char*)"proc";
-    if (! (table= open_ltable(thd, &tables, TL_WRITE)))
-      DBUG_RETURN(SP_OPEN_TABLE_FAILED);
-  }
+  ret= SP_OPEN_TABLE_FAILED;
+  if (!(table= open_proc_table_for_update(thd)))
+    goto err;
 
   ret= SP_OK;
   table->file->ha_index_init(0);
@@ -765,7 +856,8 @@
     int nxtres;
     bool deleted= FALSE;
 
-    do {
+    do
+    {
       if (! table->file->delete_row(table->record[0]))
 	deleted= TRUE;		/* We deleted something */
       else
@@ -785,6 +877,7 @@
 
   close_thread_tables(thd);
 
+err:
   DBUG_RETURN(ret);
 }
 
@@ -978,9 +1071,7 @@
   if (!(sp= sp_cache_lookup(&thd->sp_func_cache, name)) &&
       !cache_only)
   {
-    if (db_find_routine(thd, TYPE_ENUM_FUNCTION, name, &sp) != SP_OK)
-      sp= NULL;
-    else
+    if (db_find_routine(thd, TYPE_ENUM_FUNCTION, name, &sp) == SP_OK)
       sp_cache_insert(&thd->sp_func_cache, sp);
   }
   DBUG_RETURN(sp);
@@ -1058,26 +1149,6 @@
 }
 
 
-bool
-sp_function_exists(THD *thd, sp_name *name)
-{
-  TABLE *table;
-  bool ret= FALSE;
-  bool opened= FALSE;
-  DBUG_ENTER("sp_function_exists");
-
-  if (sp_cache_lookup(&thd->sp_func_cache, name) ||
-      db_find_routine_aux(thd, TYPE_ENUM_FUNCTION,
-			  name, TL_READ,
-			  &table, &opened) == SP_OK)
-    ret= TRUE;
-  if (opened)
-    close_thread_tables(thd, 0, 1);
-  thd->clear_error();
-  DBUG_RETURN(ret);
-}
-
-
 /*
   Structure that represents element in the set of stored routines
   used by statement or routine.
@@ -1276,8 +1347,6 @@
       LEX *oldlex= thd->lex;
       LEX *newlex= new st_lex;
       thd->lex= newlex;
-      /* Pass hint pointer to mysql.proc table */
-      newlex->proc_table= oldlex->proc_table;
       newlex->current_select= NULL;
       name.m_name.str= strchr(name.m_qname.str, '.');
       name.m_db.length= name.m_name.str - name.m_qname.str;

--- 1.23/sql/sp.h	2005-07-09 23:11:02 +04:00
+++ 1.24/sql/sp.h	2005-07-13 13:57:01 +04:00
@@ -74,9 +74,6 @@
 int
 sp_show_status_function(THD *thd, const char *wild);
 
-bool
-sp_function_exists(THD *thd, sp_name *name);
-
 
 /*
   Procedures for pre-caching of stored routines and building table list
Thread
bk commit into 5.0 tree (dlenev:1.1917)dlenev13 Jul