Commit 0460a23b authored by unknown's avatar unknown

thd pointer storing moved to fix_fields() (WL#1254) (SCRUM)


sql/item_subselect.cc:
  thd pointer storing moved to fix_fields()
sql/item_subselect.h:
  thd pointer storing moved to fix_fields()
sql/sql_yacc.yy:
  thd pointer storing moved to fix_fields()
parent 66ba1381
...@@ -46,7 +46,7 @@ Item_subselect::Item_subselect(): ...@@ -46,7 +46,7 @@ Item_subselect::Item_subselect():
null_value= 1; 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) select_subselect *result)
{ {
...@@ -54,11 +54,10 @@ void Item_subselect::init(THD *thd, st_select_lex *select_lex, ...@@ -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)); DBUG_PRINT("subs", ("select_lex 0x%xl", (ulong) select_lex));
if (select_lex->next_select()) 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); this);
else else
engine= new subselect_single_select_engine(thd, select_lex, result, engine= new subselect_single_select_engine(select_lex, result, this);
this);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -78,7 +77,7 @@ Item_subselect::select_transformer(JOIN *join) ...@@ -78,7 +77,7 @@ Item_subselect::select_transformer(JOIN *join)
bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref) 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; char const *save_where= thd->where;
int res= engine->prepare(); int res= engine->prepare();
...@@ -151,12 +150,11 @@ inline table_map Item_subselect::used_tables() const ...@@ -151,12 +150,11 @@ inline table_map Item_subselect::used_tables() const
(engine->uncacheable() ? RAND_TABLE_BIT : 0L)); (engine->uncacheable() ? RAND_TABLE_BIT : 0L));
} }
Item_singlerow_subselect::Item_singlerow_subselect(THD *thd, Item_singlerow_subselect::Item_singlerow_subselect(st_select_lex *select_lex):
st_select_lex *select_lex):
Item_subselect(), value(0) Item_subselect(), value(0)
{ {
DBUG_ENTER("Item_singlerow_subselect::Item_singlerow_subselect"); 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; max_columns= 1;
maybe_null= 1; maybe_null= 1;
max_columns= UINT_MAX; max_columns= UINT_MAX;
...@@ -325,12 +323,11 @@ String *Item_singlerow_subselect::val_str (String *str) ...@@ -325,12 +323,11 @@ String *Item_singlerow_subselect::val_str (String *str)
} }
} }
Item_exists_subselect::Item_exists_subselect(THD *thd, Item_exists_subselect::Item_exists_subselect(st_select_lex *select_lex):
st_select_lex *select_lex):
Item_subselect() Item_subselect()
{ {
DBUG_ENTER("Item_exists_subselect::Item_exists_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; max_columns= UINT_MAX;
null_value= 0; //can't be NULL null_value= 0; //can't be NULL
maybe_null= 0; //can't be NULL maybe_null= 0; //can't be NULL
...@@ -355,13 +352,13 @@ bool Item_in_subselect::test_limit(SELECT_LEX_UNIT *unit) ...@@ -355,13 +352,13 @@ bool Item_in_subselect::test_limit(SELECT_LEX_UNIT *unit)
return(0); 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): st_select_lex *select_lex):
Item_exists_subselect() Item_exists_subselect()
{ {
DBUG_ENTER("Item_in_subselect::Item_in_subselect"); DBUG_ENTER("Item_in_subselect::Item_in_subselect");
left_expr= left_exp; 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; max_columns= UINT_MAX;
maybe_null= 1; maybe_null= 1;
abort_on_null= 0; abort_on_null= 0;
...@@ -371,7 +368,7 @@ Item_in_subselect::Item_in_subselect(THD *thd, Item * left_exp, ...@@ -371,7 +368,7 @@ Item_in_subselect::Item_in_subselect(THD *thd, Item * left_exp,
DBUG_VOID_RETURN; 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, compare_func_creator fn,
st_select_lex *select_lex): st_select_lex *select_lex):
Item_in_subselect() Item_in_subselect()
...@@ -379,7 +376,7 @@ Item_allany_subselect::Item_allany_subselect(THD *thd, Item * left_exp, ...@@ -379,7 +376,7 @@ Item_allany_subselect::Item_allany_subselect(THD *thd, Item * left_exp,
DBUG_ENTER("Item_in_subselect::Item_in_subselect"); DBUG_ENTER("Item_in_subselect::Item_in_subselect");
left_expr= left_exp; left_expr= left_exp;
func= fn; func= fn;
init(thd, select_lex, new select_exists_subselect(this)); init(select_lex, new select_exists_subselect(this));
max_columns= 1; max_columns= 1;
abort_on_null= 0; abort_on_null= 0;
reset(); reset();
...@@ -708,12 +705,12 @@ Item_allany_subselect::select_transformer(JOIN *join) ...@@ -708,12 +705,12 @@ Item_allany_subselect::select_transformer(JOIN *join)
return single_value_transformer(join, left_expr, func); return single_value_transformer(join, left_expr, func);
} }
subselect_single_select_engine::subselect_single_select_engine(THD *thd, subselect_single_select_engine::
st_select_lex *select, subselect_single_select_engine(st_select_lex *select,
select_subselect *result, select_subselect *result,
Item_subselect *item): Item_subselect *item)
subselect_engine(thd, item, result), :subselect_engine(item, result),
prepared(0), optimized(0), executed(0) prepared(0), optimized(0), executed(0), join(0)
{ {
select_lex= select; select_lex= select;
SELECT_LEX_UNIT *unit= select_lex->master_unit(); SELECT_LEX_UNIT *unit= select_lex->master_unit();
...@@ -724,24 +721,19 @@ subselect_single_select_engine::subselect_single_select_engine(THD *thd, ...@@ -724,24 +721,19 @@ subselect_single_select_engine::subselect_single_select_engine(THD *thd,
unit->select_limit_cnt= HA_POS_ERROR; // no limit unit->select_limit_cnt= HA_POS_ERROR; // no limit
if (unit->select_limit_cnt == HA_POS_ERROR) if (unit->select_limit_cnt == HA_POS_ERROR)
select_lex->options&= ~OPTION_FOUND_ROWS; 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; unit->item= item;
this->select_lex= select_lex; this->select_lex= select_lex;
} }
subselect_union_engine::subselect_union_engine(THD *thd, subselect_union_engine::subselect_union_engine(st_select_lex_unit *u,
st_select_lex_unit *u,
select_subselect *result, select_subselect *result,
Item_subselect *item): Item_subselect *item)
subselect_engine(thd, item, result) :subselect_engine(item, result)
{ {
unit= u; unit= u;
if (!result) if (!result)
//out of memory //out of memory
thd->fatal_error(); current_thd->fatal_error();
unit->item= item; unit->item= item;
} }
...@@ -749,6 +741,13 @@ int subselect_single_select_engine::prepare() ...@@ -749,6 +741,13 @@ int subselect_single_select_engine::prepare()
{ {
if (prepared) if (prepared)
return 0; 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; prepared= 1;
SELECT_LEX *save_select= thd->lex.current_select; SELECT_LEX *save_select= thd->lex.current_select;
thd->lex.current_select= select_lex; thd->lex.current_select= select_lex;
......
...@@ -75,7 +75,7 @@ class Item_subselect :public Item_result_field ...@@ -75,7 +75,7 @@ class Item_subselect :public Item_result_field
pointer in constructor initialization list, but we need pass pointer pointer in constructor initialization list, but we need pass pointer
to subselect Item class to select_subselect classes constructor. 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); select_subselect *result);
~Item_subselect(); ~Item_subselect();
...@@ -122,7 +122,7 @@ class Item_singlerow_subselect :public Item_subselect ...@@ -122,7 +122,7 @@ class Item_singlerow_subselect :public Item_subselect
protected: protected:
Item_cache *value, **row; Item_cache *value, **row;
public: 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_singlerow_subselect(Item_singlerow_subselect *item):
Item_subselect(item) Item_subselect(item)
{ {
...@@ -161,7 +161,7 @@ class Item_exists_subselect :public Item_subselect ...@@ -161,7 +161,7 @@ class Item_exists_subselect :public Item_subselect
longlong value; /* value of this item (boolean: exists/not-exists) */ longlong value; /* value of this item (boolean: exists/not-exists) */
public: 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_exists_subselect(Item_exists_subselect *item):
Item_subselect(item) Item_subselect(item)
{ {
...@@ -202,7 +202,7 @@ class Item_in_subselect :public Item_exists_subselect ...@@ -202,7 +202,7 @@ class Item_in_subselect :public Item_exists_subselect
bool was_null; bool was_null;
bool abort_on_null; bool abort_on_null;
public: public:
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_in_subselect *item);
Item_in_subselect(): Item_exists_subselect(), abort_on_null(0) {} Item_in_subselect(): Item_exists_subselect(), abort_on_null(0) {}
...@@ -237,7 +237,7 @@ class Item_allany_subselect :public Item_in_subselect ...@@ -237,7 +237,7 @@ class Item_allany_subselect :public Item_in_subselect
compare_func_creator func; compare_func_creator func;
public: 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); st_select_lex *select_lex);
Item_allany_subselect(Item_allany_subselect *item); Item_allany_subselect(Item_allany_subselect *item);
subs_type substype() { return ALLANY_SUBS; } subs_type substype() { return ALLANY_SUBS; }
...@@ -254,16 +254,19 @@ class subselect_engine: public Sql_alloc ...@@ -254,16 +254,19 @@ class subselect_engine: public Sql_alloc
bool maybe_null; /* may be null (first item in select) */ bool maybe_null; /* may be null (first item in select) */
public: public:
subselect_engine(THD *thd, Item_subselect *si, select_subselect *res) subselect_engine(Item_subselect *si, select_subselect *res)
:thd(0)
{ {
result= res; result= res;
item= si; item= si;
this->thd= thd;
res_type= STRING_RESULT; res_type= STRING_RESULT;
maybe_null= 0; maybe_null= 0;
} }
virtual ~subselect_engine() {}; // to satisfy compiler 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 int prepare()= 0;
virtual void fix_length_and_dec(Item_cache** row)= 0; virtual void fix_length_and_dec(Item_cache** row)= 0;
virtual int exec()= 0; virtual int exec()= 0;
...@@ -283,7 +286,7 @@ class subselect_single_select_engine: public subselect_engine ...@@ -283,7 +286,7 @@ class subselect_single_select_engine: public subselect_engine
st_select_lex *select_lex; /* corresponding select_lex */ st_select_lex *select_lex; /* corresponding select_lex */
JOIN * join; /* corresponding JOIN structure */ JOIN * join; /* corresponding JOIN structure */
public: public:
subselect_single_select_engine(THD *thd, st_select_lex *select, subselect_single_select_engine(st_select_lex *select,
select_subselect *result, select_subselect *result,
Item_subselect *item); Item_subselect *item);
int prepare(); int prepare();
...@@ -299,8 +302,7 @@ class subselect_union_engine: public subselect_engine ...@@ -299,8 +302,7 @@ class subselect_union_engine: public subselect_engine
{ {
st_select_lex_unit *unit; /* corresponding unit structure */ st_select_lex_unit *unit; /* corresponding unit structure */
public: public:
subselect_union_engine(THD *thd, subselect_union_engine(st_select_lex_unit *u,
st_select_lex_unit *u,
select_subselect *result, select_subselect *result,
Item_subselect *item); Item_subselect *item);
int prepare(); int prepare();
...@@ -320,10 +322,13 @@ class subselect_uniquesubquery_engine: public subselect_engine ...@@ -320,10 +322,13 @@ class subselect_uniquesubquery_engine: public subselect_engine
Item *cond; Item *cond;
public: public:
// constructor can assign THD because it will be called after JOIN::prepare
subselect_uniquesubquery_engine(THD *thd, st_join_table *tab_arg, subselect_uniquesubquery_engine(THD *thd, st_join_table *tab_arg,
Item_subselect *subs, Item *where) 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(); int prepare();
void fix_length_and_dec(Item_cache** row); void fix_length_and_dec(Item_cache** row);
...@@ -339,6 +344,8 @@ class subselect_indexsubquery_engine: public subselect_uniquesubquery_engine ...@@ -339,6 +344,8 @@ class subselect_indexsubquery_engine: public subselect_uniquesubquery_engine
{ {
bool check_null; bool check_null;
public: public:
// constructor can assign THD because it will be called after JOIN::prepare
subselect_indexsubquery_engine(THD *thd, st_join_table *tab_arg, subselect_indexsubquery_engine(THD *thd, st_join_table *tab_arg,
Item_subselect *subs, Item *where, Item_subselect *subs, Item *where,
bool chk_null) bool chk_null)
......
...@@ -2238,10 +2238,10 @@ expr_expr: ...@@ -2238,10 +2238,10 @@ expr_expr:
| expr NOT IN_SYM '(' expr_list ')' | expr NOT IN_SYM '(' expr_list ')'
{ $5->push_front($1); $$= new Item_func_not(new Item_func_in(*$5)); } { $5->push_front($1); $$= new Item_func_not(new Item_func_in(*$5)); }
| expr IN_SYM in_subselect | expr IN_SYM in_subselect
{ $$= new Item_in_subselect(YYTHD, $1, $3); } { $$= new Item_in_subselect($1, $3); }
| expr NOT IN_SYM in_subselect | 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 | expr BETWEEN_SYM no_and_expr AND expr
{ $$= new Item_func_between($1,$3,$5); } { $$= new Item_func_between($1,$3,$5); }
...@@ -2263,7 +2263,7 @@ expr_expr: ...@@ -2263,7 +2263,7 @@ expr_expr:
| expr comp_op all_or_any in_subselect %prec EQ | expr comp_op all_or_any in_subselect %prec EQ
{ {
Item_allany_subselect *it= Item_allany_subselect *it=
new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4); new Item_allany_subselect($1, (*$2)($3), $4);
if ($3) if ($3)
$$ = new Item_func_not(it); /* ALL */ $$ = new Item_func_not(it); /* ALL */
else else
...@@ -2309,7 +2309,7 @@ no_in_expr: ...@@ -2309,7 +2309,7 @@ no_in_expr:
| no_in_expr comp_op all_or_any in_subselect %prec EQ | no_in_expr comp_op all_or_any in_subselect %prec EQ
{ {
Item_allany_subselect *it= Item_allany_subselect *it=
new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4); new Item_allany_subselect($1, (*$2)($3), $4);
if ($3) if ($3)
$$ = new Item_func_not(it); /* ALL */ $$ = new Item_func_not(it); /* ALL */
else else
...@@ -2340,10 +2340,10 @@ no_and_expr: ...@@ -2340,10 +2340,10 @@ no_and_expr:
| no_and_expr NOT IN_SYM '(' expr_list ')' | no_and_expr NOT IN_SYM '(' expr_list ')'
{ $5->push_front($1); $$= new Item_func_not(new Item_func_in(*$5)); } { $5->push_front($1); $$= new Item_func_not(new Item_func_in(*$5)); }
| no_and_expr IN_SYM in_subselect | 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 | 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 | no_and_expr BETWEEN_SYM no_and_expr AND expr
{ $$= new Item_func_between($1,$3,$5); } { $$= new Item_func_between($1,$3,$5); }
...@@ -2364,7 +2364,7 @@ no_and_expr: ...@@ -2364,7 +2364,7 @@ no_and_expr:
| no_and_expr comp_op all_or_any in_subselect %prec EQ | no_and_expr comp_op all_or_any in_subselect %prec EQ
{ {
Item_allany_subselect *it= Item_allany_subselect *it=
new Item_allany_subselect(YYTHD, $1, (*$2)($3), $4); new Item_allany_subselect($1, (*$2)($3), $4);
if ($3) if ($3)
$$ = new Item_func_not(it); /* ALL */ $$ = new Item_func_not(it); /* ALL */
else else
...@@ -5349,9 +5349,8 @@ singlerow_subselect: ...@@ -5349,9 +5349,8 @@ singlerow_subselect:
singlerow_subselect_init: singlerow_subselect_init:
select_init2 select_init2
{ {
$$= new Item_singlerow_subselect(YYTHD, $$= new Item_singlerow_subselect(Lex->current_select->
Lex->current_select->master_unit()-> master_unit()->first_select());
first_select());
}; };
exists_subselect: exists_subselect:
...@@ -5364,8 +5363,7 @@ exists_subselect: ...@@ -5364,8 +5363,7 @@ exists_subselect:
exists_subselect_init: exists_subselect_init:
select_init2 select_init2
{ {
$$= new Item_exists_subselect(YYTHD, $$= new Item_exists_subselect(Lex->current_select->master_unit()->
Lex->current_select->master_unit()->
first_select()); first_select());
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment