From 27de9ece815b04651db03ed3d413374f42c9d894 Mon Sep 17 00:00:00 2001 From: unknown 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/Makefile.am: Added SP files. sql/item.cc: Added this*_item() methods for Item_splocal. (SP local variable) sql/item.h: Added this*_item() methods for SPs in Item, and the new Item_splocal class (SP local variable). sql/lex.h: Added new symbols for SPs. (Note: SPSET is temporary and will go away later.) sql/sql_class.cc: Initialize SP runtime context in THD. sql/sql_class.h: Add SP runtime context to THD. sql/sql_lex.cc: Init. buf pointer to beginning of command (needed by SPs). Also initialize SP head and parse time context. sql/sql_lex.h: New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and SP head and parse-time context to LEX. sql/sql_parse.cc: Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases. (Still rudimentary and lacking proper error handling...) sql/sql_yacc.yy: Lots and lots of additions for SPs... (Still even more missing, and no error messages...) --- sql/sql_class.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index ca56d2dcdf5..00236aee176 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -26,6 +26,7 @@ class Query_log_event; class Load_log_event; class Slave_log_event; +class sp_rcontext; enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE }; enum enum_ha_read_modes { RFIRST, RNEXT, RPREV, RLAST, RKEY }; @@ -515,6 +516,7 @@ public: bool query_error, bootstrap, cleanup_done; bool volatile killed; bool prepare_command; + sp_rcontext *spcont; // SP runtime context /* If we do a purge of binary logs, log index info of the threads -- cgit v1.2.1 From 69047e719a6845800d0f05c04dca55d2de95feed Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 18 Jan 2003 18:21:13 +0200 Subject: SELECT ... INTO local_vars ...; For Stored Procedures --- sql/sql_class.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index a078c4bd286..f367b089fd3 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -987,13 +987,22 @@ public: bool send_eof(); }; +class my_var : public Sql_alloc { +public: + LEX_STRING s; + bool local; + uint offset; + my_var (LEX_STRING& j, bool i, uint o) : s(j), local(i), offset(o) {} + ~my_var() {} +}; class select_dumpvar :public select_result { ha_rows row_count; public: - List var_list; + List var_list; List vars; - select_dumpvar(void) { var_list.empty(); vars.empty(); row_count=0;} + List local_vars; + select_dumpvar(void) { var_list.empty(); local_vars.empty(); vars.empty(); row_count=0;} ~select_dumpvar() {} int prepare(List &list, SELECT_LEX_UNIT *u); bool send_fields(List &list, uint flag) {return 0;} -- cgit v1.2.1 From 8a9422bd2af6ea39676171b9ec16897c64104dc8 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 2 Mar 2003 19:17:41 +0100 Subject: Made FUNCTIONs work in insert and select queries, as well as nested function invocations. Had to add a cahing mechanism which is in parts an ugly kludge, but it will be reworked once the real SP caching is implemented. mysql-test/r/sp.result: New function tests. mysql-test/t/sp.test: New function tests. sql/sp.cc: Big rehack of mysql.proc table usage strategy and adding a function cache mechanism, since we need to read used functions from the db before doing anything else when executing a query. (This cache is temporary and will probably be replaced by the real thing later.) sql/sp.h: New (temporary) FUNCTION caching functions. sql/sp_head.cc: Fixed some bugs in the function and procedure execution. Disabled some data collections that's not used at the moment. sql/sp_head.h: Fixed some bugs in the function and procedure execution. Disabled some data collections that's not used at the moment. sql/sql_class.h: Added SP function cache list to thd. sql/sql_lex.cc: Added SP function name list to lex. sql/sql_lex.h: Added SP function name list to lex. sql/sql_parse.cc: Read used FUNCTIONs from db and cache them in thd before doing anything else in a query execution. (This is necessary since we can't open mysql.proc during query execution.) sql/sql_yacc.yy: Collect used function names in lex. --- sql/sql_class.h | 1 + 1 file changed, 1 insertion(+) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index f316272ff0e..7740a54d007 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -553,6 +553,7 @@ public: bool prepare_command; bool tmp_table_used; sp_rcontext *spcont; // SP runtime context + List spfuns; // SP FUNCTIONs /* If we do a purge of binary logs, log index info of the threads -- cgit v1.2.1 From 744942beab531d724032133bba44bd6d0cc8d42f Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 21 Mar 2003 09:37:01 +0400 Subject: SCRUM two versions of KILL implementation include/mysql_com.h: ONLY_KILL_QUERY flag definition sql/lex.h: CONNECTION keyword added sql/mysql_priv.h: kill_one_thread function extended sql/sql_class.h: only_kill_query flag added to the THD structure sql/sql_parse.cc: handling of KILL QUERY feature added sql/sql_yacc.yy: KILL syntax extended with CONNECTION an QUERY options --- sql/sql_class.h | 1 + 1 file changed, 1 insertion(+) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index 7740a54d007..cc935bd69bb 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -550,6 +550,7 @@ public: bool system_thread,in_lock_tables,global_read_lock; bool query_error, bootstrap, cleanup_done; bool volatile killed; + bool volatile only_kill_query; bool prepare_command; bool tmp_table_used; sp_rcontext *spcont; // SP runtime context -- cgit v1.2.1 From 3814f2a8edf71a964cdbd8c965790d7216eff9fa Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 31 Mar 2003 13:39:46 +0500 Subject: SCRUM two KILL commands implementation (version 2) include/mysqld_error.h: Error message about query interruption added myisam/mi_check.c: killed_ptr now retutns only value - not pointer myisam/myisamchk.c: killed_ptr returns value now myisam/myisamdef.h: killed_ptr returns value now myisam/sort.c: killed_ptr returns value now sql/filesort.cc: THD::killed now has enum type sql/ha_berkeley.cc: THD::killed has enum type sql/ha_myisam.cc: killed_ptr returns value now sql/lock.cc: two different errors possible here now sql/log_event.cc: two ways of killing possible here now sql/mysqld.cc: THD::killed has enum type now sql/records.cc: two errors are possible here now sql/share/czech/errmsg.txt: new error message sql/share/danish/errmsg.txt: new error message sql/share/dutch/errmsg.txt: new error message sql/share/english/errmsg.txt: new error message sql/share/estonian/errmsg.txt: new error message sql/share/french/errmsg.txt: new error message sql/share/german/errmsg.txt: new error message sql/share/greek/errmsg.txt: new error message sql/share/hungarian/errmsg.txt: new error message sql/share/italian/errmsg.txt: new error message sql/share/japanese/errmsg.txt: new error message sql/share/korean/errmsg.txt: new error message sql/share/norwegian-ny/errmsg.txt: new error message sql/share/norwegian/errmsg.txt: new error message sql/share/polish/errmsg.txt: new error message sql/share/portuguese/errmsg.txt: new error message sql/share/romanian/errmsg.txt: new error message sql/share/russian/errmsg.txt: new error message sql/share/serbian/errmsg.txt: new error message sql/share/slovak/errmsg.txt: new error message sql/share/spanish/errmsg.txt: new error message sql/share/swedish/errmsg.txt: new error message sql/share/ukrainian/errmsg.txt: new error message sql/slave.cc: two errors are possible here now sql/sql_base.cc: THD::killed has enum type now sql/sql_cache.cc: THD::killed has enum type now sql/sql_class.cc: THD::awake implementation changed to handle KILL_QUERY sql/sql_class.h: class THD changed to handle KILL_QUERY sql/sql_delete.cc: two errors are possible here now sql/sql_insert.cc: THD::killed has enum type now sql/sql_load.cc: two errors are possible here now sql/sql_parse.cc: kill_one_thread function changed to handle KILL_QUERY sql/sql_prepare.cc: two errors are possible here now sql/sql_repl.cc: the parameter to awake is of THD::killed_state type now sql/sql_repl.h: awake parameter changed sql/sql_select.cc: two errors are possible here now sql/sql_show.cc: notification adopted to changes in class THD sql/sql_table.cc: two errors are possible here now sql/sql_update.cc: two errors are possible here now --- sql/sql_class.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index f1817876fc3..1e293fd0323 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -548,8 +548,10 @@ public: bool query_start_used,last_insert_id_used,insert_id_used,rand_used; bool system_thread,in_lock_tables,global_read_lock; bool query_error, bootstrap, cleanup_done; - bool volatile killed; - bool volatile only_kill_query; + + enum killed_state { NOT_KILLED=0, KILL_CONNECTION=ER_SERVER_SHUTDOWN, KILL_QUERY=ER_QUERY_INTERRUPTED }; + killed_state volatile killed; + bool prepare_command; bool tmp_table_used; sp_rcontext *spcont; // SP runtime context @@ -592,7 +594,7 @@ public: } void close_active_vio(); #endif - void awake(bool prepare_to_die); + void awake(THD::killed_state state_to_set); inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex, const char* msg) { -- cgit v1.2.1 From 131d90001f2eca14d3497207b57fcd484c3f8927 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 8 Apr 2003 19:18:33 +0500 Subject: SCRUM two KILL versions code trimming with headquarter's suggestions myisam/mi_check.c: killed_ptr function changed backward myisam/myisamchk.c: killed_ptr function changed backward myisam/myisamdef.h: killed_ptr function changed backward myisam/sort.c: killed_ptr function changed backward sql/ha_myisam.cc: killed_ptr function changed backward sql/lock.cc: error sending trimmed sql/log_event.cc: error sending trimmed sql/records.cc: error sending trimmed sql/slave.cc: error sending trimmed sql/sql_class.h: inline functions to send right message about killing added sql/sql_delete.cc: error sending trimmed sql/sql_load.cc: error sending trimmed sql/sql_parse.cc: error sending trimmed sql/sql_prepare.cc: error sending trimmed sql/sql_select.cc: error sending trimmed sql/sql_table.cc: error sending trimmed sql/sql_update.cc: error sending trimmed --- sql/sql_class.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index 96a3bb7051f..605d86e9684 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -527,6 +527,14 @@ public: enum killed_state { NOT_KILLED=0, KILL_CONNECTION=ER_SERVER_SHUTDOWN, KILL_QUERY=ER_QUERY_INTERRUPTED }; killed_state volatile killed; + inline int killed_errno() const + { + return killed; + } + inline void send_kill_message() const + { + my_error(killed_errno(), MYF(0)); + } bool prepare_command; bool tmp_table_used; -- cgit v1.2.1 From b9121cdea38b75aabc5a29a769ee409c962f42e0 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 5 May 2003 14:54:37 -0400 Subject: made lex a pointer in THD --- sql/sql_class.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index 1a3cd66c7e4..3bb0f348024 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -404,7 +404,8 @@ public: struct st_mysql *mysql; #endif NET net; // client connection descriptor - LEX lex; // parse tree descriptor + LEX main_lex; + LEX *lex; // parse tree descriptor MEM_ROOT mem_root; // 1 command-life memory pool MEM_ROOT con_root; // connection-life memory MEM_ROOT warn_root; // For warnings and errors -- cgit v1.2.1 From 8070c06ae009e6dea64992419899d8a769458ddb Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 1 Jul 2003 18:14:24 +0200 Subject: SP cache (WL#730). (Mostly by vva, additions by pem.) sql/sp.cc: In-memory cache added. sp_clear_function_cache() no longer needed. sql/sp.h: In-memory cache added. sp_clear_function_cache() no longer needed. sql/sql_class.cc: In-memory cache added. sql/sql_class.h: In-memory cache added. sql/sql_parse.cc: In-memory cache added. sp_clear_function_cache() no longer needed. Don't delete sp_heads after each use. --- sql/sql_class.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index 3bb0f348024..cebcdf68391 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -551,7 +551,7 @@ public: bool prepare_command; bool tmp_table_used; sp_rcontext *spcont; // SP runtime context - List spfuns; // SP FUNCTIONs + HASH sp_hash[2]; // hash for SP PROCEDURES and FUNCTIONS /* If we do a purge of binary logs, log index info of the threads -- cgit v1.2.1 From f1c754efe9b78fb8497042ebdb1b2245df392381 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 3 Jul 2003 15:58:37 +0200 Subject: Code cleanup (and moved sp cache to separate file). --- sql/sql_class.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index cebcdf68391..e1aa22831cb 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -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 -- cgit v1.2.1 From 776784b8215044bc320af5b43a1cbd100d6b944b Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 14 Oct 2003 12:59:28 +0200 Subject: Fix for BUG#1495: Evaluate items before setting a local variable with SELECT INTO. Also copy and restore order_list and group_list for selects in SPs. mysql-test/r/sp.result: Test for BUG#1495, and an additional cursor test. mysql-test/t/sp.test: Test for BUG#1495, and an additional cursor test. sql/sp_head.cc: Fix BUG#1495: renamed eval_func_item() into sp_eval_func_item() and made it non-static. Also need to copy and restore order_list and group_list pointers before and after execution of a substatement. (Which means these must always be properly initialized for all queries.) sql/sp_rcontext.cc: Fix BUG#1495: Evaluate and set a local variable (for SELECT INTO). sql/sp_rcontext.h: Fix BUG#1495: Evaluate and set a local variable (for SELECT INTO). sql/sql_class.cc: Fix BUG#1495: Evaluate and set a local variable (for SELECT INTO). sql/sql_class.h: Fix BUG#1495: Evaluate and set a local variable (for SELECT INTO); need type for this. sql/sql_parse.cc: order_list and group_list must be initialized in select_lex for all queries, to make SP sub statement execution work. sql/sql_yacc.yy: Type needed for setting local variables. sql/table.h: Need a copy of the Item* pointer when executing sub-statements in SPs. (Since it's modified and must be restored afterwards.) --- sql/sql_class.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index 19bf451be22..f7c9fb58513 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1123,7 +1123,10 @@ public: LEX_STRING s; bool local; uint offset; - my_var (LEX_STRING& j, bool i, uint o) : s(j), local(i), offset(o) {} + enum_field_types type; + my_var (LEX_STRING& j, bool i, uint o, enum_field_types t) + :s(j), local(i), offset(o), type(t) + {} ~my_var() {} }; -- cgit v1.2.1