@@ -79,7 +79,6 @@ void Item_subselect::init(st_select_lex *select_lex,
79
79
DBUG_PRINT (" enter" , (" select_lex: 0x%lx this: 0x%lx" ,
80
80
(ulong) select_lex, (ulong) this ));
81
81
unit= select_lex->master_unit ();
82
- thd= unit->thd ;
83
82
84
83
if (unit->item )
85
84
{
@@ -90,7 +89,7 @@ void Item_subselect::init(st_select_lex *select_lex,
90
89
engine= unit->item ->engine ;
91
90
own_engine= FALSE ;
92
91
parsing_place= unit->item ->parsing_place ;
93
- thd->change_item_tree ((Item**)&unit->item , this );
92
+ unit-> thd ->change_item_tree ((Item**)&unit->item , this );
94
93
engine->change_result (this , result, TRUE );
95
94
}
96
95
else
@@ -104,9 +103,9 @@ void Item_subselect::init(st_select_lex *select_lex,
104
103
NO_MATTER :
105
104
outer_select->parsing_place );
106
105
if (unit->is_union ())
107
- engine= new subselect_union_engine (thd, unit, result, this );
106
+ engine= new subselect_union_engine (unit, result, this );
108
107
else
109
- engine= new subselect_single_select_engine (thd, select_lex, result, this );
108
+ engine= new subselect_single_select_engine (select_lex, result, this );
110
109
}
111
110
{
112
111
SELECT_LEX *upper= unit->outer_select ();
@@ -220,6 +219,10 @@ bool Item_subselect::fix_fields(THD *thd_param, Item **ref)
220
219
uint8 uncacheable;
221
220
bool res;
222
221
222
+ thd= thd_param;
223
+
224
+ DBUG_ASSERT (unit->thd == thd);
225
+
223
226
status_var_increment (thd_param->status_var .feature_subquery );
224
227
225
228
DBUG_ASSERT (fixed == 0 );
@@ -242,7 +245,7 @@ bool Item_subselect::fix_fields(THD *thd_param, Item **ref)
242
245
return TRUE ;
243
246
244
247
245
- if (!(res= engine->prepare ()))
248
+ if (!(res= engine->prepare (thd )))
246
249
{
247
250
// all transformation is done (used by prepared statements)
248
251
changed= 1 ;
@@ -2651,7 +2654,10 @@ bool Item_in_subselect::fix_fields(THD *thd_arg, Item **ref)
2651
2654
{
2652
2655
uint outer_cols_num;
2653
2656
List<Item> *inner_cols;
2654
- char const *save_where= thd->where ;
2657
+ char const *save_where= thd_arg->where ;
2658
+
2659
+ thd= thd_arg;
2660
+ DBUG_ASSERT (unit->thd == thd);
2655
2661
2656
2662
if (test_strategy (SUBS_SEMI_JOIN))
2657
2663
return !( (*ref)= new Item_int (1 ));
@@ -2769,7 +2775,8 @@ bool Item_in_subselect::setup_mat_engine()
2769
2775
if (!(mat_engine= new subselect_hash_sj_engine (thd, this , select_engine)))
2770
2776
DBUG_RETURN (TRUE );
2771
2777
2772
- if (mat_engine->init (&select_engine->join ->fields_list ,
2778
+ if (mat_engine->prepare (thd) ||
2779
+ mat_engine->init (&select_engine->join ->fields_list ,
2773
2780
engine->get_identifier ()))
2774
2781
DBUG_RETURN (TRUE );
2775
2782
@@ -2885,10 +2892,10 @@ void subselect_engine::set_thd(THD *thd_arg)
2885
2892
2886
2893
2887
2894
subselect_single_select_engine::
2888
- subselect_single_select_engine (THD *thd_arg, st_select_lex *select,
2895
+ subselect_single_select_engine (st_select_lex *select,
2889
2896
select_result_interceptor *result_arg,
2890
2897
Item_subselect *item_arg)
2891
- :subselect_engine(thd_arg, item_arg, result_arg),
2898
+ :subselect_engine(item_arg, result_arg),
2892
2899
prepared(0 ), executed(0 ),
2893
2900
select_lex(select), join(0 )
2894
2901
{
@@ -2966,10 +2973,10 @@ void subselect_uniquesubquery_engine::cleanup()
2966
2973
}
2967
2974
2968
2975
2969
- subselect_union_engine::subselect_union_engine (THD *thd_arg, st_select_lex_unit *u,
2976
+ subselect_union_engine::subselect_union_engine (st_select_lex_unit *u,
2970
2977
select_result_interceptor *result_arg,
2971
2978
Item_subselect *item_arg)
2972
- :subselect_engine(thd_arg, item_arg, result_arg)
2979
+ :subselect_engine(item_arg, result_arg)
2973
2980
{
2974
2981
unit= u;
2975
2982
unit->item = item_arg;
@@ -3002,10 +3009,11 @@ subselect_union_engine::subselect_union_engine(THD *thd_arg, st_select_lex_unit
3002
3009
@retval 1 if error
3003
3010
*/
3004
3011
3005
- int subselect_single_select_engine::prepare ()
3012
+ int subselect_single_select_engine::prepare (THD *thd )
3006
3013
{
3007
3014
if (prepared)
3008
3015
return 0 ;
3016
+ set_thd (thd);
3009
3017
if (select_lex->join )
3010
3018
{
3011
3019
select_lex->cleanup ();
@@ -3034,12 +3042,13 @@ int subselect_single_select_engine::prepare()
3034
3042
return 0 ;
3035
3043
}
3036
3044
3037
- int subselect_union_engine::prepare ()
3045
+ int subselect_union_engine::prepare (THD *thd_arg )
3038
3046
{
3047
+ set_thd (thd_arg);
3039
3048
return unit->prepare (thd, result, SELECT_NO_UNLOCK);
3040
3049
}
3041
3050
3042
- int subselect_uniquesubquery_engine::prepare ()
3051
+ int subselect_uniquesubquery_engine::prepare (THD * )
3043
3052
{
3044
3053
/* Should never be called. */
3045
3054
DBUG_ASSERT (FALSE );
@@ -4499,13 +4508,14 @@ subselect_hash_sj_engine::~subselect_hash_sj_engine()
4499
4508
}
4500
4509
4501
4510
4502
- int subselect_hash_sj_engine::prepare ()
4511
+ int subselect_hash_sj_engine::prepare (THD *thd_arg )
4503
4512
{
4504
4513
/*
4505
4514
Create and optimize the JOIN that will be used to materialize
4506
4515
the subquery if not yet created.
4507
4516
*/
4508
- return materialize_engine->prepare ();
4517
+ set_thd (thd_arg);
4518
+ return materialize_engine->prepare (thd);
4509
4519
}
4510
4520
4511
4521
@@ -4877,7 +4887,7 @@ int subselect_hash_sj_engine::exec()
4877
4887
if (strategy == PARTIAL_MATCH_MERGE)
4878
4888
{
4879
4889
pm_engine=
4880
- new subselect_rowid_merge_engine (thd, (subselect_uniquesubquery_engine*)
4890
+ new subselect_rowid_merge_engine ((subselect_uniquesubquery_engine*)
4881
4891
lookup_engine, tmp_table,
4882
4892
count_pm_keys,
4883
4893
has_covering_null_row,
@@ -4886,6 +4896,7 @@ int subselect_hash_sj_engine::exec()
4886
4896
item, result,
4887
4897
semi_join_conds->argument_list ());
4888
4898
if (!pm_engine ||
4899
+ pm_engine->prepare (thd) ||
4889
4900
((subselect_rowid_merge_engine*) pm_engine)->
4890
4901
init (nn_key_parts, &partial_match_key_parts))
4891
4902
{
@@ -4903,13 +4914,14 @@ int subselect_hash_sj_engine::exec()
4903
4914
if (strategy == PARTIAL_MATCH_SCAN)
4904
4915
{
4905
4916
if (!(pm_engine=
4906
- new subselect_table_scan_engine (thd, (subselect_uniquesubquery_engine*)
4917
+ new subselect_table_scan_engine ((subselect_uniquesubquery_engine*)
4907
4918
lookup_engine, tmp_table,
4908
4919
item, result,
4909
4920
semi_join_conds->argument_list (),
4910
4921
has_covering_null_row,
4911
4922
has_covering_null_columns,
4912
- count_columns_with_nulls)))
4923
+ count_columns_with_nulls)) ||
4924
+ pm_engine->prepare (thd))
4913
4925
{
4914
4926
/* This is an irrecoverable error. */
4915
4927
res= 1 ;
@@ -5356,14 +5368,14 @@ void Ordered_key::print(String *str)
5356
5368
5357
5369
5358
5370
subselect_partial_match_engine::subselect_partial_match_engine (
5359
- THD *thd_arg, subselect_uniquesubquery_engine *engine_arg,
5371
+ subselect_uniquesubquery_engine *engine_arg,
5360
5372
TABLE *tmp_table_arg, Item_subselect *item_arg,
5361
5373
select_result_interceptor *result_arg,
5362
5374
List<Item> *equi_join_conds_arg,
5363
5375
bool has_covering_null_row_arg,
5364
5376
bool has_covering_null_columns_arg,
5365
5377
uint count_columns_with_nulls_arg)
5366
- :subselect_engine(thd_arg, item_arg, result_arg),
5378
+ :subselect_engine(item_arg, result_arg),
5367
5379
tmp_table(tmp_table_arg), lookup_engine(engine_arg),
5368
5380
equi_join_conds(equi_join_conds_arg),
5369
5381
has_covering_null_row(has_covering_null_row_arg),
@@ -5976,15 +5988,15 @@ bool subselect_rowid_merge_engine::partial_match()
5976
5988
5977
5989
5978
5990
subselect_table_scan_engine::subselect_table_scan_engine (
5979
- THD *thd_arg, subselect_uniquesubquery_engine *engine_arg,
5991
+ subselect_uniquesubquery_engine *engine_arg,
5980
5992
TABLE *tmp_table_arg,
5981
5993
Item_subselect *item_arg,
5982
5994
select_result_interceptor *result_arg,
5983
5995
List<Item> *equi_join_conds_arg,
5984
5996
bool has_covering_null_row_arg,
5985
5997
bool has_covering_null_columns_arg,
5986
5998
uint count_columns_with_nulls_arg)
5987
- :subselect_partial_match_engine(thd_arg, engine_arg, tmp_table_arg, item_arg,
5999
+ :subselect_partial_match_engine(engine_arg, tmp_table_arg, item_arg,
5988
6000
result_arg, equi_join_conds_arg,
5989
6001
has_covering_null_row_arg,
5990
6002
has_covering_null_columns_arg,
0 commit comments