@@ -83,7 +83,6 @@ void Item_subselect::init(st_select_lex *select_lex,
83
83
DBUG_PRINT (" enter" , (" select_lex: 0x%lx this: 0x%lx" ,
84
84
(ulong) select_lex, (ulong) this ));
85
85
unit= select_lex->master_unit ();
86
- thd= unit->thd ;
87
86
88
87
if (unit->item )
89
88
{
@@ -102,7 +101,7 @@ void Item_subselect::init(st_select_lex *select_lex,
102
101
Item can be changed in JOIN::prepare while engine in JOIN::optimize
103
102
=> we do not copy old_engine here
104
103
*/
105
- thd->change_item_tree ((Item**)&unit->item , this );
104
+ unit-> thd ->change_item_tree ((Item**)&unit->item , this );
106
105
engine->change_result (this , result, TRUE );
107
106
}
108
107
}
@@ -117,9 +116,9 @@ void Item_subselect::init(st_select_lex *select_lex,
117
116
NO_MATTER :
118
117
outer_select->parsing_place );
119
118
if (unit->is_union ())
120
- engine= new subselect_union_engine (thd, unit, result, this );
119
+ engine= new subselect_union_engine (unit, result, this );
121
120
else
122
- engine= new subselect_single_select_engine (thd, select_lex, result, this );
121
+ engine= new subselect_single_select_engine (select_lex, result, this );
123
122
}
124
123
{
125
124
SELECT_LEX *upper= unit->outer_select ();
@@ -233,6 +232,10 @@ bool Item_subselect::fix_fields(THD *thd_param, Item **ref)
233
232
uint8 uncacheable;
234
233
bool res;
235
234
235
+ thd= thd_param;
236
+
237
+ DBUG_ASSERT (unit->thd == thd);
238
+
236
239
status_var_increment (thd_param->status_var .feature_subquery );
237
240
238
241
DBUG_ASSERT (fixed == 0 );
@@ -255,7 +258,7 @@ bool Item_subselect::fix_fields(THD *thd_param, Item **ref)
255
258
return TRUE ;
256
259
257
260
258
- if (!(res= engine->prepare ()))
261
+ if (!(res= engine->prepare (thd )))
259
262
{
260
263
// all transformation is done (used by prepared statements)
261
264
changed= 1 ;
@@ -3105,9 +3108,12 @@ bool Item_in_subselect::fix_fields(THD *thd_arg, Item **ref)
3105
3108
{
3106
3109
uint outer_cols_num;
3107
3110
List<Item> *inner_cols;
3108
- char const *save_where= thd ->where ;
3111
+ char const *save_where= thd_arg ->where ;
3109
3112
DBUG_ENTER (" Item_in_subselect::fix_fields" );
3110
3113
3114
+ thd= thd_arg;
3115
+ DBUG_ASSERT (unit->thd == thd);
3116
+
3111
3117
if (test_strategy (SUBS_SEMI_JOIN))
3112
3118
DBUG_RETURN ( !( (*ref)= new Item_int (1 )) );
3113
3119
@@ -3224,7 +3230,8 @@ bool Item_in_subselect::setup_mat_engine()
3224
3230
if (!(mat_engine= new subselect_hash_sj_engine (thd, this , select_engine)))
3225
3231
DBUG_RETURN (TRUE );
3226
3232
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 ,
3228
3235
engine->get_identifier ()))
3229
3236
DBUG_RETURN (TRUE );
3230
3237
@@ -3340,10 +3347,10 @@ void subselect_engine::set_thd(THD *thd_arg)
3340
3347
3341
3348
3342
3349
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,
3344
3351
select_result_interceptor *result_arg,
3345
3352
Item_subselect *item_arg)
3346
- :subselect_engine(thd_arg, item_arg, result_arg),
3353
+ :subselect_engine(item_arg, result_arg),
3347
3354
prepared(0 ), executed(0 ),
3348
3355
select_lex(select), join(0 )
3349
3356
{
@@ -3421,10 +3428,10 @@ void subselect_uniquesubquery_engine::cleanup()
3421
3428
}
3422
3429
3423
3430
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,
3425
3432
select_result_interceptor *result_arg,
3426
3433
Item_subselect *item_arg)
3427
- :subselect_engine(thd_arg, item_arg, result_arg)
3434
+ :subselect_engine(item_arg, result_arg)
3428
3435
{
3429
3436
unit= u;
3430
3437
unit->item = item_arg;
@@ -3457,10 +3464,11 @@ subselect_union_engine::subselect_union_engine(THD *thd_arg, st_select_lex_unit
3457
3464
@retval 1 if error
3458
3465
*/
3459
3466
3460
- int subselect_single_select_engine::prepare ()
3467
+ int subselect_single_select_engine::prepare (THD *thd )
3461
3468
{
3462
3469
if (prepared)
3463
3470
return 0 ;
3471
+ set_thd (thd);
3464
3472
if (select_lex->join )
3465
3473
{
3466
3474
select_lex->cleanup ();
@@ -3489,12 +3497,13 @@ int subselect_single_select_engine::prepare()
3489
3497
return 0 ;
3490
3498
}
3491
3499
3492
- int subselect_union_engine::prepare ()
3500
+ int subselect_union_engine::prepare (THD *thd_arg )
3493
3501
{
3502
+ set_thd (thd_arg);
3494
3503
return unit->prepare (thd, result, SELECT_NO_UNLOCK);
3495
3504
}
3496
3505
3497
- int subselect_uniquesubquery_engine::prepare ()
3506
+ int subselect_uniquesubquery_engine::prepare (THD * )
3498
3507
{
3499
3508
/* Should never be called. */
3500
3509
DBUG_ASSERT (FALSE );
@@ -4956,13 +4965,14 @@ subselect_hash_sj_engine::~subselect_hash_sj_engine()
4956
4965
}
4957
4966
4958
4967
4959
- int subselect_hash_sj_engine::prepare ()
4968
+ int subselect_hash_sj_engine::prepare (THD *thd_arg )
4960
4969
{
4961
4970
/*
4962
4971
Create and optimize the JOIN that will be used to materialize
4963
4972
the subquery if not yet created.
4964
4973
*/
4965
- return materialize_engine->prepare ();
4974
+ set_thd (thd_arg);
4975
+ return materialize_engine->prepare (thd);
4966
4976
}
4967
4977
4968
4978
@@ -5334,7 +5344,7 @@ int subselect_hash_sj_engine::exec()
5334
5344
if (strategy == PARTIAL_MATCH_MERGE)
5335
5345
{
5336
5346
pm_engine=
5337
- new subselect_rowid_merge_engine (thd, (subselect_uniquesubquery_engine*)
5347
+ new subselect_rowid_merge_engine ((subselect_uniquesubquery_engine*)
5338
5348
lookup_engine, tmp_table,
5339
5349
count_pm_keys,
5340
5350
has_covering_null_row,
@@ -5343,6 +5353,7 @@ int subselect_hash_sj_engine::exec()
5343
5353
item, result,
5344
5354
semi_join_conds->argument_list ());
5345
5355
if (!pm_engine ||
5356
+ pm_engine->prepare (thd) ||
5346
5357
((subselect_rowid_merge_engine*) pm_engine)->
5347
5358
init (nn_key_parts, &partial_match_key_parts))
5348
5359
{
@@ -5360,13 +5371,14 @@ int subselect_hash_sj_engine::exec()
5360
5371
if (strategy == PARTIAL_MATCH_SCAN)
5361
5372
{
5362
5373
if (!(pm_engine=
5363
- new subselect_table_scan_engine (thd, (subselect_uniquesubquery_engine*)
5374
+ new subselect_table_scan_engine ((subselect_uniquesubquery_engine*)
5364
5375
lookup_engine, tmp_table,
5365
5376
item, result,
5366
5377
semi_join_conds->argument_list (),
5367
5378
has_covering_null_row,
5368
5379
has_covering_null_columns,
5369
- count_columns_with_nulls)))
5380
+ count_columns_with_nulls)) ||
5381
+ pm_engine->prepare (thd))
5370
5382
{
5371
5383
/* This is an irrecoverable error. */
5372
5384
res= 1 ;
@@ -5815,14 +5827,14 @@ void Ordered_key::print(String *str)
5815
5827
5816
5828
5817
5829
subselect_partial_match_engine::subselect_partial_match_engine (
5818
- THD *thd_arg, subselect_uniquesubquery_engine *engine_arg,
5830
+ subselect_uniquesubquery_engine *engine_arg,
5819
5831
TABLE *tmp_table_arg, Item_subselect *item_arg,
5820
5832
select_result_interceptor *result_arg,
5821
5833
List<Item> *equi_join_conds_arg,
5822
5834
bool has_covering_null_row_arg,
5823
5835
bool has_covering_null_columns_arg,
5824
5836
uint count_columns_with_nulls_arg)
5825
- :subselect_engine(thd_arg, item_arg, result_arg),
5837
+ :subselect_engine(item_arg, result_arg),
5826
5838
tmp_table(tmp_table_arg), lookup_engine(engine_arg),
5827
5839
equi_join_conds(equi_join_conds_arg),
5828
5840
has_covering_null_row(has_covering_null_row_arg),
@@ -6435,15 +6447,15 @@ bool subselect_rowid_merge_engine::partial_match()
6435
6447
6436
6448
6437
6449
subselect_table_scan_engine::subselect_table_scan_engine (
6438
- THD *thd_arg, subselect_uniquesubquery_engine *engine_arg,
6450
+ subselect_uniquesubquery_engine *engine_arg,
6439
6451
TABLE *tmp_table_arg,
6440
6452
Item_subselect *item_arg,
6441
6453
select_result_interceptor *result_arg,
6442
6454
List<Item> *equi_join_conds_arg,
6443
6455
bool has_covering_null_row_arg,
6444
6456
bool has_covering_null_columns_arg,
6445
6457
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,
6447
6459
result_arg, equi_join_conds_arg,
6448
6460
has_covering_null_row_arg,
6449
6461
has_covering_null_columns_arg,
0 commit comments