summaryrefslogtreecommitdiff
path: root/sql/sp_head.h
diff options
context:
space:
mode:
authorunknown <pem@mysql.comhem.se>2004-08-02 18:05:31 +0200
committerunknown <pem@mysql.comhem.se>2004-08-02 18:05:31 +0200
commit81aad353c5338433db4ab3e208e1858018ae7982 (patch)
treec0c3ba42464ab9922b65d89d2d985f9b8ee830da /sql/sp_head.h
parent4467bcf26e0e5f9b205864b5f54f6234c62a2fe3 (diff)
downloadmariadb-git-81aad353c5338433db4ab3e208e1858018ae7982.tar.gz
WL#2001: Optimize stored procedure code.
Added a simple optimizer that shortcuts jumps and skip unused instructions. sql/sp.cc: Optimize the code after parsing. sql/sp_head.cc: Added a simple optimizer that shortcuts jumps and skip unused instructions. sql/sp_head.h: Added a simple optimizer that shortcuts jumps and skip unused instructions.
Diffstat (limited to 'sql/sp_head.h')
-rw-r--r--sql/sp_head.h102
1 files changed, 84 insertions, 18 deletions
diff --git a/sql/sp_head.h b/sql/sp_head.h
index fd6ecfd7320..165f83c58fd 100644
--- a/sql/sp_head.h
+++ b/sql/sp_head.h
@@ -201,6 +201,20 @@ public:
void restore_thd_mem_root(THD *thd);
+ void optimize();
+ void opt_mark(uint ip);
+
+ inline sp_instr *
+ get_instr(uint i)
+ {
+ sp_instr *ip;
+
+ if (i < m_instr.elements)
+ get_dynamic(&m_instr, (gptr)&ip, i);
+ else
+ ip= NULL;
+ return ip;
+ }
private:
@@ -218,18 +232,6 @@ private:
} bp_t;
List<bp_t> m_backpatch; // Instructions needing backpatching
- inline sp_instr *
- get_instr(uint i)
- {
- sp_instr *ip;
-
- if (i < m_instr.elements)
- get_dynamic(&m_instr, (gptr)&ip, i);
- else
- ip= NULL;
- return ip;
- }
-
int
execute(THD *thd);
@@ -247,11 +249,13 @@ class sp_instr : public Sql_alloc
public:
+ uint marked;
Item *free_list; // My Items
+ uint m_ip; // My index
// Should give each a name or type code for debugging purposes?
sp_instr(uint ip)
- :Sql_alloc(), free_list(0), m_ip(ip)
+ :Sql_alloc(), marked(0), free_list(0), m_ip(ip)
{}
virtual ~sp_instr()
@@ -265,9 +269,24 @@ public:
virtual void print(String *str) = 0;
-protected:
+ virtual void set_destination(uint dest)
+ {}
- uint m_ip; // My index
+ virtual uint opt_mark(sp_head *sp)
+ {
+ marked= 1;
+ return m_ip+1;
+ }
+
+ virtual uint opt_shortcut_jump(sp_head *sp)
+ {
+ return m_ip;
+ }
+
+ virtual void opt_move(uint dst, List<sp_instr> *ibp)
+ {
+ m_ip= dst;
+ }
}; // class sp_instr : public Sql_alloc
@@ -349,12 +368,14 @@ class sp_instr_jump : public sp_instr
public:
+ uint m_dest; // Where we will go
+
sp_instr_jump(uint ip)
- : sp_instr(ip), m_dest(0)
+ : sp_instr(ip), m_dest(0), m_optdest(0)
{}
sp_instr_jump(uint ip, uint dest)
- : sp_instr(ip), m_dest(dest)
+ : sp_instr(ip), m_dest(dest), m_optdest(0)
{}
virtual ~sp_instr_jump()
@@ -364,6 +385,12 @@ public:
virtual void print(String *str);
+ virtual uint opt_mark(sp_head *sp);
+
+ virtual uint opt_shortcut_jump(sp_head *sp);
+
+ virtual void opt_move(uint dst, List<sp_instr> *ibp);
+
virtual void
set_destination(uint dest)
{
@@ -373,7 +400,7 @@ public:
protected:
- int m_dest; // Where we will go
+ sp_instr *m_optdest; // Used during optimization
}; // class sp_instr_jump : public sp_instr
@@ -400,6 +427,13 @@ public:
virtual void print(String *str);
+ virtual uint opt_mark(sp_head *sp);
+
+ virtual uint opt_shortcut_jump(sp_head *sp)
+ {
+ return m_ip;
+ }
+
private:
Item *m_expr; // The condition
@@ -429,6 +463,13 @@ public:
virtual void print(String *str);
+ virtual uint opt_mark(sp_head *sp);
+
+ virtual uint opt_shortcut_jump(sp_head *sp)
+ {
+ return m_ip;
+ }
+
private:
Item *m_expr; // The condition
@@ -454,6 +495,12 @@ public:
virtual void print(String *str);
+ virtual uint opt_mark(sp_head *sp)
+ {
+ marked= 1;
+ return UINT_MAX;
+ }
+
protected:
Item *m_value;
@@ -485,6 +532,13 @@ public:
virtual void print(String *str);
+ virtual uint opt_mark(sp_head *sp);
+
+ virtual uint opt_shortcut_jump(sp_head *sp)
+ {
+ return m_ip;
+ }
+
inline void add_condition(struct sp_cond_type *cond)
{
m_cond.push_front(cond);
@@ -543,6 +597,12 @@ public:
virtual void print(String *str);
+ virtual uint opt_mark(sp_head *sp)
+ {
+ marked= 1;
+ return UINT_MAX;
+ }
+
private:
uint m_frame;
@@ -700,6 +760,12 @@ public:
virtual void print(String *str);
+ virtual uint opt_mark(sp_head *sp)
+ {
+ marked= 1;
+ return UINT_MAX;
+ }
+
private:
int m_errcode;