diff options
Diffstat (limited to 'sql/item_subselect.h')
-rw-r--r-- | sql/item_subselect.h | 105 |
1 files changed, 58 insertions, 47 deletions
diff --git a/sql/item_subselect.h b/sql/item_subselect.h index d323dab51f1..cf7f612224a 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -42,6 +42,8 @@ protected: subselect_engine *engine; /* allowed number of columns (1 for single value subqueries) */ uint max_columns; + /* work with 'substitution' */ + bool have_to_be_excluded; public: Item_subselect(); @@ -65,67 +67,62 @@ public: select_subselect *result); ~Item_subselect(); - virtual void assign_null() + virtual void reset() { null_value= 1; } - virtual void select_transformer(st_select_lex *select_lex); + virtual void select_transformer(THD *thd, st_select_lex_unit *unit); 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 is_null() + { + val_int(); + return null_value; + } bool fix_fields(THD *thd, TABLE_LIST *tables, Item **ref); virtual void fix_length_and_dec(); table_map used_tables() const; bool check_loop(uint id); friend class select_subselect; + friend class Item_in_optimizer; }; /* single value subselect */ -class Item_singleval_subselect :public Item_subselect +class Item_cache; +class Item_singlerow_subselect :public Item_subselect { protected: - longlong int_value; /* Here stored integer value of this item */ - double real_value; /* Here stored real value of this item */ - /* - Here stored string value of this item. - (str_value used only as temporary buffer, because it can be changed - by Item::save_field) - */ - String string_value; - enum Item_result res_type; /* type of results */ - + Item_cache *value, **row; public: - Item_singleval_subselect(THD *thd, st_select_lex *select_lex); - Item_singleval_subselect(Item_singleval_subselect *item): + Item_singlerow_subselect(THD *thd, st_select_lex *select_lex); + Item_singlerow_subselect(Item_singlerow_subselect *item): Item_subselect(item) { - int_value= item->int_value; - real_value= item->real_value; - string_value.set(item->string_value, 0, item->string_value.length()); + value= item->value; max_length= item->max_length; 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 (); + void reset(); + void select_transformer(THD *thd, st_select_lex_unit *unit); + void store(uint i, Item* item); + 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; } + Item *new_item() { return new Item_singlerow_subselect(this); } + enum Item_result result_type() const; void fix_length_and_dec(); - friend class select_singleval_subselect; + uint cols(); + Item* el(uint i) { return (Item*)row[i]; } + Item** addr(uint i) { return (Item**)row + i; } + bool check_cols(uint c); + bool null_inside(); + void bring_value(); + + friend class select_singlerow_subselect; }; /* exists subselect */ @@ -144,7 +141,7 @@ public: } Item_exists_subselect(): Item_subselect() {} - virtual void assign_null() + void reset() { value= 0; } @@ -155,6 +152,7 @@ public: double val(); String *val_str(String*); void fix_length_and_dec(); + friend class select_exists_subselect; }; @@ -164,14 +162,28 @@ class Item_in_subselect :public Item_exists_subselect { protected: Item * left_expr; - + bool was_null; public: Item_in_subselect(THD *thd, Item * left_expr, st_select_lex *select_lex); Item_in_subselect(Item_in_subselect *item); Item_in_subselect(): Item_exists_subselect() {} - virtual void select_transformer(st_select_lex *select_lex); - void single_value_transformer(st_select_lex *select_lex, + void reset() + { + value= 0; + null_value= 0; + was_null= 0; + } + virtual void select_transformer(THD *thd, st_select_lex_unit *unit); + void single_value_transformer(THD *thd, st_select_lex_unit *unit, Item *left_expr, compare_func_creator func); + void row_value_transformer(THD *thd, st_select_lex_unit *unit, + Item *left_expr); + longlong val_int(); + double val(); + String *val_str(String*); + + friend class Item_asterisk_remover; + friend class Item_ref_null_helper; }; /* ALL/ANY/SOME subselect */ @@ -184,22 +196,18 @@ public: Item_allany_subselect(THD *thd, Item * left_expr, compare_func_creator f, st_select_lex *select_lex); Item_allany_subselect(Item_allany_subselect *item); - virtual void select_transformer(st_select_lex *select_lex); + virtual void select_transformer(THD *thd, st_select_lex_unit *unit); }; -class subselect_engine +class subselect_engine: public Sql_alloc { 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 */ + bool maybe_null; /* may be null (first item in select) */ 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) { @@ -207,16 +215,19 @@ public: item= si; this->thd= thd; res_type= STRING_RESULT; + maybe_null= 0; } + virtual ~subselect_engine() {}; // to satisfy compiler virtual int prepare()= 0; - virtual void fix_length_and_dec()= 0; + virtual void fix_length_and_dec(Item_cache** row)= 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; } virtual bool check_loop(uint id)= 0; virtual void exclude()= 0; + bool may_be_null() { return maybe_null; }; }; class subselect_single_select_engine: public subselect_engine @@ -231,7 +242,7 @@ public: select_subselect *result, Item_subselect *item); int prepare(); - void fix_length_and_dec(); + void fix_length_and_dec(Item_cache** row); int exec(); uint cols(); bool depended(); @@ -248,7 +259,7 @@ public: select_subselect *result, Item_subselect *item); int prepare(); - void fix_length_and_dec(); + void fix_length_and_dec(Item_cache** row); int exec(); uint cols(); bool depended(); |