summaryrefslogtreecommitdiff
path: root/sql/sp.cc
diff options
context:
space:
mode:
authorunknown <sergefp@mysql.com>2005-08-03 03:47:07 +0000
committerunknown <sergefp@mysql.com>2005-08-03 03:47:07 +0000
commite442059c0dbfeadaabf7e12e905fec0b94c153a6 (patch)
tree551d1a44fe7c14ba73b87378e84fb04d7228ab30 /sql/sp.cc
parent88105618c5eba3714189875a8d799cb7503bd657 (diff)
parentb323667ffc7176482073ca7d626560dcd8d7ee75 (diff)
downloadmariadb-git-e442059c0dbfeadaabf7e12e905fec0b94c153a6.tar.gz
Manual merge
mysql-test/r/sp.result: Auto merged mysql-test/r/view.result: Auto merged mysql-test/t/view.test: Auto merged sql/item_func.cc: Auto merged sql/sp.cc: Auto merged sql/sp_head.cc: Auto merged sql/sp_head.h: Auto merged sql/sql_base.cc: Auto merged sql/sql_class.cc: Auto merged sql/sql_class.h: Auto merged sql/sql_lex.cc: Auto merged sql/sql_parse.cc: Auto merged sql/sql_trigger.h: Auto merged
Diffstat (limited to 'sql/sp.cc')
-rw-r--r--sql/sp.cc83
1 files changed, 65 insertions, 18 deletions
diff --git a/sql/sp.cc b/sql/sp.cc
index dec0eee0095..6c0785b4130 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -1176,6 +1176,43 @@ extern "C" byte* sp_sroutine_key(const byte *ptr, uint *plen, my_bool first)
/*
+ Check if
+ - current statement (the one in thd->lex) needs table prelocking
+ - first routine in thd->lex->sroutines_list needs to execute its body in
+ prelocked mode.
+
+ SYNOPSIS
+ sp_get_prelocking_info()
+ thd Current thread, thd->lex is the statement to be
+ checked.
+ need_prelocking OUT TRUE - prelocked mode should be activated
+ before executing the statement
+ FALSE - Don't activate prelocking
+ first_no_prelocking OUT TRUE - Tables used by first routine in
+ thd->lex->sroutines_list should be
+ prelocked.
+ FALSE - Otherwise.
+ NOTES
+ This function assumes that for any "CALL proc(...)" statement routines_list
+ will have 'proc' as first element (it may have several, consider e.g.
+ "proc(sp_func(...)))". This property is currently guaranted by the parser.
+*/
+
+void sp_get_prelocking_info(THD *thd, bool *need_prelocking,
+ bool *first_no_prelocking)
+{
+ Sroutine_hash_entry *routine;
+ routine= (Sroutine_hash_entry*)thd->lex->sroutines_list.first;
+
+ DBUG_ASSERT(routine);
+ bool first_is_procedure= (routine->key.str[0] == TYPE_ENUM_PROCEDURE);
+
+ *first_no_prelocking= first_is_procedure;
+ *need_prelocking= !first_is_procedure || test(routine->next);
+}
+
+
+/*
Auxilary function that adds new element to the set of stored routines
used by statement.
@@ -1312,11 +1349,13 @@ static void sp_update_stmt_used_routines(THD *thd, LEX *lex, HASH *src)
SYNOPSIS
sp_cache_routines_and_add_tables_aux()
- thd - thread context
- lex - LEX representing statement
- start - first routine from the list of routines to be cached
- (this list defines mentioned sub-set).
-
+ thd - thread context
+ lex - LEX representing statement
+ start - first routine from the list of routines to be cached
+ (this list defines mentioned sub-set).
+ first_no_prelock - If true, don't add tables or cache routines used by
+ the body of the first routine (i.e. *start)
+ will be executed in non-prelocked mode.
NOTE
If some function is missing this won't be reported here.
Instead this fact will be discovered during query execution.
@@ -1328,10 +1367,11 @@ static void sp_update_stmt_used_routines(THD *thd, LEX *lex, HASH *src)
static bool
sp_cache_routines_and_add_tables_aux(THD *thd, LEX *lex,
- Sroutine_hash_entry *start)
+ Sroutine_hash_entry *start,
+ bool first_no_prelock)
{
bool result= FALSE;
-
+ bool first= TRUE;
DBUG_ENTER("sp_cache_routines_and_add_tables_aux");
for (Sroutine_hash_entry *rt= start; rt; rt= rt->next)
@@ -1367,9 +1407,13 @@ sp_cache_routines_and_add_tables_aux(THD *thd, LEX *lex,
}
if (sp)
{
- sp_update_stmt_used_routines(thd, lex, &sp->m_sroutines);
- result|= sp->add_used_tables_to_table_list(thd, &lex->query_tables_last);
+ if (!(first && first_no_prelock))
+ {
+ sp_update_stmt_used_routines(thd, lex, &sp->m_sroutines);
+ result|= sp->add_used_tables_to_table_list(thd, &lex->query_tables_last);
+ }
}
+ first= FALSE;
}
DBUG_RETURN(result);
}
@@ -1382,20 +1426,22 @@ sp_cache_routines_and_add_tables_aux(THD *thd, LEX *lex,
SYNOPSIS
sp_cache_routines_and_add_tables()
- thd - thread context
- lex - LEX representing statement
-
+ thd - thread context
+ lex - LEX representing statement
+ first_no_prelock - If true, don't add tables or cache routines used by
+ the body of the first routine (i.e. *start)
+
RETURN VALUE
TRUE - some tables were added
FALSE - no tables were added.
*/
bool
-sp_cache_routines_and_add_tables(THD *thd, LEX *lex)
+sp_cache_routines_and_add_tables(THD *thd, LEX *lex, bool first_no_prelock)
{
-
return sp_cache_routines_and_add_tables_aux(thd, lex,
- (Sroutine_hash_entry *)lex->sroutines_list.first);
+ (Sroutine_hash_entry *)lex->sroutines_list.first,
+ first_no_prelock);
}
@@ -1417,8 +1463,8 @@ sp_cache_routines_and_add_tables_for_view(THD *thd, LEX *lex, LEX *aux_lex)
Sroutine_hash_entry **last_cached_routine_ptr=
(Sroutine_hash_entry **)lex->sroutines_list.next;
sp_update_stmt_used_routines(thd, lex, &aux_lex->sroutines);
- (void)sp_cache_routines_and_add_tables_aux(thd, lex,
- *last_cached_routine_ptr);
+ (void)sp_cache_routines_and_add_tables_aux(thd, lex,
+ *last_cached_routine_ptr, FALSE);
}
@@ -1456,7 +1502,8 @@ sp_cache_routines_and_add_tables_for_triggers(THD *thd, LEX *lex,
}
}
(void)sp_cache_routines_and_add_tables_aux(thd, lex,
- *last_cached_routine_ptr);
+ *last_cached_routine_ptr,
+ FALSE);
}
}