summaryrefslogtreecommitdiff
path: root/sql/sp_head.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sp_head.cc')
-rw-r--r--sql/sp_head.cc45
1 files changed, 37 insertions, 8 deletions
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 966aa675362..1084c3efc82 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -34,6 +34,36 @@
extern "C" uchar *sp_table_key(const uchar *ptr, size_t *plen, my_bool first);
+/**
+ Helper function which operates on a THD object to set the query start_time to
+ the current time.
+
+ @param[in, out] thd The session object
+
+*/
+
+static void reset_start_time_for_sp(THD *thd)
+{
+ /*
+ Do nothing if the context is a trigger or function because time should be
+ constant during the execution of those.
+ */
+ if (!thd->in_sub_stmt)
+ {
+ /*
+ First investigate if there is a cached time stamp
+ */
+ if (thd->user_time)
+ {
+ thd->start_time= thd->user_time;
+ }
+ else
+ {
+ my_micro_time_and_time(&thd->start_time);
+ }
+ }
+}
+
Item_result
sp_map_result_type(enum enum_field_types type)
{
@@ -1225,10 +1255,13 @@ sp_head::execute(THD *thd)
DBUG_PRINT("execute", ("Instruction %u", ip));
- /* Don't change NOW() in FUNCTION or TRIGGER */
- if (!thd->in_sub_stmt)
- thd->set_time(); // Make current_time() et al work
-
+ /*
+ We need to reset start_time to allow for time to flow inside a stored
+ procedure. This is only done for SP since time is suppose to be constant
+ during execution of triggers and functions.
+ */
+ reset_start_time_for_sp(thd);
+
/*
We have to set thd->stmt_arena before executing the instruction
to store in the instruction free_list all new items, created
@@ -1840,8 +1873,6 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
{
bool err_status= FALSE;
uint params = m_pcont->context_var_count();
- /* Query start time may be reset in a multi-stmt SP; keep this for later. */
- ulonglong utime_before_sp_exec= thd->utime_after_lock;
sp_rcontext *save_spcont, *octx;
sp_rcontext *nctx = NULL;
bool save_enable_slow_log;
@@ -2034,8 +2065,6 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
delete nctx;
thd->spcont= save_spcont;
- thd->utime_after_lock= utime_before_sp_exec;
-
DBUG_RETURN(err_status);
}