From aae07a4d45989b1b2a57ee01002e4a101511b512 Mon Sep 17 00:00:00 2001 From: "pem@mysql.com" <> Date: Sun, 8 Dec 2002 19:59:22 +0100 Subject: Simplistic, experimental framework for Stored Procedures (SPs). Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters, single-statement procedures, rudimentary multi-statement (begin-end) prodedures (when the client can handle it), and local variables. Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling, reparses procedures at each call (no caching), etc, etc. Certainly buggy too, but procedures can actually be created and called.... --- sql/sql_class.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index ebd1d9d2b3c..855c97715ea 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -81,7 +81,7 @@ extern "C" void free_user_var(user_var_entry *entry) THD::THD():user_time(0), fatal_error(0), last_insert_id_used(0), insert_id_used(0), rand_used(0), in_lock_tables(0), - global_read_lock(0), bootstrap(0) + global_read_lock(0), bootstrap(0), spcont(NULL) { host=user=priv_user=db=query=ip=0; host_or_ip="unknown ip"; -- cgit v1.2.1 From e6b8fa57072d29131071057fb827161346cd9df0 Mon Sep 17 00:00:00 2001 From: "Sinisa@sinisa.nasamreza.org" <> Date: Sat, 18 Jan 2003 18:21:13 +0200 Subject: SELECT ... INTO local_vars ...; For Stored Procedures --- sql/sql_class.cc | 51 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index a5fb7922243..8e66e1ca068 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -36,6 +36,7 @@ #endif #include #include +#include /***************************************************************************** @@ -960,37 +961,71 @@ bool select_exists_subselect::send_data(List &items) int select_dumpvar::prepare(List &list, SELECT_LEX_UNIT *u) { List_iterator_fast li(list); - List_iterator_fast gl(var_list); + List_iterator_fast gl(var_list); Item *item; + my_var *mv; LEX_STRING *ls; if (var_list.elements != list.elements) { my_error(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT, MYF(0)); return 1; } + unit=u; while ((item=li++)) { - ls= gl++; - Item_func_set_user_var *xx = new Item_func_set_user_var(*ls,item); - xx->fix_fields(current_thd,(TABLE_LIST*) current_thd->lex.select_lex.table_list.first,&item); - xx->fix_length_and_dec(); - vars.push_back(xx); + mv=gl++; + ls= &mv->s; + if (mv->local) + { + (void)local_vars.push_back(new Item_splocal(mv->offset)); + } + else + { + Item_func_set_user_var *xx = new Item_func_set_user_var(*ls,item); + xx->fix_fields(thd,(TABLE_LIST*) thd->lex.select_lex.table_list.first,&item); + xx->fix_length_and_dec(); + vars.push_back(xx); + } } return 0; } bool select_dumpvar::send_data(List &items) { List_iterator_fast li(vars); + List_iterator_fast var_li(local_vars); + List_iterator_fast my_li(var_list); + List_iterator_fast it(items); Item_func_set_user_var *xx; + Item_splocal *yy; + Item *item; + my_var *zz; DBUG_ENTER("send_data"); + if (unit->offset_limit_cnt) + { // using limit offset,count + unit->offset_limit_cnt--; + DBUG_RETURN(0); + } if (row_count++) { my_error(ER_TOO_MANY_ROWS, MYF(0)); DBUG_RETURN(1); } - while ((xx=li++)) - xx->update(); + while ((zz=my_li++) && (item=it++)) + { + if (zz->local) + { + if ((yy=var_li++)) + { + thd->spcont->set_item(yy->get_offset(), item); + } + } + else + { + if ((xx=li++)) + xx->update(); + } + } DBUG_RETURN(0); } -- cgit v1.2.1 From 02211a600b83d8be7e7f91e807d148a147093be3 Mon Sep 17 00:00:00 2001 From: "pem@mysql.com" <> Date: Tue, 18 Feb 2003 19:58:03 +0100 Subject: Post-merge fixes (adapting new SP code to 4.1 changes). --- sql/sql_class.cc | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 5ac904393f5..7ea9bfc1ba6 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1043,6 +1043,15 @@ bool select_dumpvar::send_data(List &items) bool select_dumpvar::send_eof() { + /* This mimics select_send::send_eof(), which unlocks this way. + * It appears to be necessary, since tables aren't unlock after + * selects otherwise. + */ + if (thd->lock) + { + mysql_unlock_tables(thd, thd->lock); + thd->lock=0; + } if (row_count) { ::send_ok(thd,row_count); -- cgit v1.2.1 From 52cd3e3142da39afb30855d24833209cae924c90 Mon Sep 17 00:00:00 2001 From: "pem@mysql.com" <> Date: Wed, 19 Feb 2003 12:42:32 +0100 Subject: Fixed SELECT INTO OUTFILE/DUMPFILE and stored procedures, and extended and reorganized the sp.test file. --- sql/sql_class.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 7ea9bfc1ba6..ac82996600f 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -801,6 +801,15 @@ void select_export::send_error(uint errcode, const char *err) bool select_export::send_eof() { + /* This mimics select_send::send_eof(), which unlocks this way. + * It appears to be necessary, since tables aren't unlock after + * selects otherwise. + */ + if (thd->lock) + { + mysql_unlock_tables(thd, thd->lock); + thd->lock=0; + } int error=test(end_io_cache(&cache)); if (my_close(file,MYF(MY_WME))) error=1; @@ -911,6 +920,15 @@ void select_dump::send_error(uint errcode,const char *err) bool select_dump::send_eof() { + /* This mimics select_send::send_eof(), which unlocks this way. + * It appears to be necessary, since tables aren't unlock after + * selects otherwise. + */ + if (thd->lock) + { + mysql_unlock_tables(thd, thd->lock); + thd->lock=0; + } int error=test(end_io_cache(&cache)); if (my_close(file,MYF(MY_WME))) error=1; -- cgit v1.2.1 From b6ab762dc15a3ac4aa2528f9c9b2ba3725afe710 Mon Sep 17 00:00:00 2001 From: "pem@mysql.com" <> Date: Fri, 28 Feb 2003 15:07:14 +0100 Subject: Closing tables during SP execution the proper way. --- sql/sql_class.cc | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index ac82996600f..5ac904393f5 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -801,15 +801,6 @@ void select_export::send_error(uint errcode, const char *err) bool select_export::send_eof() { - /* This mimics select_send::send_eof(), which unlocks this way. - * It appears to be necessary, since tables aren't unlock after - * selects otherwise. - */ - if (thd->lock) - { - mysql_unlock_tables(thd, thd->lock); - thd->lock=0; - } int error=test(end_io_cache(&cache)); if (my_close(file,MYF(MY_WME))) error=1; @@ -920,15 +911,6 @@ void select_dump::send_error(uint errcode,const char *err) bool select_dump::send_eof() { - /* This mimics select_send::send_eof(), which unlocks this way. - * It appears to be necessary, since tables aren't unlock after - * selects otherwise. - */ - if (thd->lock) - { - mysql_unlock_tables(thd, thd->lock); - thd->lock=0; - } int error=test(end_io_cache(&cache)); if (my_close(file,MYF(MY_WME))) error=1; @@ -1061,15 +1043,6 @@ bool select_dumpvar::send_data(List &items) bool select_dumpvar::send_eof() { - /* This mimics select_send::send_eof(), which unlocks this way. - * It appears to be necessary, since tables aren't unlock after - * selects otherwise. - */ - if (thd->lock) - { - mysql_unlock_tables(thd, thd->lock); - thd->lock=0; - } if (row_count) { ::send_ok(thd,row_count); -- cgit v1.2.1 From dba598cddd9c14fd15cf2f0a23f668617e4bf09b Mon Sep 17 00:00:00 2001 From: "pem@mysql.com" <> Date: Thu, 6 Mar 2003 19:16:46 +0100 Subject: Fixed reentrantness bugs in select (lex->result) and select_dumpvar, and added cool prime number test example. --- sql/sql_class.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 5ac904393f5..ee14ce16593 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -972,6 +972,8 @@ int select_dumpvar::prepare(List &list, SELECT_LEX_UNIT *u) Item *item; my_var *mv; LEX_STRING *ls; + + row_count= 0; if (var_list.elements != list.elements) { my_error(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT, MYF(0)); @@ -996,6 +998,7 @@ int select_dumpvar::prepare(List &list, SELECT_LEX_UNIT *u) } return 0; } + bool select_dumpvar::send_data(List &items) { List_iterator_fast li(vars); -- cgit v1.2.1 From f8f0b703808f19b788b57c8c35c9aa0147b48b7f Mon Sep 17 00:00:00 2001 From: "hf@genie.(none)" <> Date: Mon, 31 Mar 2003 13:39:46 +0500 Subject: SCRUM two KILL commands implementation (version 2) --- sql/sql_class.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index cf790012c37..7058b9d7b3c 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -85,8 +85,9 @@ THD::THD():user_time(0), is_fatal_error(0), { host=user=priv_user=db=query=ip=0; host_or_ip= "connecting host"; - locked=killed=count_cuted_fields=some_tables_deleted=no_errors=password= + locked=count_cuted_fields=some_tables_deleted=no_errors=password= query_start_used=prepare_command=0; + killed= NOT_KILLED; db_length=query_length=col_access=0; query_error= tmp_table_used= 0; next_insert_id=last_insert_id=0; @@ -176,7 +177,7 @@ THD::THD():user_time(0), is_fatal_error(0), if (open_cached_file(&transaction.trans_log, mysql_tmpdir, LOG_PREFIX, binlog_cache_size, MYF(MY_WME))) - killed=1; + killed= KILL_CONNECTION; transaction.trans_log.end_of_file= max_binlog_cache_size; } #endif @@ -318,14 +319,14 @@ THD::~THD() } -void THD::awake(bool prepare_to_die) +void THD::awake(THD::killed_state state_to_set) { THD_CHECK_SENTRY(this); safe_mutex_assert_owner(&LOCK_delete); - if (prepare_to_die) - killed = 1; - thr_alarm_kill(real_id); + killed= state_to_set; + if (state_to_set != THD::KILL_QUERY) + thr_alarm_kill(real_id); #ifdef SIGNAL_WITH_VIO_CLOSE close_active_vio(); #endif @@ -442,7 +443,7 @@ CHANGED_TABLE_LIST* THD::changed_table_dup(const char *key, long key_length) { my_error(EE_OUTOFMEMORY, MYF(ME_BELL), ALIGN_SIZE(sizeof(TABLE_LIST)) + key_length + 1); - killed= 1; + killed= KILL_CONNECTION; return 0; } -- cgit v1.2.1 From c673fcb813cace451070bd08e3670329a1c31c62 Mon Sep 17 00:00:00 2001 From: "pem@mysql.com" <> Date: Wed, 2 Apr 2003 20:42:28 +0200 Subject: Getting rid of lots of memory leaks (but not quite all of them yet, some will go away when temporary code is replaced). --- sql/sql_class.cc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index d5197b65071..7247d5bc3d0 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -191,6 +191,9 @@ THD::THD():user_time(0), is_fatal_error(0), pthread_mutex_unlock(&LOCK_thread_count); randominit(&rand, tmp + (ulong) &rand, tmp + (ulong) ::query_id); } + + /* QQ init the temporary function cache */ + spfuns.empty(); } @@ -282,6 +285,10 @@ void THD::cleanup(void) pthread_mutex_unlock(&LOCK_user_locks); ull= 0; } + + // extern void sp_clear_function_cache(THD *); + // sp_clear_function_cache(this); + cleanup_done=1; DBUG_VOID_RETURN; } -- cgit v1.2.1 From afd581edd39976432cd9c920ebedbca0f544a81e Mon Sep 17 00:00:00 2001 From: "vva@eagle.mysql.r18.ru" <> Date: Mon, 5 May 2003 14:54:37 -0400 Subject: made lex a pointer in THD --- sql/sql_class.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 0ead869216f..5c7091529d8 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -90,6 +90,7 @@ THD::THD():user_time(0), is_fatal_error(0), insert_id_used(0), rand_used(0), in_lock_tables(0), global_read_lock(0), bootstrap(0), spcont(NULL) { + lex= &main_lex; host=user=priv_user=db=query=ip=0; host_or_ip= "connecting host"; locked=count_cuted_fields=some_tables_deleted=no_errors=password= @@ -1040,7 +1041,7 @@ int select_dumpvar::prepare(List &list, SELECT_LEX_UNIT *u) else { Item_func_set_user_var *xx = new Item_func_set_user_var(*ls,item); - xx->fix_fields(thd,(TABLE_LIST*) thd->lex.select_lex.table_list.first,&item); + xx->fix_fields(thd,(TABLE_LIST*) thd->lex->select_lex.table_list.first,&item); xx->fix_length_and_dec(); vars.push_back(xx); } -- cgit v1.2.1 From 05c78eec38cd1b8e4ddf088ebd208eb5b34a5e2c Mon Sep 17 00:00:00 2001 From: "guilhem@mysql.com" <> Date: Mon, 12 May 2003 15:36:31 +0200 Subject: Task #627 : user variables' names are now case-insensitive : @test=@"tEsT"=@`teST` etc. Tests updated. Note that the patch to sql_class.cc does not use HASH_CASE_INSENSITIVE as did the one which I sent for review. This is because meanwhile HASH_CASE_INSENSITIVE has disappeared (since cset 1.1504.1.6). --- sql/sql_class.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 0ead869216f..7f73ed6238d 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -151,9 +151,9 @@ THD::THD():user_time(0), is_fatal_error(0), bzero((char*) &warn_root,sizeof(warn_root)); init_alloc_root(&warn_root, 1024, 0); user_connect=(USER_CONN *)0; - hash_init(&user_vars, &my_charset_bin, 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_free_key) free_user_var,0); + (hash_free_key) free_user_var, 0); /* For user vars replication*/ if (opt_bin_log) @@ -257,7 +257,7 @@ void THD::change_user(void) cleanup(); cleanup_done= 0; init(); - hash_init(&user_vars, &my_charset_bin, 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_free_key) free_user_var, 0); } -- cgit v1.2.1 From 1d3c703d58af5b98ba1055054319d5c5b521b335 Mon Sep 17 00:00:00 2001 From: "pem@mysql.com" <> Date: Tue, 1 Jul 2003 18:14:24 +0200 Subject: SP cache (WL#730). (Mostly by vva, additions by pem.) --- sql/sql_class.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index c64bb7ff8fa..5ab096b91e4 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -38,6 +38,8 @@ #include +byte *hash_get_key_for_sp_head(const byte*,uint*,my_bool); + /* The following is used to initialise Table_ident with a internal table name @@ -155,6 +157,11 @@ THD::THD():user_time(0), is_fatal_error(0), 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); /* For user vars replication*/ if (opt_bin_log) @@ -200,9 +207,6 @@ THD::THD():user_time(0), is_fatal_error(0), pthread_mutex_unlock(&LOCK_thread_count); randominit(&rand, tmp + (ulong) &rand, tmp + (ulong) ::query_id); } - - /* QQ init the temporary function cache */ - spfuns.empty(); } @@ -261,6 +265,10 @@ 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); } @@ -284,6 +292,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); if (global_read_lock) unlock_global_read_lock(this); if (ull) @@ -294,9 +304,6 @@ void THD::cleanup(void) ull= 0; } - // extern void sp_clear_function_cache(THD *); - // sp_clear_function_cache(this); - cleanup_done=1; DBUG_VOID_RETURN; } -- cgit v1.2.1 From 6d225437ed4eb35b93e991ef77d0600c2496f7a7 Mon Sep 17 00:00:00 2001 From: "pem@mysql.com" <> Date: Thu, 3 Jul 2003 15:58:37 +0200 Subject: Code cleanup (and moved sp cache to separate file). --- sql/sql_class.cc | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 5ab096b91e4..e66c70fcf21 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -37,8 +37,7 @@ #include #include - -byte *hash_get_key_for_sp_head(const byte*,uint*,my_bool); +#include /* The following is used to initialise Table_ident with a internal @@ -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_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); -- cgit v1.2.1