Skip to content

Commit 0fdb17e

Browse files
committed
Merge branch '5.5' into 10.0
2 parents 6dfe3fb + 79f852a commit 0fdb17e

File tree

2 files changed

+50
-42
lines changed

2 files changed

+50
-42
lines changed

sql/item_subselect.cc

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ void Item_subselect::init(st_select_lex *select_lex,
8383
DBUG_PRINT("enter", ("select_lex: 0x%lx this: 0x%lx",
8484
(ulong) select_lex, (ulong) this));
8585
unit= select_lex->master_unit();
86-
thd= unit->thd;
8786

8887
if (unit->item)
8988
{
@@ -102,7 +101,7 @@ void Item_subselect::init(st_select_lex *select_lex,
102101
Item can be changed in JOIN::prepare while engine in JOIN::optimize
103102
=> we do not copy old_engine here
104103
*/
105-
thd->change_item_tree((Item**)&unit->item, this);
104+
unit->thd->change_item_tree((Item**)&unit->item, this);
106105
engine->change_result(this, result, TRUE);
107106
}
108107
}
@@ -117,9 +116,9 @@ void Item_subselect::init(st_select_lex *select_lex,
117116
NO_MATTER :
118117
outer_select->parsing_place);
119118
if (unit->is_union())
120-
engine= new subselect_union_engine(thd, unit, result, this);
119+
engine= new subselect_union_engine(unit, result, this);
121120
else
122-
engine= new subselect_single_select_engine(thd, select_lex, result, this);
121+
engine= new subselect_single_select_engine(select_lex, result, this);
123122
}
124123
{
125124
SELECT_LEX *upper= unit->outer_select();
@@ -233,6 +232,10 @@ bool Item_subselect::fix_fields(THD *thd_param, Item **ref)
233232
uint8 uncacheable;
234233
bool res;
235234

235+
thd= thd_param;
236+
237+
DBUG_ASSERT(unit->thd == thd);
238+
236239
status_var_increment(thd_param->status_var.feature_subquery);
237240

238241
DBUG_ASSERT(fixed == 0);
@@ -255,7 +258,7 @@ bool Item_subselect::fix_fields(THD *thd_param, Item **ref)
255258
return TRUE;
256259

257260

258-
if (!(res= engine->prepare()))
261+
if (!(res= engine->prepare(thd)))
259262
{
260263
// all transformation is done (used by prepared statements)
261264
changed= 1;
@@ -3105,9 +3108,12 @@ bool Item_in_subselect::fix_fields(THD *thd_arg, Item **ref)
31053108
{
31063109
uint outer_cols_num;
31073110
List<Item> *inner_cols;
3108-
char const *save_where= thd->where;
3111+
char const *save_where= thd_arg->where;
31093112
DBUG_ENTER("Item_in_subselect::fix_fields");
31103113

3114+
thd= thd_arg;
3115+
DBUG_ASSERT(unit->thd == thd);
3116+
31113117
if (test_strategy(SUBS_SEMI_JOIN))
31123118
DBUG_RETURN( !( (*ref)= new Item_int(1)) );
31133119

@@ -3224,7 +3230,8 @@ bool Item_in_subselect::setup_mat_engine()
32243230
if (!(mat_engine= new subselect_hash_sj_engine(thd, this, select_engine)))
32253231
DBUG_RETURN(TRUE);
32263232

3227-
if (mat_engine->init(&select_engine->join->fields_list,
3233+
if (mat_engine->prepare(thd) ||
3234+
mat_engine->init(&select_engine->join->fields_list,
32283235
engine->get_identifier()))
32293236
DBUG_RETURN(TRUE);
32303237

@@ -3340,10 +3347,10 @@ void subselect_engine::set_thd(THD *thd_arg)
33403347

33413348

33423349
subselect_single_select_engine::
3343-
subselect_single_select_engine(THD *thd_arg, st_select_lex *select,
3350+
subselect_single_select_engine(st_select_lex *select,
33443351
select_result_interceptor *result_arg,
33453352
Item_subselect *item_arg)
3346-
:subselect_engine(thd_arg, item_arg, result_arg),
3353+
:subselect_engine(item_arg, result_arg),
33473354
prepared(0), executed(0),
33483355
select_lex(select), join(0)
33493356
{
@@ -3421,10 +3428,10 @@ void subselect_uniquesubquery_engine::cleanup()
34213428
}
34223429

34233430

3424-
subselect_union_engine::subselect_union_engine(THD *thd_arg, st_select_lex_unit *u,
3431+
subselect_union_engine::subselect_union_engine(st_select_lex_unit *u,
34253432
select_result_interceptor *result_arg,
34263433
Item_subselect *item_arg)
3427-
:subselect_engine(thd_arg, item_arg, result_arg)
3434+
:subselect_engine(item_arg, result_arg)
34283435
{
34293436
unit= u;
34303437
unit->item= item_arg;
@@ -3457,10 +3464,11 @@ subselect_union_engine::subselect_union_engine(THD *thd_arg, st_select_lex_unit
34573464
@retval 1 if error
34583465
*/
34593466

3460-
int subselect_single_select_engine::prepare()
3467+
int subselect_single_select_engine::prepare(THD *thd)
34613468
{
34623469
if (prepared)
34633470
return 0;
3471+
set_thd(thd);
34643472
if (select_lex->join)
34653473
{
34663474
select_lex->cleanup();
@@ -3489,12 +3497,13 @@ int subselect_single_select_engine::prepare()
34893497
return 0;
34903498
}
34913499

3492-
int subselect_union_engine::prepare()
3500+
int subselect_union_engine::prepare(THD *thd_arg)
34933501
{
3502+
set_thd(thd_arg);
34943503
return unit->prepare(thd, result, SELECT_NO_UNLOCK);
34953504
}
34963505

3497-
int subselect_uniquesubquery_engine::prepare()
3506+
int subselect_uniquesubquery_engine::prepare(THD *)
34983507
{
34993508
/* Should never be called. */
35003509
DBUG_ASSERT(FALSE);
@@ -4956,13 +4965,14 @@ subselect_hash_sj_engine::~subselect_hash_sj_engine()
49564965
}
49574966

49584967

4959-
int subselect_hash_sj_engine::prepare()
4968+
int subselect_hash_sj_engine::prepare(THD *thd_arg)
49604969
{
49614970
/*
49624971
Create and optimize the JOIN that will be used to materialize
49634972
the subquery if not yet created.
49644973
*/
4965-
return materialize_engine->prepare();
4974+
set_thd(thd_arg);
4975+
return materialize_engine->prepare(thd);
49664976
}
49674977

49684978

@@ -5334,7 +5344,7 @@ int subselect_hash_sj_engine::exec()
53345344
if (strategy == PARTIAL_MATCH_MERGE)
53355345
{
53365346
pm_engine=
5337-
new subselect_rowid_merge_engine(thd, (subselect_uniquesubquery_engine*)
5347+
new subselect_rowid_merge_engine((subselect_uniquesubquery_engine*)
53385348
lookup_engine, tmp_table,
53395349
count_pm_keys,
53405350
has_covering_null_row,
@@ -5343,6 +5353,7 @@ int subselect_hash_sj_engine::exec()
53435353
item, result,
53445354
semi_join_conds->argument_list());
53455355
if (!pm_engine ||
5356+
pm_engine->prepare(thd) ||
53465357
((subselect_rowid_merge_engine*) pm_engine)->
53475358
init(nn_key_parts, &partial_match_key_parts))
53485359
{
@@ -5360,13 +5371,14 @@ int subselect_hash_sj_engine::exec()
53605371
if (strategy == PARTIAL_MATCH_SCAN)
53615372
{
53625373
if (!(pm_engine=
5363-
new subselect_table_scan_engine(thd, (subselect_uniquesubquery_engine*)
5374+
new subselect_table_scan_engine((subselect_uniquesubquery_engine*)
53645375
lookup_engine, tmp_table,
53655376
item, result,
53665377
semi_join_conds->argument_list(),
53675378
has_covering_null_row,
53685379
has_covering_null_columns,
5369-
count_columns_with_nulls)))
5380+
count_columns_with_nulls)) ||
5381+
pm_engine->prepare(thd))
53705382
{
53715383
/* This is an irrecoverable error. */
53725384
res= 1;
@@ -5815,14 +5827,14 @@ void Ordered_key::print(String *str)
58155827

58165828

58175829
subselect_partial_match_engine::subselect_partial_match_engine(
5818-
THD *thd_arg, subselect_uniquesubquery_engine *engine_arg,
5830+
subselect_uniquesubquery_engine *engine_arg,
58195831
TABLE *tmp_table_arg, Item_subselect *item_arg,
58205832
select_result_interceptor *result_arg,
58215833
List<Item> *equi_join_conds_arg,
58225834
bool has_covering_null_row_arg,
58235835
bool has_covering_null_columns_arg,
58245836
uint count_columns_with_nulls_arg)
5825-
:subselect_engine(thd_arg, item_arg, result_arg),
5837+
:subselect_engine(item_arg, result_arg),
58265838
tmp_table(tmp_table_arg), lookup_engine(engine_arg),
58275839
equi_join_conds(equi_join_conds_arg),
58285840
has_covering_null_row(has_covering_null_row_arg),
@@ -6435,15 +6447,15 @@ bool subselect_rowid_merge_engine::partial_match()
64356447

64366448

64376449
subselect_table_scan_engine::subselect_table_scan_engine(
6438-
THD *thd_arg, subselect_uniquesubquery_engine *engine_arg,
6450+
subselect_uniquesubquery_engine *engine_arg,
64396451
TABLE *tmp_table_arg,
64406452
Item_subselect *item_arg,
64416453
select_result_interceptor *result_arg,
64426454
List<Item> *equi_join_conds_arg,
64436455
bool has_covering_null_row_arg,
64446456
bool has_covering_null_columns_arg,
64456457
uint count_columns_with_nulls_arg)
6446-
:subselect_partial_match_engine(thd_arg, engine_arg, tmp_table_arg, item_arg,
6458+
:subselect_partial_match_engine(engine_arg, tmp_table_arg, item_arg,
64476459
result_arg, equi_join_conds_arg,
64486460
has_covering_null_row_arg,
64496461
has_covering_null_columns_arg,

sql/item_subselect.h

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -750,15 +750,14 @@ class subselect_engine: public Sql_alloc
750750
INDEXSUBQUERY_ENGINE, HASH_SJ_ENGINE,
751751
ROWID_MERGE_ENGINE, TABLE_SCAN_ENGINE};
752752

753-
subselect_engine(THD *thd_arg, Item_subselect *si,
753+
subselect_engine(Item_subselect *si,
754754
select_result_interceptor *res)
755755
{
756756
result= res;
757757
item= si;
758758
cmp_type= res_type= STRING_RESULT;
759759
res_field_type= MYSQL_TYPE_VAR_STRING;
760760
maybe_null= 0;
761-
set_thd(thd_arg);
762761
}
763762
virtual ~subselect_engine() {}; // to satisfy compiler
764763
virtual void cleanup()= 0;
@@ -769,7 +768,7 @@ class subselect_engine: public Sql_alloc
769768
*/
770769
void set_thd(THD *thd_arg);
771770
THD * get_thd() { return thd; }
772-
virtual int prepare()= 0;
771+
virtual int prepare(THD *)= 0;
773772
virtual void fix_length_and_dec(Item_cache** row)= 0;
774773
/*
775774
Execute the engine
@@ -824,11 +823,11 @@ class subselect_single_select_engine: public subselect_engine
824823
st_select_lex *select_lex; /* corresponding select_lex */
825824
JOIN * join; /* corresponding JOIN structure */
826825
public:
827-
subselect_single_select_engine(THD *thd_arg, st_select_lex *select,
826+
subselect_single_select_engine(st_select_lex *select,
828827
select_result_interceptor *result,
829828
Item_subselect *item);
830829
void cleanup();
831-
int prepare();
830+
int prepare(THD *thd);
832831
void fix_length_and_dec(Item_cache** row);
833832
int exec();
834833
uint cols();
@@ -858,11 +857,11 @@ class subselect_union_engine: public subselect_engine
858857
{
859858
st_select_lex_unit *unit; /* corresponding unit structure */
860859
public:
861-
subselect_union_engine(THD *thd_arg, st_select_lex_unit *u,
860+
subselect_union_engine(st_select_lex_unit *u,
862861
select_result_interceptor *result,
863862
Item_subselect *item);
864863
void cleanup();
865-
int prepare();
864+
int prepare(THD *);
866865
void fix_length_and_dec(Item_cache** row);
867866
int exec();
868867
uint cols();
@@ -915,11 +914,11 @@ class subselect_uniquesubquery_engine: public subselect_engine
915914
// constructor can assign THD because it will be called after JOIN::prepare
916915
subselect_uniquesubquery_engine(THD *thd_arg, st_join_table *tab_arg,
917916
Item_subselect *subs, Item *where)
918-
:subselect_engine(thd_arg, subs, 0), tab(tab_arg), cond(where)
917+
:subselect_engine(subs, 0), tab(tab_arg), cond(where)
919918
{}
920919
~subselect_uniquesubquery_engine();
921920
void cleanup();
922-
int prepare();
921+
int prepare(THD *);
923922
void fix_length_and_dec(Item_cache** row);
924923
int exec();
925924
uint cols() { return 1; }
@@ -1047,7 +1046,7 @@ class subselect_hash_sj_engine : public subselect_engine
10471046

10481047
subselect_hash_sj_engine(THD *thd, Item_subselect *in_predicate,
10491048
subselect_single_select_engine *old_engine)
1050-
: subselect_engine(thd, in_predicate, NULL),
1049+
: subselect_engine(in_predicate, NULL),
10511050
tmp_table(NULL), is_materialized(FALSE), materialize_engine(old_engine),
10521051
materialize_join(NULL), semi_join_conds(NULL), lookup_engine(NULL),
10531052
count_partial_match_columns(0), count_null_only_columns(0),
@@ -1057,7 +1056,7 @@ class subselect_hash_sj_engine : public subselect_engine
10571056

10581057
bool init(List<Item> *tmp_columns, uint subquery_id);
10591058
void cleanup();
1060-
int prepare();
1059+
int prepare(THD *);
10611060
int exec();
10621061
virtual void print(String *str, enum_query_type query_type);
10631062
uint cols()
@@ -1336,15 +1335,14 @@ class subselect_partial_match_engine : public subselect_engine
13361335
protected:
13371336
virtual bool partial_match()= 0;
13381337
public:
1339-
subselect_partial_match_engine(THD *thd_arg,
1340-
subselect_uniquesubquery_engine *engine_arg,
1338+
subselect_partial_match_engine(subselect_uniquesubquery_engine *engine_arg,
13411339
TABLE *tmp_table_arg, Item_subselect *item_arg,
13421340
select_result_interceptor *result_arg,
13431341
List<Item> *equi_join_conds_arg,
13441342
bool has_covering_null_row_arg,
13451343
bool has_covering_null_columns_arg,
13461344
uint count_columns_with_nulls_arg);
1347-
int prepare() { return 0; }
1345+
int prepare(THD *thd_arg) { set_thd(thd_arg); return 0; }
13481346
int exec();
13491347
void fix_length_and_dec(Item_cache**) {}
13501348
uint cols() { /* TODO: what is the correct value? */ return 1; }
@@ -1431,16 +1429,15 @@ class subselect_rowid_merge_engine: public subselect_partial_match_engine
14311429
bool exists_complementing_null_row(MY_BITMAP *keys_to_complement);
14321430
bool partial_match();
14331431
public:
1434-
subselect_rowid_merge_engine(THD *thd_arg,
1435-
subselect_uniquesubquery_engine *engine_arg,
1432+
subselect_rowid_merge_engine(subselect_uniquesubquery_engine *engine_arg,
14361433
TABLE *tmp_table_arg, uint merge_keys_count_arg,
14371434
bool has_covering_null_row_arg,
14381435
bool has_covering_null_columns_arg,
14391436
uint count_columns_with_nulls_arg,
14401437
Item_subselect *item_arg,
14411438
select_result_interceptor *result_arg,
14421439
List<Item> *equi_join_conds_arg)
1443-
:subselect_partial_match_engine(thd_arg, engine_arg, tmp_table_arg,
1440+
:subselect_partial_match_engine(engine_arg, tmp_table_arg,
14441441
item_arg, result_arg, equi_join_conds_arg,
14451442
has_covering_null_row_arg,
14461443
has_covering_null_columns_arg,
@@ -1459,8 +1456,7 @@ class subselect_table_scan_engine: public subselect_partial_match_engine
14591456
protected:
14601457
bool partial_match();
14611458
public:
1462-
subselect_table_scan_engine(THD *thd_arg,
1463-
subselect_uniquesubquery_engine *engine_arg,
1459+
subselect_table_scan_engine(subselect_uniquesubquery_engine *engine_arg,
14641460
TABLE *tmp_table_arg, Item_subselect *item_arg,
14651461
select_result_interceptor *result_arg,
14661462
List<Item> *equi_join_conds_arg,

0 commit comments

Comments
 (0)