summaryrefslogtreecommitdiff
path: root/sql/sp_head.h
diff options
context:
space:
mode:
authorJon Olav Hauglid <jon.hauglid@oracle.com>2012-01-09 11:28:02 +0100
committerJon Olav Hauglid <jon.hauglid@oracle.com>2012-01-09 11:28:02 +0100
commitb8291e2b60b311b621b15aff1dfec817da1bbf4c (patch)
tree72ca1c71906da75727e51474b01b58c7a6f16892 /sql/sp_head.h
parent86505c3c545d3866a85464b0762b452d85599993 (diff)
downloadmariadb-git-b8291e2b60b311b621b15aff1dfec817da1bbf4c.tar.gz
Backport from mysql-trunk of:
------------------------------------------------------------ revno: 3258 committer: Jon Olav Hauglid <jon.hauglid@oracle.com> branch nick: mysql-trunk-bug12663165 timestamp: Thu 2011-07-14 10:05:12 +0200 message: Bug#12663165 SP DEAD CODE REMOVAL DOESN'T UNDERSTAND CONTINUE HANDLERS When stored routines are loaded, a simple optimizer tries to locate and remove dead code. The problem was that this dead code removal did not work correctly with CONTINUE handlers. If a statement triggers a CONTINUE handler, the following statement will be executed after the handler statement has completed. This means that the following statement is not dead code even if the previous statement unconditionally alters control flow. This fact was lost on the dead code removal routine, which ended up with removing instructions that could have been executed. This could then lead to assertions, crashes and generally bad behavior when the stored routine was executed. This patch fixes the problem by marking as live code all stored routine instructions that are in the same scope as a CONTINUE handler. Test case added to sp.test.
Diffstat (limited to 'sql/sp_head.h')
-rw-r--r--sql/sp_head.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/sql/sp_head.h b/sql/sp_head.h
index da490527f42..a026ac47221 100644
--- a/sql/sp_head.h
+++ b/sql/sp_head.h
@@ -1000,7 +1000,7 @@ class sp_instr_hpush_jump : public sp_instr_jump
public:
sp_instr_hpush_jump(uint ip, sp_pcontext *ctx, int htype, uint fp)
- : sp_instr_jump(ip, ctx), m_type(htype), m_frame(fp)
+ : sp_instr_jump(ip, ctx), m_type(htype), m_frame(fp), m_opt_hpop(0)
{
m_cond.empty();
}
@@ -1022,6 +1022,15 @@ public:
return m_ip;
}
+ virtual void backpatch(uint dest, sp_pcontext *dst_ctx)
+ {
+ DBUG_ASSERT(!m_dest || !m_opt_hpop);
+ if (!m_dest)
+ m_dest= dest;
+ else
+ m_opt_hpop= dest;
+ }
+
inline void add_condition(struct sp_cond_type *cond)
{
m_cond.push_front(cond);
@@ -1031,6 +1040,7 @@ private:
int m_type; ///< Handler type
uint m_frame;
+ uint m_opt_hpop; // hpop marking end of handler scope.
List<struct sp_cond_type> m_cond;
}; // class sp_instr_hpush_jump : public sp_instr_jump