diff options
author | unknown <dlenev@mysql.com> | 2005-07-09 21:51:59 +0400 |
---|---|---|
committer | unknown <dlenev@mysql.com> | 2005-07-09 21:51:59 +0400 |
commit | 14b1f91ba4aa9a4d950450b513d167b221ce6f6d (patch) | |
tree | 0499c7d8dab27b531e4671a4999a2c0dffeae0c5 /sql/sp_head.h | |
parent | d27132953d608aed019e48ee180821fc87b47556 (diff) | |
download | mariadb-git-14b1f91ba4aa9a4d950450b513d167b221ce6f6d.tar.gz |
Enable support of access to tables from triggers. Thus fix bug #8406 "Triggers
crash if referencing a table" and several other related bugs.
Fix for bug #11834 "Re-execution of prepared statement with dropped function
crashes server." which was spotted during work on previous bugs.
Also couple of nice cleanups:
- Replaced two separate hashes for stored routines used by statement with one.
- Now instead of doing one pass through all routines used in statement for
caching them and then doing another pass for adding their tables to table
list, we do only one pass during which do both things.
mysql-test/r/sp-error.result:
Added test for bug #11834 "Re-execution of prepared statement with dropped
function crashes server" also covering handling of prepared statements
which use stored functions but does not require prelocking.
mysql-test/r/sp.result:
Updated test for LOCK TABLES with views in table list.
(Old version of statement used in this test will work ok now, since prelocking
algorithm was tuned and will lock only one multi-set of tables for each routine
even if this routine is used in several different views).
mysql-test/r/trigger.result:
Added several tests for triggers using tables.
mysql-test/t/sp-error.test:
Added test for bug #11834 "Re-execution of prepared statement with dropped
function crashes server" also covering handling of prepared statements
which use stored functions but does not require prelocking.
mysql-test/t/sp.test:
Updated comment about recursive views to reflect current situation.
Updated test for LOCK TABLES with views in table list.
(Old version of statement used in this test will work ok now, since prelocking
algorithm was tuned and will lock only one multi-set of tables for each routine
even if this routine is used in several different views).
mysql-test/t/trigger.test:
Added several tests for triggers using tables.
sql/item_func.cc:
Item_func_sp::cleanup():
By next statement execution stored function can be dropped or altered so
we can't assume that sp_head object for it will be still valid.
sql/sp.cc:
- Added Sroutine_hash_entry structure that represents element in the set of
stored routines used by statement or routine. We can't as before use
LEX_STRING for this purprose because we want link all elements of this set
in list.
- Replaced sp_add_to_hash() with sp_add_used_routine() which takes into account
that now we use one hash for stored routines used by statement instead of two
and which mantains list linking all elelemnts in this hash.
- Renamed sp_merge_hash() to sp_update_sp_used_routines().
- Introduced sp_update_stmt_used_routines() for adding elements to the set of
routines used by statement from another similar set for statement or routine.
This function will also mantain list linking elements of destination set.
- Now instead of one sp_cache_routines() function we have family of
sp_cache_routines_and_add_tables() functions which are also responsible for
adding tables used by routines being cached to statement table list. Nice
optimization - thanks to list linking all elements in the hash of routines
used by statement we don't need to perform several iterations over this hash
(as it was before in cases when we have added new elements to it).
sql/sp.h:
Added declarations of functions used for manipulations with set (hash) of stored
routines used by statement.
sql/sp_head.cc:
sp_name::init_qname():
Now sp_name also holds key identifying routine in the set (hash) of
stored routines used by statement.
sp_head:
Instead of two separate hashes sp_funs/m_spprocs representing sets of stored
routines used by this routine we use one hash - m_sroutines.
sp_instr_set_trigger_field:
Added support for subqueries in assignments to row accessors in triggers.
Removed definition of sp_add_sp_tables_to_table_list() and auxilary functions
since now we don't have separate stage on which we add tables used by routines
used by statement to table list for prelocking. We do it on the same stage as
we load those routines in SP cache. So all this functionality moved to
sp_cache_routines_and_add_tables() family of functions.
sql/sp_head.h:
sp_name:
Now this class also holds key identifying routine in the set (hash) of stored
routines used by statement.
sp_head:
Instead of two separate hashes sp_funs/m_spprocs representing sets of stored
routines used by this routine we use one hash - m_sroutines.
sp_instr_set_trigger_field:
Added support for subqueries in assignments to row accessors in triggers.
Removed declaration of sp_add_sp_tables_to_table_list() since now we don't have
separate stage on which we add tables used by routines used by statement to
table list for prelocking. We do it on the same stage as we load those routines
in SP cache.
sql/sql_base.cc:
open_tables():
- LEX::spfuns/spprocs hashes were replaced with one LEX::sroutines hash.
- Now instead of doing one pass through all routines used in statement for
caching them and then doing another pass for adding their tables to table
list, we do only one pass during which do both things. It is easy to do
since all routines in the set of routines used by statement are linked in
the list. This also allows us to calculate table list for prelocking more
precisely.
- Now triggers properly inform prelocking algorithm about tables they use.
sql/sql_lex.cc:
lex_start():
Replaced LEX::spfuns/spprocs with with one LEX::sroutines hash.
Added LEX::sroutines_list list linking all elements in this hash.
st_lex::st_lex():
Moved definition of LEX constructor to sql_lex.cc file to be able
use sp_sroutine_key declaration from sp.h in it.
sql/sql_lex.h:
LEX:
Replaced two separate hashes for stored routines used by statement with one.
Added list linking all elements in this hash to be able to iterate through all
elements and add new elements to this hash at the same time.
Moved constructor definition to sql_lex.cc.
sql/sql_parse.cc:
mysql_execute_command():
Replaced LEX::spfuns/spprocs with one LEX::sroutines hash.
sql/sql_trigger.cc:
Added missing GNU GPL notice.
Table_triggers_list::check_n_load()
Added initialization of sroutines_key which stores key representing
triggers of this table in the set (hash) of routines used by this statement.
sql/sql_trigger.h:
Added missing GNU GPL notice.
Table_triggers_list:
Added sroutines_key member to store key representing triggers of this
table in the set (hash) of routines used by this statement.
Declared sp_cache_routines_and_add_tables_for_triggers() as friend since
it needs access to sroutines_key and trigger bodies.
sql/sql_yacc.yy:
- Now we use sp_add_used_routine() instead of sp_add_to_hash() for adding
elements to the set of stored routines used in statement.
- Enabled support of subqueries as right sides in assignments to triggers' row
accessors.
Diffstat (limited to 'sql/sp_head.h')
-rw-r--r-- | sql/sp_head.h | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/sql/sp_head.h b/sql/sp_head.h index 617d6622037..28048285fb3 100644 --- a/sql/sp_head.h +++ b/sql/sp_head.h @@ -48,24 +48,50 @@ public: LEX_STRING m_db; LEX_STRING m_name; LEX_STRING m_qname; + /* + Key representing routine in the set of stored routines used by statement. + Consists of 1-byte routine type and m_qname (which usually refences to + same buffer). Note that one must complete initialization of the key by + calling set_routine_type(). + */ + LEX_STRING m_sroutines_key; sp_name(LEX_STRING name) : m_name(name) { - m_db.str= m_qname.str= 0; - m_db.length= m_qname.length= 0; + m_db.str= m_qname.str= m_sroutines_key.str= 0; + m_db.length= m_qname.length= m_sroutines_key.length= 0; } sp_name(LEX_STRING db, LEX_STRING name) : m_db(db), m_name(name) { - m_qname.str= 0; - m_qname.length= 0; + m_qname.str= m_sroutines_key.str= 0; + m_qname.length= m_sroutines_key.length= 0; + } + + /* + Creates temporary sp_name object from key, used mainly + for SP-cache lookups. + */ + sp_name(char *key, uint key_len) + { + m_sroutines_key.str= key; + m_sroutines_key.length= key_len; + m_name.str= m_qname.str= key + 1; + m_name.length= m_qname.length= key_len - 1; + m_db.str= 0; + m_db.length= 0; } // Init. the qualified name from the db and name. void init_qname(THD *thd); // thd for memroot allocation + void set_routine_type(char type) + { + m_sroutines_key.str[0]= type; + } + ~sp_name() {} }; @@ -106,13 +132,13 @@ public: longlong m_created; longlong m_modified; /* - Sets containing names of SP and SF used by this routine. - - TODO Probably we should combine these two hashes in one. It will - decrease memory overhead ans simplify algorithms using them. The - same applies to similar hashes in LEX. + Set containing names of stored routines used by this routine. + Note that unlike elements of similar set for statement elements of this + set are not linked in one list. Because of this we are able save memory + by using for this set same objects that are used in 'sroutines' sets + for statements of which this stored routine consists. */ - HASH m_spfuns, m_spprocs; + HASH m_sroutines; // Pointers set during parsing uchar *m_param_begin, *m_param_end, *m_body_begin; @@ -471,10 +497,11 @@ class sp_instr_set_trigger_field : public sp_instr public: sp_instr_set_trigger_field(uint ip, sp_pcontext *ctx, - Item_trigger_field *trg_fld, Item *val) + Item_trigger_field *trg_fld, + Item *val, LEX *lex) : sp_instr(ip, ctx), trigger_field(trg_fld), - value(val) + value(val), m_lex_keeper(lex, TRUE) {} virtual ~sp_instr_set_trigger_field() @@ -482,11 +509,14 @@ public: virtual int execute(THD *thd, uint *nextp); + virtual int exec_core(THD *thd, uint *nextp); + virtual void print(String *str); private: Item_trigger_field *trigger_field; Item *value; + sp_lex_keeper m_lex_keeper; }; // class sp_instr_trigger_field : public sp_instr @@ -951,7 +981,5 @@ TABLE_LIST * sp_add_to_query_tables(THD *thd, LEX *lex, const char *db, const char *name, thr_lock_type locktype); -bool -sp_add_sp_tables_to_table_list(THD *thd, LEX *lex, LEX *func_lex); #endif /* _SP_HEAD_H_ */ |