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 \
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 \
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
......
......@@ -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 \
stacktrace.h sql_sort.h sql_cache.h set_var.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 \
item.cc item_sum.cc item_buff.cc item_func.cc \
item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \
......@@ -87,7 +87,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc \
mini_client.cc mini_client_errors.c pack.c\
stacktrace.c repl_failsafe.h repl_failsafe.cc sql_olap.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_LDADD = $(LDADD) $(CXXLDFLAGS)
......
......@@ -18,12 +18,7 @@
#include "mysql_priv.h"
#include "sp.h"
#include "sp_head.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);
#include "sp_cache.h"
/*
*
......@@ -102,7 +97,7 @@ db_find_routine(THD *thd, int type, char *name, uint namelen, sp_head **sphp)
char *ptr;
uint length;
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???
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)
if (ptr[0] == 'N')
suid= 0;
table->field[7]->val_str(&str,&str);
table->field[7]->val_str(&str, &str);
ptr= 0;
if ((length= str.length()))
ptr= strmake_root(&thd->mem_root, str.ptr(),length);
ptr= strmake_root(&thd->mem_root, str.ptr(), length);
if (opened)
{
......@@ -204,10 +199,10 @@ db_create_routine(THD *thd, int type,
table->field[0]->store(name, namelen, system_charset_info);
table->field[1]->store((longlong)type);
table->field[2]->store(def, deflen, system_charset_info);
table->field[3]->store(creator, (uint) strlen(creator), system_charset_info);
((Field_timestamp*) table->field[5])->set_time();
table->field[3]->store(creator, (uint)strlen(creator), system_charset_info);
((Field_timestamp *)table->field[5])->set_time();
if (suid)
table->field[6]->store((longlong) suid);
table->field[6]->store((longlong)suid);
if (comment)
table->field[7]->store(comment, commentlen, system_charset_info);
......@@ -257,15 +252,13 @@ sp_find_procedure(THD *thd, LEX_STRING *name)
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 (db_find_routine(thd, TYPE_ENUM_PROCEDURE,
name->str, name->length, &sp) == SP_OK)
{
HASH *phash= thd->sp_hash+TYPE_ENUM_PROCEDURE-1;
hash_insert(phash, (const byte*)sp);
thd->sp_proc_cache->insert(sp);
}
}
......@@ -294,12 +287,10 @@ sp_drop_procedure(THD *thd, char *name, uint namelen)
sp_head *sp;
int ret;
sp= sp_find_cached_procedure(thd, name, namelen);
sp= thd->sp_proc_cache->lookup(name, namelen);
if (sp)
{
HASH *phash= thd->sp_hash+TYPE_ENUM_PROCEDURE-1;
hash_delete(phash, (byte*)sp);
thd->sp_proc_cache->remove(sp);
delete sp;
}
ret= db_drop_routine(thd, TYPE_ENUM_PROCEDURE, name, namelen);
......@@ -322,7 +313,7 @@ sp_find_function(THD *thd, LEX_STRING *name)
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 (db_find_routine(thd, TYPE_ENUM_FUNCTION,
......@@ -354,12 +345,10 @@ sp_drop_function(THD *thd, char *name, uint namelen)
sp_head *sp;
int ret;
sp= sp_find_cached_function(thd, name, namelen);
sp= thd->sp_func_cache->lookup(name, namelen);
if (sp)
{
HASH *fhash= thd->sp_hash+TYPE_ENUM_FUNCTION-1;
hash_delete(fhash, (byte*)sp);
thd->sp_func_cache->remove(sp);
delete sp;
}
ret= db_drop_routine(thd, TYPE_ENUM_FUNCTION, name, namelen);
......@@ -375,7 +364,7 @@ sp_function_exists(THD *thd, LEX_STRING *name)
bool ret= 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,
name->str, name->length, TL_READ,
&table, &opened) == SP_OK)
......@@ -434,14 +423,13 @@ sp_cache_functions(THD *thd, LEX *lex)
char *fn;
enum_sql_command cmd= lex->sql_command;
int ret= 0;
HASH *fhash= thd->sp_hash+TYPE_ENUM_FUNCTION-1;
while ((fn= li++))
{
sp_head *sp;
int len= strlen(fn);
if (hash_search(fhash,(const byte*)fn,len))
if (thd->sp_func_cache->lookup(fn, len))
continue;
if (db_find_routine(thd, TYPE_ENUM_FUNCTION, fn, len, &sp) == SP_OK)
......@@ -449,7 +437,7 @@ sp_cache_functions(THD *thd, LEX *lex)
ret= sp_cache_functions(thd, thd->lex);
if (ret)
break;
hash_insert(fhash,(const byte*)sp);
thd->sp_func_cache->insert(sp);
}
else
{
......@@ -460,24 +448,3 @@ sp_cache_functions(THD *thd, LEX *lex)
lex->sql_command= cmd;
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)
octx->set_item(nctx->get_oindex(i), nctx->get_item(i));
else
{ // A global user variable
#if 0
#if NOT_USED_NOW
// 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
// something else. So for now, we just do nothing, to avoid a crash.
......
......@@ -48,7 +48,7 @@ public:
my_bool m_simple_case; // TRUE if parsing simple case, FALSE otherwise
my_bool m_multi_query; // TRUE if a procedure with SELECT(s)
uint m_old_cmq; // Old CLIENT_MULTI_QUERIES value
#if 0
#if NOT_USED_NOW
// QQ We're not using this at the moment.
List<char *> m_calls; // Called procedures.
List<char *> m_tables; // Used tables.
......
......@@ -37,8 +37,7 @@
#include <mysys_err.h>
#include <sp_rcontext.h>
byte *hash_get_key_for_sp_head(const byte*,uint*,my_bool);
#include <sp_cache.h>
/*
The following is used to initialise Table_ident with a internal
......@@ -158,10 +157,8 @@ THD::THD():user_time(0), is_fatal_error(0),
(hash_get_key) get_var_key,
(hash_free_key) free_user_var, 0);
hash_init(sp_hash,system_charset_info,0,0,0,
hash_get_key_for_sp_head,0,0);
hash_init(sp_hash+1,system_charset_info,0,0,0,
hash_get_key_for_sp_head,0,0);
sp_proc_cache= new sp_cache();
sp_func_cache= new sp_cache();
/* For user vars replication*/
if (opt_bin_log)
......@@ -265,10 +262,8 @@ void THD::change_user(void)
hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0,
(hash_get_key) get_var_key,
(hash_free_key) free_user_var, 0);
hash_init(sp_hash,system_charset_info,0,0,0,
hash_get_key_for_sp_head,0,0);
hash_init(sp_hash+1,system_charset_info,0,0,0,
hash_get_key_for_sp_head,0,0);
sp_proc_cache->init();
sp_func_cache->init();
}
......@@ -292,8 +287,8 @@ void THD::cleanup(void)
close_temporary_tables(this);
delete_dynamic(&user_var_events);
hash_free(&user_vars);
hash_free(sp_hash);
hash_free(sp_hash+1);
sp_proc_cache->cleanup();
sp_func_cache->cleanup();
if (global_read_lock)
unlock_global_read_lock(this);
if (ull)
......@@ -335,6 +330,9 @@ THD::~THD()
}
#endif
delete sp_proc_cache;
delete sp_func_cache;
DBUG_PRINT("info", ("freeing host"));
if (host != localhost) // If not pointer to constant
safeFree(host);
......
......@@ -27,6 +27,7 @@ class Query_log_event;
class Load_log_event;
class Slave_log_event;
class sp_rcontext;
class sp_cache;
enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE };
enum enum_ha_read_modes { RFIRST, RNEXT, RPREV, RLAST, RKEY };
......@@ -551,7 +552,8 @@ public:
bool prepare_command;
bool tmp_table_used;
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
......
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