summaryrefslogtreecommitdiff
path: root/sql/item_subselect.h
diff options
context:
space:
mode:
Diffstat (limited to 'sql/item_subselect.h')
-rw-r--r--sql/item_subselect.h135
1 files changed, 98 insertions, 37 deletions
diff --git a/sql/item_subselect.h b/sql/item_subselect.h
index 88ea01f9c68..92839eb0e5f 100644
--- a/sql/item_subselect.h
+++ b/sql/item_subselect.h
@@ -21,30 +21,24 @@
#endif
class st_select_lex;
+class st_select_lex_unit;
class JOIN;
class select_subselect;
+class subselect_engine;
/* base class for subselects */
class Item_subselect :public Item
{
+ my_bool engine_owner; /* Is this item owner of engine */
+ my_bool value_assigned; /* value already assigned to subselect */
protected:
+ /* engine that perform execution of subselect (single select or union) */
+ subselect_engine *engine;
+ /* allowed number of columns (1 for single value subqueries) */
uint max_columns;
- my_bool assigned; /* value already assigned to subselect */
- my_bool executed; /* simple subselect is executed */
- my_bool optimized; /* simple subselect is optimized */
- my_bool error; /* error in query */
- int exec();
- virtual void assign_null()
- {
- null_value= 1;
- }
public:
- st_select_lex *select_lex;
- JOIN *join;
- select_subselect *result;
-
Item_subselect(THD *thd, st_select_lex *select_lex,
select_subselect* result);
Item_subselect(Item_subselect *item)
@@ -52,18 +46,22 @@ public:
null_value= item->null_value;
decimals= item->decimals;
max_columns= item->max_columns;
- assigned= item->assigned;
- executed= item->executed;
- select_lex= item->select_lex;
- join= item->join;
- result= item->result;
+ engine= item->engine;
+ engine_owner= 0;
name= item->name;
- error= item->error;
}
+ ~Item_subselect();
+ virtual void assign_null()
+ {
+ null_value= 1;
+ }
+ bool assigned() { return value_assigned; }
+ void assigned(bool a) { value_assigned= a; }
enum Type type() const;
bool is_null() { return null_value; }
void make_field (Send_field *);
bool fix_fields(THD *thd, TABLE_LIST *tables, Item **ref);
+ virtual void fix_length_and_dec();
table_map used_tables() const;
friend class select_subselect;
@@ -75,18 +73,10 @@ public:
class Item_singleval_subselect :public Item_subselect
{
protected:
- longlong int_value;
- double real_value;
- enum Item_result res_type;
+ longlong int_value; /* here stored integer value of this item */
+ double real_value; /* here stored real value of this item */
+ enum Item_result res_type; /* type of results */
- virtual void assign_null()
- {
- null_value= 1;
- int_value= 0;
- real_value= 0;
- max_length= 4;
- res_type= STRING_RESULT;
- }
public:
Item_singleval_subselect(THD *thd, st_select_lex *select_lex);
Item_singleval_subselect(Item_singleval_subselect *item):
@@ -98,12 +88,20 @@ public:
decimals= item->decimals;
res_type= item->res_type;
}
+ virtual void assign_null()
+ {
+ null_value= 1;
+ int_value= 0;
+ real_value= 0;
+ max_length= 4;
+ res_type= STRING_RESULT;
+ }
double val ();
longlong val_int ();
String *val_str (String *);
Item *new_item() { return new Item_singleval_subselect(this); }
enum Item_result result_type() const { return res_type; }
-
+ void fix_length_and_dec();
friend class select_singleval_subselect;
};
@@ -112,12 +110,8 @@ public:
class Item_exists_subselect :public Item_subselect
{
protected:
- longlong value;
+ longlong value; /* value of this item (boolean: exists/not-exists) */
- virtual void assign_null()
- {
- value= 0;
- }
public:
Item_exists_subselect(THD *thd, st_select_lex *select_lex);
Item_exists_subselect(Item_exists_subselect *item):
@@ -125,11 +119,78 @@ public:
{
value= item->value;
}
+ virtual void assign_null()
+ {
+ value= 0;
+ }
+
Item *new_item() { return new Item_exists_subselect(this); }
enum Item_result result_type() const { return INT_RESULT;}
longlong val_int();
double val();
String *val_str(String*);
-
+ void fix_length_and_dec();
friend class select_exists_subselect;
};
+
+class subselect_engine
+{
+protected:
+ select_subselect *result; /* results storage class */
+ THD *thd; /* pointer to current THD */
+ Item_subselect *item; /* item, that use this engine */
+ enum Item_result res_type; /* type of results */
+public:
+ static void *operator new(size_t size)
+ {
+ return (void*) sql_alloc((uint) size);
+ }
+ static void operator delete(void *ptr, size_t size) {}
+
+ subselect_engine(THD *thd, Item_subselect *si, select_subselect *res)
+ {
+ result= res;
+ item= si;
+ this->thd= thd;
+ res_type= STRING_RESULT;
+ }
+
+ virtual int prepare()= 0;
+ virtual void fix_length_and_dec()= 0;
+ virtual int exec()= 0;
+ virtual uint cols()= 0; /* return number of columnss in select */
+ virtual bool depended()= 0; /* depended from outer select */
+ enum Item_result type() { return res_type; }
+};
+
+class subselect_single_select_engine: public subselect_engine
+{
+ my_bool executed; /* simple subselect is executed */
+ my_bool optimized; /* simple subselect is optimized */
+ st_select_lex *select_lex; /* corresponding select_lex */
+ JOIN * join; /* corresponding JOIN structure */
+public:
+ subselect_single_select_engine(THD *thd, st_select_lex *select,
+ select_subselect *result,
+ Item_subselect *item);
+ virtual int prepare();
+ virtual void fix_length_and_dec();
+ virtual int exec();
+ virtual uint cols();
+ virtual bool depended();
+};
+
+class subselect_union_engine: public subselect_engine
+{
+ st_select_lex_unit *unit; /* corresponding unit structure */
+public:
+ subselect_union_engine(THD *thd,
+ st_select_lex_unit *u,
+ select_subselect *result,
+ Item_subselect *item);
+ virtual int prepare();
+ virtual void fix_length_and_dec();
+ virtual int exec();
+ virtual uint cols();
+ virtual bool depended();
+};