diff options
author | bell@laptop.sanja.is.com.ua <> | 2003-10-07 08:51:09 +0300 |
---|---|---|
committer | bell@laptop.sanja.is.com.ua <> | 2003-10-07 08:51:09 +0300 |
commit | d5a7a6ec34f3d3d54f834cb9a590221d4e17a766 (patch) | |
tree | fda067894ad896fec9598b066ee7574213f50c64 | |
parent | 5b13ec47dd607612c5483f17935f1f98aa60c165 (diff) | |
parent | 9db4024b8d13138932474c390992d5a7e116f3d4 (diff) | |
download | mariadb-git-d5a7a6ec34f3d3d54f834cb9a590221d4e17a766.tar.gz |
merge
-rw-r--r-- | sql/item_subselect.cc | 58 | ||||
-rw-r--r-- | sql/item_subselect.h | 33 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 24 |
3 files changed, 59 insertions, 56 deletions
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index abe89eb6a76..6c21ba525c7 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -46,7 +46,7 @@ Item_subselect::Item_subselect(): null_value= 1; } -void Item_subselect::init(THD *thd, st_select_lex *select_lex, +void Item_subselect::init(st_select_lex *select_lex, select_subselect *result) { @@ -54,11 +54,10 @@ void Item_subselect::init(THD *thd, st_select_lex *select_lex, DBUG_PRINT("subs", ("select_lex 0x%xl", (ulong) select_lex)); if (select_lex->next_select()) - engine= new subselect_union_engine(thd, select_lex->master_unit(), result, + engine= new subselect_union_engine(select_lex->master_unit(), result, this); else - engine= new subselect_single_select_engine(thd, select_lex, result, - this); + engine= new subselect_single_select_engine(select_lex, result, this); DBUG_VOID_RETURN; } @@ -78,7 +77,7 @@ Item_subselect::select_transformer(JOIN *join) bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref) { - thd= thd_param; + engine->set_thd((thd= thd_param)); char const *save_where= thd->where; int res= engine->prepare(); @@ -151,12 +150,11 @@ inline table_map Item_subselect::used_tables() const (engine->uncacheable() ? RAND_TABLE_BIT : 0L)); } -Item_singlerow_subselect::Item_singlerow_subselect(THD *thd, - st_select_lex *select_lex) +Item_singlerow_subselect::Item_singlerow_subselect(st_select_lex *select_lex) :Item_subselect(), value(0) { DBUG_ENTER("Item_singlerow_subselect::Item_singlerow_subselect"); - init(thd, select_lex, new select_singlerow_subselect(this)); + init(select_lex, new select_singlerow_subselect(this)); max_columns= 1; maybe_null= 1; max_columns= UINT_MAX; @@ -338,12 +336,11 @@ String *Item_singlerow_subselect::val_str (String *str) } } -Item_exists_subselect::Item_exists_subselect(THD *thd, - st_select_lex *select_lex): +Item_exists_subselect::Item_exists_subselect(st_select_lex *select_lex): Item_subselect() { DBUG_ENTER("Item_exists_subselect::Item_exists_subselect"); - init(thd, select_lex, new select_exists_subselect(this)); + init(select_lex, new select_exists_subselect(this)); max_columns= UINT_MAX; null_value= 0; //can't be NULL maybe_null= 0; //can't be NULL @@ -368,13 +365,13 @@ bool Item_in_subselect::test_limit(SELECT_LEX_UNIT *unit) return(0); } -Item_in_subselect::Item_in_subselect(THD *thd, Item * left_exp, +Item_in_subselect::Item_in_subselect(Item * left_exp, st_select_lex *select_lex): Item_exists_subselect(), upper_not(0) { DBUG_ENTER("Item_in_subselect::Item_in_subselect"); left_expr= left_exp; - init(thd, select_lex, new select_exists_subselect(this)); + init(select_lex, new select_exists_subselect(this)); max_columns= UINT_MAX; maybe_null= 1; abort_on_null= 0; @@ -384,7 +381,7 @@ Item_in_subselect::Item_in_subselect(THD *thd, Item * left_exp, DBUG_VOID_RETURN; } -Item_allany_subselect::Item_allany_subselect(THD *thd, Item * left_exp, +Item_allany_subselect::Item_allany_subselect(Item * left_exp, compare_func_creator fn, st_select_lex *select_lex) :Item_in_subselect() @@ -392,7 +389,7 @@ Item_allany_subselect::Item_allany_subselect(THD *thd, Item * left_exp, DBUG_ENTER("Item_in_subselect::Item_in_subselect"); left_expr= left_exp; func= fn; - init(thd, select_lex, new select_exists_subselect(this)); + init(select_lex, new select_exists_subselect(this)); max_columns= 1; abort_on_null= 0; reset(); @@ -783,12 +780,11 @@ Item_allany_subselect::select_transformer(JOIN *join) } subselect_single_select_engine:: - subselect_single_select_engine(THD *thd, - st_select_lex *select, - select_subselect *result, - Item_subselect *item): - subselect_engine(thd, item, result), - prepared(0), optimized(0), executed(0) +subselect_single_select_engine(st_select_lex *select, + select_subselect *result, + Item_subselect *item) + :subselect_engine(item, result), + prepared(0), optimized(0), executed(0), join(0) { select_lex= select; SELECT_LEX_UNIT *unit= select_lex->master_unit(); @@ -799,24 +795,19 @@ subselect_single_select_engine:: unit->select_limit_cnt= HA_POS_ERROR; // no limit if (unit->select_limit_cnt == HA_POS_ERROR) select_lex->options&= ~OPTION_FOUND_ROWS; - join= new JOIN(thd, select_lex->item_list, select_lex->options, result); - if (!join || !result) - //out of memory - thd->fatal_error(); unit->item= item; this->select_lex= select_lex; } -subselect_union_engine::subselect_union_engine(THD *thd, - st_select_lex_unit *u, +subselect_union_engine::subselect_union_engine(st_select_lex_unit *u, select_subselect *result, - Item_subselect *item): - subselect_engine(thd, item, result) + Item_subselect *item) + :subselect_engine(item, result) { unit= u; if (!result) //out of memory - thd->fatal_error(); + current_thd->fatal_error(); unit->item= item; } @@ -824,6 +815,13 @@ int subselect_single_select_engine::prepare() { if (prepared) return 0; + join= new JOIN(thd, select_lex->item_list, select_lex->options, result); + if (!join || !result) + { + //out of memory + thd->fatal_error(); + return 1; + } prepared= 1; SELECT_LEX *save_select= thd->lex.current_select; thd->lex.current_select= select_lex; diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 1b5b9e9bd38..ecfd90a9a55 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -75,7 +75,7 @@ public: pointer in constructor initialization list, but we need pass pointer to subselect Item class to select_subselect classes constructor. */ - virtual void init (THD *thd, st_select_lex *select_lex, + virtual void init (st_select_lex *select_lex, select_subselect *result); ~Item_subselect(); @@ -122,7 +122,7 @@ class Item_singlerow_subselect :public Item_subselect protected: Item_cache *value, **row; public: - Item_singlerow_subselect(THD *thd, st_select_lex *select_lex); + Item_singlerow_subselect(st_select_lex *select_lex); Item_singlerow_subselect(Item_singlerow_subselect *item): Item_subselect(item) { @@ -171,7 +171,7 @@ protected: longlong value; /* value of this item (boolean: exists/not-exists) */ public: - Item_exists_subselect(THD *thd, st_select_lex *select_lex); + Item_exists_subselect(st_select_lex *select_lex); Item_exists_subselect(Item_exists_subselect *item): Item_subselect(item) { @@ -214,7 +214,7 @@ protected: public: Item_func_not_all *upper_not; // point on NOT before ALL subquery - Item_in_subselect(THD *thd, Item * left_expr, st_select_lex *select_lex); + Item_in_subselect(Item * left_expr, st_select_lex *select_lex); Item_in_subselect(Item_in_subselect *item); Item_in_subselect() :Item_exists_subselect(), abort_on_null(0), upper_not(0) {} @@ -250,7 +250,7 @@ protected: compare_func_creator func; public: - Item_allany_subselect(THD *thd, Item * left_expr, compare_func_creator f, + Item_allany_subselect(Item * left_expr, compare_func_creator f, st_select_lex *select_lex); Item_allany_subselect(Item_allany_subselect *item); // only ALL subquery has upper not @@ -268,16 +268,19 @@ protected: bool maybe_null; /* may be null (first item in select) */ public: - subselect_engine(THD *thd, Item_subselect *si, select_subselect *res) + subselect_engine(Item_subselect *si, select_subselect *res) + :thd(0) { result= res; item= si; - this->thd= thd; res_type= STRING_RESULT; maybe_null= 0; } virtual ~subselect_engine() {}; // to satisfy compiler - + + // set_thd should be called before prepare() + void set_thd(THD *thd) { this->thd= thd; } + THD * get_thd() { return thd; } virtual int prepare()= 0; virtual void fix_length_and_dec(Item_cache** row)= 0; virtual int exec()= 0; @@ -297,7 +300,7 @@ class subselect_single_select_engine: public subselect_engine st_select_lex *select_lex; /* corresponding select_lex */ JOIN * join; /* corresponding JOIN structure */ public: - subselect_single_select_engine(THD *thd, st_select_lex *select, + subselect_single_select_engine(st_select_lex *select, select_subselect *result, Item_subselect *item); int prepare(); @@ -313,8 +316,7 @@ 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, + subselect_union_engine(st_select_lex_unit *u, select_subselect *result, Item_subselect *item); int prepare(); @@ -334,10 +336,13 @@ protected: Item *cond; public: + // constructor can assign THD because it will be called after JOIN::prepare subselect_uniquesubquery_engine(THD *thd, st_join_table *tab_arg, Item_subselect *subs, Item *where) - :subselect_engine(thd, subs, 0), tab(tab_arg), cond(where) - {} + :subselect_engine(subs, 0), tab(tab_arg), cond(where) + { + set_thd(thd); + } int prepare(); void fix_length_and_dec(Item_cache** row); @@ -353,6 +358,8 @@ class subselect_indexsubquery_engine: public subselect_uniquesubquery_engine { bool check_null; public: + + // constructor can assign THD because it will be called after JOIN::prepare subselect_indexsubquery_engine(THD *thd, st_join_table *tab_arg, Item_subselect *subs, Item *where, bool chk_null) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 5e45a2c4fbb..81a59196e3c 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -2238,10 +2238,10 @@ expr_expr: | expr NOT IN_SYM '(' expr_list ')' { $5->push_front($1); $$= new Item_func_not(new Item_func_in(*$5)); } | expr IN_SYM in_subselect - { $$= new Item_in_subselect(YYTHD, $1, $3); } + { $$= new Item_in_subselect($1, $3); } | expr NOT IN_SYM in_subselect { - $$= new Item_func_not(new Item_in_subselect(YYTHD, $1, $4)); + $$= new Item_func_not(new Item_in_subselect($1, $4)); } | expr BETWEEN_SYM no_and_expr AND expr { $$= new Item_func_between($1,$3,$5); } @@ -2263,7 +2263,7 @@ expr_expr: | expr comp_op all_or_any in_subselect %prec EQ { Item_allany_subselect *it= - new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4); + new Item_allany_subselect($1, (*$2)($3), $4); if ($3) $$ = it->upper_not= new Item_func_not_all(it); /* ALL */ else @@ -2309,7 +2309,7 @@ no_in_expr: | no_in_expr comp_op all_or_any in_subselect %prec EQ { Item_allany_subselect *it= - new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4); + new Item_allany_subselect($1, (*$2)($3), $4); if ($3) $$ = it->upper_not= new Item_func_not_all(it); /* ALL */ else @@ -2340,10 +2340,10 @@ no_and_expr: | no_and_expr NOT IN_SYM '(' expr_list ')' { $5->push_front($1); $$= new Item_func_not(new Item_func_in(*$5)); } | no_and_expr IN_SYM in_subselect - { $$= new Item_in_subselect(YYTHD, $1, $3); } + { $$= new Item_in_subselect($1, $3); } | no_and_expr NOT IN_SYM in_subselect { - $$= new Item_func_not(new Item_in_subselect(YYTHD, $1, $4)); + $$= new Item_func_not(new Item_in_subselect($1, $4)); } | no_and_expr BETWEEN_SYM no_and_expr AND expr { $$= new Item_func_between($1,$3,$5); } @@ -2364,7 +2364,7 @@ no_and_expr: | no_and_expr comp_op all_or_any in_subselect %prec EQ { Item_allany_subselect *it= - new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4); + new Item_allany_subselect($1, (*$2)($3), $4); if ($3) $$ = it->upper_not= new Item_func_not_all(it); /* ALL */ else @@ -5356,9 +5356,8 @@ singlerow_subselect: singlerow_subselect_init: select_init2 { - $$= new Item_singlerow_subselect(YYTHD, - Lex->current_select->master_unit()-> - first_select()); + $$= new Item_singlerow_subselect(Lex->current_select-> + master_unit()->first_select()); }; exists_subselect: @@ -5371,9 +5370,8 @@ exists_subselect: exists_subselect_init: select_init2 { - $$= new Item_exists_subselect(YYTHD, - Lex->current_select->master_unit()-> - first_select()); + $$= new Item_exists_subselect(Lex->current_select->master_unit()-> + first_select()); }; in_subselect: |