Commit f1c754ef authored by unknown's avatar unknown

Code cleanup (and moved sp cache to separate file).

parent 8070c06a
...@@ -56,7 +56,7 @@ sqlsources = convert.cc derror.cc field.cc field_conv.cc filesort.cc \ ...@@ -56,7 +56,7 @@ sqlsources = convert.cc derror.cc field.cc field_conv.cc filesort.cc \
sql_update.cc sql_yacc.cc table.cc thr_malloc.cc time.cc \ sql_update.cc sql_yacc.cc table.cc thr_malloc.cc time.cc \
unireg.cc uniques.cc stacktrace.c sql_union.cc hash_filo.cc \ unireg.cc uniques.cc stacktrace.c sql_union.cc hash_filo.cc \
spatial.cc gstream.cc sql_help.cc \ spatial.cc gstream.cc sql_help.cc \
sp_head.cc sp_pcontext.cc sp.cc sp_head.cc sp_pcontext.cc sp.cc sp_cache.cc
EXTRA_DIST = lib_vio.c EXTRA_DIST = lib_vio.c
......
...@@ -58,7 +58,7 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \ ...@@ -58,7 +58,7 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \
log_event.h mini_client.h sql_repl.h slave.h \ log_event.h mini_client.h sql_repl.h slave.h \
stacktrace.h sql_sort.h sql_cache.h set_var.h \ stacktrace.h sql_sort.h sql_cache.h set_var.h \
spatial.h gstream.h sp_head.h sp_pcontext.h \ spatial.h gstream.h sp_head.h sp_pcontext.h \
sp_rcontext.h sp.h sp_rcontext.h sp.h sp_cache.h
mysqld_SOURCES = sql_lex.cc sql_handler.cc \ mysqld_SOURCES = sql_lex.cc sql_handler.cc \
item.cc item_sum.cc item_buff.cc item_func.cc \ item.cc item_sum.cc item_buff.cc item_func.cc \
item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \ item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \
...@@ -87,7 +87,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc \ ...@@ -87,7 +87,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc \
mini_client.cc mini_client_errors.c pack.c\ mini_client.cc mini_client_errors.c pack.c\
stacktrace.c repl_failsafe.h repl_failsafe.cc sql_olap.cc\ stacktrace.c repl_failsafe.h repl_failsafe.cc sql_olap.cc\
gstream.cc spatial.cc sql_help.cc protocol_cursor.cc \ gstream.cc spatial.cc sql_help.cc protocol_cursor.cc \
sp_head.cc sp_pcontext.cc sp.cc sp_head.cc sp_pcontext.cc sp.cc sp_cache.cc
gen_lex_hash_SOURCES = gen_lex_hash.cc gen_lex_hash_SOURCES = gen_lex_hash.cc
gen_lex_hash_LDADD = $(LDADD) $(CXXLDFLAGS) gen_lex_hash_LDADD = $(LDADD) $(CXXLDFLAGS)
......
...@@ -18,12 +18,7 @@ ...@@ -18,12 +18,7 @@
#include "mysql_priv.h" #include "mysql_priv.h"
#include "sp.h" #include "sp.h"
#include "sp_head.h" #include "sp_head.h"
#include "sp_cache.h"
static sp_head *
sp_find_cached_function(THD *thd, char *name, uint namelen);
static sp_head *
sp_find_cached_procedure(THD *thd, char *name, uint namelen);
/* /*
* *
...@@ -102,7 +97,7 @@ db_find_routine(THD *thd, int type, char *name, uint namelen, sp_head **sphp) ...@@ -102,7 +97,7 @@ db_find_routine(THD *thd, int type, char *name, uint namelen, sp_head **sphp)
char *ptr; char *ptr;
uint length; uint length;
char buff[65]; char buff[65];
String str(buff,sizeof(buff),&my_charset_bin); String str(buff, sizeof(buff), &my_charset_bin);
// QQ Set up our own mem_root here??? // QQ Set up our own mem_root here???
ret= db_find_routine_aux(thd, type, name, namelen, TL_READ, &table, &opened); ret= db_find_routine_aux(thd, type, name, namelen, TL_READ, &table, &opened);
...@@ -132,10 +127,10 @@ db_find_routine(THD *thd, int type, char *name, uint namelen, sp_head **sphp) ...@@ -132,10 +127,10 @@ db_find_routine(THD *thd, int type, char *name, uint namelen, sp_head **sphp)
if (ptr[0] == 'N') if (ptr[0] == 'N')
suid= 0; suid= 0;
table->field[7]->val_str(&str,&str); table->field[7]->val_str(&str, &str);
ptr= 0; ptr= 0;
if ((length= str.length())) if ((length= str.length()))
ptr= strmake_root(&thd->mem_root, str.ptr(),length); ptr= strmake_root(&thd->mem_root, str.ptr(), length);
if (opened) if (opened)
{ {
...@@ -166,7 +161,7 @@ db_find_routine(THD *thd, int type, char *name, uint namelen, sp_head **sphp) ...@@ -166,7 +161,7 @@ db_find_routine(THD *thd, int type, char *name, uint namelen, sp_head **sphp)
{ {
*sphp= thd->lex->sphead; *sphp= thd->lex->sphead;
(*sphp)->sp_set_info((char *) creator, (uint) strlen(creator), (*sphp)->sp_set_info((char *) creator, (uint) strlen(creator),
created, modified, suid, created, modified, suid,
ptr, length); ptr, length);
} }
thd->lex->sql_command= oldcmd; thd->lex->sql_command= oldcmd;
...@@ -204,10 +199,10 @@ db_create_routine(THD *thd, int type, ...@@ -204,10 +199,10 @@ db_create_routine(THD *thd, int type,
table->field[0]->store(name, namelen, system_charset_info); table->field[0]->store(name, namelen, system_charset_info);
table->field[1]->store((longlong)type); table->field[1]->store((longlong)type);
table->field[2]->store(def, deflen, system_charset_info); table->field[2]->store(def, deflen, system_charset_info);
table->field[3]->store(creator, (uint) strlen(creator), system_charset_info); table->field[3]->store(creator, (uint)strlen(creator), system_charset_info);
((Field_timestamp*) table->field[5])->set_time(); ((Field_timestamp *)table->field[5])->set_time();
if (suid) if (suid)
table->field[6]->store((longlong) suid); table->field[6]->store((longlong)suid);
if (comment) if (comment)
table->field[7]->store(comment, commentlen, system_charset_info); table->field[7]->store(comment, commentlen, system_charset_info);
...@@ -257,15 +252,13 @@ sp_find_procedure(THD *thd, LEX_STRING *name) ...@@ -257,15 +252,13 @@ sp_find_procedure(THD *thd, LEX_STRING *name)
DBUG_PRINT("enter", ("name: %*s", name->length, name->str)); DBUG_PRINT("enter", ("name: %*s", name->length, name->str));
sp= sp_find_cached_procedure(thd, name->str, name->length); sp= thd->sp_proc_cache->lookup(name->str, name->length);
if (! sp) if (! sp)
{ {
if (db_find_routine(thd, TYPE_ENUM_PROCEDURE, if (db_find_routine(thd, TYPE_ENUM_PROCEDURE,
name->str, name->length, &sp) == SP_OK) name->str, name->length, &sp) == SP_OK)
{ {
HASH *phash= thd->sp_hash+TYPE_ENUM_PROCEDURE-1; thd->sp_proc_cache->insert(sp);
hash_insert(phash, (const byte*)sp);
} }
} }
...@@ -294,12 +287,10 @@ sp_drop_procedure(THD *thd, char *name, uint namelen) ...@@ -294,12 +287,10 @@ sp_drop_procedure(THD *thd, char *name, uint namelen)
sp_head *sp; sp_head *sp;
int ret; int ret;
sp= sp_find_cached_procedure(thd, name, namelen); sp= thd->sp_proc_cache->lookup(name, namelen);
if (sp) if (sp)
{ {
HASH *phash= thd->sp_hash+TYPE_ENUM_PROCEDURE-1; thd->sp_proc_cache->remove(sp);
hash_delete(phash, (byte*)sp);
delete sp; delete sp;
} }
ret= db_drop_routine(thd, TYPE_ENUM_PROCEDURE, name, namelen); ret= db_drop_routine(thd, TYPE_ENUM_PROCEDURE, name, namelen);
...@@ -322,7 +313,7 @@ sp_find_function(THD *thd, LEX_STRING *name) ...@@ -322,7 +313,7 @@ sp_find_function(THD *thd, LEX_STRING *name)
DBUG_PRINT("enter", ("name: %*s", name->length, name->str)); DBUG_PRINT("enter", ("name: %*s", name->length, name->str));
sp= sp_find_cached_function(thd, name->str, name->length); sp= thd->sp_func_cache->lookup(name->str, name->length);
if (! sp) if (! sp)
{ {
if (db_find_routine(thd, TYPE_ENUM_FUNCTION, if (db_find_routine(thd, TYPE_ENUM_FUNCTION,
...@@ -354,12 +345,10 @@ sp_drop_function(THD *thd, char *name, uint namelen) ...@@ -354,12 +345,10 @@ sp_drop_function(THD *thd, char *name, uint namelen)
sp_head *sp; sp_head *sp;
int ret; int ret;
sp= sp_find_cached_function(thd, name, namelen); sp= thd->sp_func_cache->lookup(name, namelen);
if (sp) if (sp)
{ {
HASH *fhash= thd->sp_hash+TYPE_ENUM_FUNCTION-1; thd->sp_func_cache->remove(sp);
hash_delete(fhash, (byte*)sp);
delete sp; delete sp;
} }
ret= db_drop_routine(thd, TYPE_ENUM_FUNCTION, name, namelen); ret= db_drop_routine(thd, TYPE_ENUM_FUNCTION, name, namelen);
...@@ -375,7 +364,7 @@ sp_function_exists(THD *thd, LEX_STRING *name) ...@@ -375,7 +364,7 @@ sp_function_exists(THD *thd, LEX_STRING *name)
bool ret= FALSE; bool ret= FALSE;
bool opened= FALSE; bool opened= FALSE;
if (sp_find_cached_function(thd, name->str, name->length) || if (thd->sp_func_cache->lookup(name->str, name->length) ||
db_find_routine_aux(thd, TYPE_ENUM_FUNCTION, db_find_routine_aux(thd, TYPE_ENUM_FUNCTION,
name->str, name->length, TL_READ, name->str, name->length, TL_READ,
&table, &opened) == SP_OK) &table, &opened) == SP_OK)
...@@ -434,14 +423,13 @@ sp_cache_functions(THD *thd, LEX *lex) ...@@ -434,14 +423,13 @@ sp_cache_functions(THD *thd, LEX *lex)
char *fn; char *fn;
enum_sql_command cmd= lex->sql_command; enum_sql_command cmd= lex->sql_command;
int ret= 0; int ret= 0;
HASH *fhash= thd->sp_hash+TYPE_ENUM_FUNCTION-1;
while ((fn= li++)) while ((fn= li++))
{ {
sp_head *sp; sp_head *sp;
int len= strlen(fn); int len= strlen(fn);
if (hash_search(fhash,(const byte*)fn,len)) if (thd->sp_func_cache->lookup(fn, len))
continue; continue;
if (db_find_routine(thd, TYPE_ENUM_FUNCTION, fn, len, &sp) == SP_OK) if (db_find_routine(thd, TYPE_ENUM_FUNCTION, fn, len, &sp) == SP_OK)
...@@ -449,7 +437,7 @@ sp_cache_functions(THD *thd, LEX *lex) ...@@ -449,7 +437,7 @@ sp_cache_functions(THD *thd, LEX *lex)
ret= sp_cache_functions(thd, thd->lex); ret= sp_cache_functions(thd, thd->lex);
if (ret) if (ret)
break; break;
hash_insert(fhash,(const byte*)sp); thd->sp_func_cache->insert(sp);
} }
else else
{ {
...@@ -460,24 +448,3 @@ sp_cache_functions(THD *thd, LEX *lex) ...@@ -460,24 +448,3 @@ sp_cache_functions(THD *thd, LEX *lex)
lex->sql_command= cmd; lex->sql_command= cmd;
return ret; return ret;
} }
byte *
hash_get_key_for_sp_head(const byte *ptr, uint *plen,
my_bool first)
{
return ((sp_head*)ptr)->name(plen);
}
static sp_head *
sp_find_cached_function(THD *thd, char *name, uint namelen)
{
return (sp_head*)hash_search(thd->sp_hash+TYPE_ENUM_FUNCTION-1,
(const byte*)name,namelen);
}
static sp_head *
sp_find_cached_procedure(THD *thd, char *name, uint namelen)
{
return (sp_head*)hash_search(thd->sp_hash+TYPE_ENUM_PROCEDURE-1,
(const byte*)name,namelen);
}
...@@ -387,7 +387,7 @@ sp_head::execute_procedure(THD *thd, List<Item> *args) ...@@ -387,7 +387,7 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
octx->set_item(nctx->get_oindex(i), nctx->get_item(i)); octx->set_item(nctx->get_oindex(i), nctx->get_item(i));
else else
{ // A global user variable { // A global user variable
#if 0 #if NOT_USED_NOW
// QQ This works if the parameter really is a user variable, but // QQ This works if the parameter really is a user variable, but
// for the moment we can't assure that, so it will crash if it's // for the moment we can't assure that, so it will crash if it's
// something else. So for now, we just do nothing, to avoid a crash. // something else. So for now, we just do nothing, to avoid a crash.
......
...@@ -48,7 +48,7 @@ class sp_head : public Sql_alloc ...@@ -48,7 +48,7 @@ class sp_head : public Sql_alloc
my_bool m_simple_case; // TRUE if parsing simple case, FALSE otherwise my_bool m_simple_case; // TRUE if parsing simple case, FALSE otherwise
my_bool m_multi_query; // TRUE if a procedure with SELECT(s) my_bool m_multi_query; // TRUE if a procedure with SELECT(s)
uint m_old_cmq; // Old CLIENT_MULTI_QUERIES value uint m_old_cmq; // Old CLIENT_MULTI_QUERIES value
#if 0 #if NOT_USED_NOW
// QQ We're not using this at the moment. // QQ We're not using this at the moment.
List<char *> m_calls; // Called procedures. List<char *> m_calls; // Called procedures.
List<char *> m_tables; // Used tables. List<char *> m_tables; // Used tables.
......
...@@ -37,8 +37,7 @@ ...@@ -37,8 +37,7 @@
#include <mysys_err.h> #include <mysys_err.h>
#include <sp_rcontext.h> #include <sp_rcontext.h>
#include <sp_cache.h>
byte *hash_get_key_for_sp_head(const byte*,uint*,my_bool);
/* /*
The following is used to initialise Table_ident with a internal The following is used to initialise Table_ident with a internal
...@@ -157,11 +156,9 @@ THD::THD():user_time(0), is_fatal_error(0), ...@@ -157,11 +156,9 @@ THD::THD():user_time(0), is_fatal_error(0),
hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0, hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0,
(hash_get_key) get_var_key, (hash_get_key) get_var_key,
(hash_free_key) free_user_var, 0); (hash_free_key) free_user_var, 0);
hash_init(sp_hash,system_charset_info,0,0,0, sp_proc_cache= new sp_cache();
hash_get_key_for_sp_head,0,0); sp_func_cache= new sp_cache();
hash_init(sp_hash+1,system_charset_info,0,0,0,
hash_get_key_for_sp_head,0,0);
/* For user vars replication*/ /* For user vars replication*/
if (opt_bin_log) if (opt_bin_log)
...@@ -265,10 +262,8 @@ void THD::change_user(void) ...@@ -265,10 +262,8 @@ void THD::change_user(void)
hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0, hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0,
(hash_get_key) get_var_key, (hash_get_key) get_var_key,
(hash_free_key) free_user_var, 0); (hash_free_key) free_user_var, 0);
hash_init(sp_hash,system_charset_info,0,0,0, sp_proc_cache->init();
hash_get_key_for_sp_head,0,0); sp_func_cache->init();
hash_init(sp_hash+1,system_charset_info,0,0,0,
hash_get_key_for_sp_head,0,0);
} }
...@@ -292,8 +287,8 @@ void THD::cleanup(void) ...@@ -292,8 +287,8 @@ void THD::cleanup(void)
close_temporary_tables(this); close_temporary_tables(this);
delete_dynamic(&user_var_events); delete_dynamic(&user_var_events);
hash_free(&user_vars); hash_free(&user_vars);
hash_free(sp_hash); sp_proc_cache->cleanup();
hash_free(sp_hash+1); sp_func_cache->cleanup();
if (global_read_lock) if (global_read_lock)
unlock_global_read_lock(this); unlock_global_read_lock(this);
if (ull) if (ull)
...@@ -335,6 +330,9 @@ THD::~THD() ...@@ -335,6 +330,9 @@ THD::~THD()
} }
#endif #endif
delete sp_proc_cache;
delete sp_func_cache;
DBUG_PRINT("info", ("freeing host")); DBUG_PRINT("info", ("freeing host"));
if (host != localhost) // If not pointer to constant if (host != localhost) // If not pointer to constant
safeFree(host); safeFree(host);
......
...@@ -27,6 +27,7 @@ class Query_log_event; ...@@ -27,6 +27,7 @@ class Query_log_event;
class Load_log_event; class Load_log_event;
class Slave_log_event; class Slave_log_event;
class sp_rcontext; class sp_rcontext;
class sp_cache;
enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE }; enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE };
enum enum_ha_read_modes { RFIRST, RNEXT, RPREV, RLAST, RKEY }; enum enum_ha_read_modes { RFIRST, RNEXT, RPREV, RLAST, RKEY };
...@@ -551,7 +552,8 @@ class THD :public ilink ...@@ -551,7 +552,8 @@ class THD :public ilink
bool prepare_command; bool prepare_command;
bool tmp_table_used; bool tmp_table_used;
sp_rcontext *spcont; // SP runtime context sp_rcontext *spcont; // SP runtime context
HASH sp_hash[2]; // hash for SP PROCEDURES and FUNCTIONS sp_cache *sp_proc_cache;
sp_cache *sp_func_cache;
/* /*
If we do a purge of binary logs, log index info of the threads If we do a purge of binary logs, log index info of the threads
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment