summaryrefslogtreecommitdiff
path: root/sql/sp_head.cc
diff options
context:
space:
mode:
authorunknown <konstantin@mysql.com>2006-06-22 19:29:48 +0400
committerunknown <konstantin@mysql.com>2006-06-22 19:29:48 +0400
commit67fd3c4a53f585f8e33b5094822cf639a27483de (patch)
tree47e8b88fc7e1c24d26790e8ccdfc025e2c90eece /sql/sp_head.cc
parente9452db1c1b7fb534a44590312d6608640675350 (diff)
downloadmariadb-git-67fd3c4a53f585f8e33b5094822cf639a27483de.tar.gz
A fix and a test case for Bug#15217 "Using a SP cursor on a table created
with PREPARE fails with weird error". More generally, re-executing a stored procedure with a complex SP cursor query could lead to a crash. The cause of the problem was that SP cursor queries were not optimized properly at first execution: their parse tree belongs to sp_instr_cpush, not sp_instr_copen, and thus the tree was tagged "EXECUTED" when the cursor was declared, not when it was opened. This led to loss of optimization transformations performed at first execution, as sp_instr_copen saw that the query is already "EXECUTED" and therefore either not ran first-execution related blocks or wrongly rolled back the transformations caused by first-execution code. The fix is to update the state of the parsed tree only when the tree is executed, as opposed to when the instruction containing the tree is executed. Assignment if i->state is moved to reset_lex_and_exec_core. mysql-test/r/sp.result: Test results fixed (Bug#15217) mysql-test/t/sp.test: Add a test case for Bug#15217 sql/sp_head.cc: Move assignment of stmt_arena->state to reset_lex_and_exec_core
Diffstat (limited to 'sql/sp_head.cc')
-rw-r--r--sql/sp_head.cc4
1 files changed, 3 insertions, 1 deletions
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 3b29a841966..ef2f895c8b2 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -1075,7 +1075,6 @@ sp_head::execute(THD *thd)
thd->net.no_send_error= 0;
if (i->free_list)
cleanup_items(i->free_list);
- i->state= Query_arena::EXECUTED;
/*
If we've set thd->user_var_events_alloc to mem_root of this SP
@@ -2210,6 +2209,9 @@ sp_lex_keeper::reset_lex_and_exec_core(THD *thd, uint *nextp,
m_lex->mark_as_requiring_prelocking(NULL);
}
thd->rollback_item_tree_changes();
+ /* Update the state of the active arena. */
+ thd->stmt_arena->state= Query_arena::EXECUTED;
+
/*
Unlike for PS we should not call Item's destructors for newly created