~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item_subselect.cc

  • Committer: Brian Aker
  • Date: 2008-10-20 04:28:21 UTC
  • mto: (492.3.21 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: brian@tangent.org-20081020042821-rqqdrccuu8195k3y
Second pass of thd cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
}
34
34
 
35
35
Item_subselect::Item_subselect():
36
 
  Item_result_field(), value_assigned(0), thd(0), substitution(0),
 
36
  Item_result_field(), value_assigned(0), session(0), substitution(0),
37
37
  engine(0), old_engine(0), used_tables_cache(0), have_to_be_excluded(0),
38
38
  const_item_cache(1), engine_changed(0), changed(0),
39
39
  is_correlated(false)
149
149
}
150
150
 
151
151
 
152
 
bool Item_subselect::fix_fields(Session *thd_param, Item **ref)
 
152
bool Item_subselect::fix_fields(Session *session_param, Item **ref)
153
153
{
154
 
  char const *save_where= thd_param->where;
 
154
  char const *save_where= session_param->where;
155
155
  uint8_t uncacheable;
156
156
  bool res;
157
157
 
158
158
  assert(fixed == 0);
159
 
  engine->set_thd((thd= thd_param));
 
159
  engine->set_session((session= session_param));
160
160
 
161
 
  if (check_stack_overrun(thd, STACK_MIN_SIZE, (unsigned char*)&res))
 
161
  if (check_stack_overrun(session, STACK_MIN_SIZE, (unsigned char*)&res))
162
162
    return true;
163
163
 
164
164
  res= engine->prepare();
189
189
      if (have_to_be_excluded)
190
190
        engine->exclude();
191
191
      substitution= 0;
192
 
      thd->where= "checking transformed subquery";
 
192
      session->where= "checking transformed subquery";
193
193
      if (!(*ref)->fixed)
194
 
        ret= (*ref)->fix_fields(thd, ref);
195
 
      thd->where= save_where;
 
194
        ret= (*ref)->fix_fields(session, ref);
 
195
      session->where= save_where;
196
196
      return ret;
197
197
    }
198
198
    // Is it one field subselect?
215
215
  fixed= 1;
216
216
 
217
217
err:
218
 
  thd->where= save_where;
 
218
  session->where= save_where;
219
219
  return res;
220
220
}
221
221
 
263
263
{
264
264
  int res;
265
265
 
266
 
  if (thd->is_error())
 
266
  if (session->is_error())
267
267
  /* Do not execute subselect in case of a fatal error */
268
268
    return 1;
269
269
 
343
343
  return const_item_cache;
344
344
}
345
345
 
346
 
Item *Item_subselect::get_tmp_table_item(Session *thd_arg)
 
346
Item *Item_subselect::get_tmp_table_item(Session *session_arg)
347
347
{
348
348
  if (!with_sum_func && !const_item())
349
349
    return new Item_field(result_field);
350
 
  return copy_or_same(thd_arg);
 
350
  return copy_or_same(session_arg);
351
351
}
352
352
 
353
353
void Item_subselect::update_used_tables()
397
397
  return(result);
398
398
}
399
399
 
400
 
Item_maxmin_subselect::Item_maxmin_subselect(Session *thd_param,
 
400
Item_maxmin_subselect::Item_maxmin_subselect(Session *session_param,
401
401
                                             Item_subselect *parent,
402
402
                                             st_select_lex *select_lex,
403
403
                                             bool max_arg)
418
418
 
419
419
  /*
420
420
    this subquery always creates during preparation, so we can assign
421
 
    thd here
 
421
    session here
422
422
  */
423
 
  thd= thd_param;
 
423
  session= session_param;
424
424
 
425
425
  return;
426
426
}
493
493
  {
494
494
 
495
495
    have_to_be_excluded= 1;
496
 
    if (thd->lex->describe)
 
496
    if (session->lex->describe)
497
497
    {
498
498
      char warn_buff[DRIZZLE_ERRMSG_SIZE];
499
499
      sprintf(warn_buff, ER(ER_SELECT_REDUCED), select_lex->select_number);
500
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
 
500
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
501
501
                   ER_SELECT_REDUCED, warn_buff);
502
502
    }
503
503
    substitution= select_lex->item_list.head();
1011
1011
        it.replace(item);
1012
1012
      }
1013
1013
 
1014
 
      save_allow_sum_func= thd->lex->allow_sum_func;
1015
 
      thd->lex->allow_sum_func|= 1 << thd->lex->current_select->nest_level;
 
1014
      save_allow_sum_func= session->lex->allow_sum_func;
 
1015
      session->lex->allow_sum_func|= 1 << session->lex->current_select->nest_level;
1016
1016
      /*
1017
1017
        Item_sum_(max|min) can't substitute other item => we can use 0 as
1018
1018
        reference, also Item_sum_(max|min) can't be fixed after creation, so
1019
1019
        we do not check item->fixed
1020
1020
      */
1021
 
      if (item->fix_fields(thd, 0))
 
1021
      if (item->fix_fields(session, 0))
1022
1022
        return(RES_ERROR);
1023
 
      thd->lex->allow_sum_func= save_allow_sum_func; 
 
1023
      session->lex->allow_sum_func= save_allow_sum_func; 
1024
1024
      /* we added aggregate function => we have to change statistic */
1025
1025
      count_field_types(select_lex, &join->tmp_table_param, join->all_fields, 
1026
1026
                        0);
1030
1030
    else
1031
1031
    {
1032
1032
      Item_maxmin_subselect *item;
1033
 
      subs= item= new Item_maxmin_subselect(thd, this, select_lex, func->l_op());
 
1033
      subs= item= new Item_maxmin_subselect(session, this, select_lex, func->l_op());
1034
1034
      if (upper_item)
1035
1035
        upper_item->set_sub_test(item);
1036
1036
    }
1045
1045
    SELECT_LEX_UNIT *master_unit= select_lex->master_unit();
1046
1046
    substitution= optimizer;
1047
1047
 
1048
 
    SELECT_LEX *current= thd->lex->current_select, *up;
 
1048
    SELECT_LEX *current= session->lex->current_select, *up;
1049
1049
 
1050
 
    thd->lex->current_select= up= current->return_after_parsing();
 
1050
    session->lex->current_select= up= current->return_after_parsing();
1051
1051
    //optimizer never use Item **ref => we can pass 0 as parameter
1052
 
    if (!optimizer || optimizer->fix_left(thd, 0))
 
1052
    if (!optimizer || optimizer->fix_left(session, 0))
1053
1053
    {
1054
 
      thd->lex->current_select= current;
 
1054
      session->lex->current_select= current;
1055
1055
      return(RES_ERROR);
1056
1056
    }
1057
 
    thd->lex->current_select= current;
 
1057
    session->lex->current_select= current;
1058
1058
 
1059
1059
    /*
1060
1060
      As far as  Item_ref_in_optimizer do not substitute itself on fix_fields
1070
1070
 
1071
1071
  if (!abort_on_null && left_expr->maybe_null && !pushed_cond_guards)
1072
1072
  {
1073
 
    if (!(pushed_cond_guards= (bool*)join->thd->alloc(sizeof(bool))))
 
1073
    if (!(pushed_cond_guards= (bool*)join->session->alloc(sizeof(bool))))
1074
1074
      return(RES_ERROR);
1075
1075
    pushed_cond_guards[0]= true;
1076
1076
  }
1162
1162
      we do not check join->having->fixed, because Item_and (from and_items)
1163
1163
      or comparison function (from func->create) can't be fixed after creation
1164
1164
    */
1165
 
    tmp= join->having->fix_fields(thd, 0);
 
1165
    tmp= join->having->fix_fields(session, 0);
1166
1166
    select_lex->having_fix_field= 0;
1167
1167
    if (tmp)
1168
1168
      return(RES_ERROR);
1204
1204
          and_items) or comparison function (from func->create) can't be
1205
1205
          fixed after creation
1206
1206
        */
1207
 
        tmp= join->having->fix_fields(thd, 0);
 
1207
        tmp= join->having->fix_fields(session, 0);
1208
1208
        select_lex->having_fix_field= 0;
1209
1209
        if (tmp)
1210
1210
          return(RES_ERROR);
1238
1238
        we do not check join->conds->fixed, because Item_and can't be fixed
1239
1239
        after creation
1240
1240
      */
1241
 
      if (join->conds->fix_fields(thd, 0))
 
1241
      if (join->conds->fix_fields(session, 0))
1242
1242
        return(RES_ERROR);
1243
1243
    }
1244
1244
    else
1271
1271
          we do not check join->having->fixed, because comparison function
1272
1272
          (from func->create) can't be fixed after creation
1273
1273
        */
1274
 
        tmp= join->having->fix_fields(thd, 0);
 
1274
        tmp= join->having->fix_fields(session, 0);
1275
1275
        select_lex->having_fix_field= 0;
1276
1276
        if (tmp)
1277
1277
          return(RES_ERROR);
1283
1283
        // fix_field of item will be done in time of substituting
1284
1284
        substitution= item;
1285
1285
        have_to_be_excluded= 1;
1286
 
        if (thd->lex->describe)
 
1286
        if (session->lex->describe)
1287
1287
        {
1288
1288
          char warn_buff[DRIZZLE_ERRMSG_SIZE];
1289
1289
          sprintf(warn_buff, ER(ER_SELECT_REDUCED), select_lex->select_number);
1290
 
          push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
 
1290
          push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1291
1291
                       ER_SELECT_REDUCED, warn_buff);
1292
1292
        }
1293
1293
        return(RES_REDUCE);
1321
1321
    SELECT_LEX_UNIT *master_unit= select_lex->master_unit();
1322
1322
    substitution= optimizer;
1323
1323
 
1324
 
    SELECT_LEX *current= thd->lex->current_select, *up;
1325
 
    thd->lex->current_select= up= current->return_after_parsing();
 
1324
    SELECT_LEX *current= session->lex->current_select, *up;
 
1325
    session->lex->current_select= up= current->return_after_parsing();
1326
1326
    //optimizer never use Item **ref => we can pass 0 as parameter
1327
 
    if (!optimizer || optimizer->fix_left(thd, 0))
 
1327
    if (!optimizer || optimizer->fix_left(session, 0))
1328
1328
    {
1329
 
      thd->lex->current_select= current;
 
1329
      session->lex->current_select= current;
1330
1330
      return(RES_ERROR);
1331
1331
    }
1332
1332
 
1333
1333
    // we will refer to upper level cache array => we have to save it in PS
1334
1334
    optimizer->keep_top_level_cache();
1335
1335
 
1336
 
    thd->lex->current_select= current;
 
1336
    session->lex->current_select= current;
1337
1337
    master_unit->uncacheable|= UNCACHEABLE_DEPENDENT;
1338
1338
 
1339
1339
    if (!abort_on_null && left_expr->maybe_null && !pushed_cond_guards)
1340
1340
    {
1341
 
      if (!(pushed_cond_guards= (bool*)join->thd->alloc(sizeof(bool) *
 
1341
      if (!(pushed_cond_guards= (bool*)join->session->alloc(sizeof(bool) *
1342
1342
                                                        left_expr->cols())))
1343
1343
        return(RES_ERROR);
1344
1344
      for (uint32_t i= 0; i < cols_num; i++)
1546
1546
    */
1547
1547
    select_lex->where= join->conds= and_items(join->conds, where_item);
1548
1548
    select_lex->where->top_level_item();
1549
 
    if (join->conds->fix_fields(thd, 0))
 
1549
    if (join->conds->fix_fields(session, 0))
1550
1550
      return(RES_ERROR);
1551
1551
  }
1552
1552
  if (having_item)
1562
1562
      argument (reference) to fix_fields()
1563
1563
    */
1564
1564
    select_lex->having_fix_field= 1;
1565
 
    res= join->having->fix_fields(thd, 0);
 
1565
    res= join->having->fix_fields(session, 0);
1566
1566
    select_lex->having_fix_field= 0;
1567
1567
    if (res)
1568
1568
    {
1605
1605
Item_subselect::trans_res
1606
1606
Item_in_subselect::select_in_like_transformer(JOIN *join, Comp_creator *func)
1607
1607
{
1608
 
  SELECT_LEX *current= thd->lex->current_select, *up;
1609
 
  const char *save_where= thd->where;
 
1608
  SELECT_LEX *current= session->lex->current_select, *up;
 
1609
  const char *save_where= session->where;
1610
1610
  Item_subselect::trans_res res= RES_ERROR;
1611
1611
  bool result;
1612
1612
 
1626
1626
  if (changed)
1627
1627
    return(RES_OK);
1628
1628
 
1629
 
  thd->where= "IN/ALL/ANY subquery";
 
1629
  session->where= "IN/ALL/ANY subquery";
1630
1630
 
1631
1631
  /*
1632
1632
    In some optimisation cases we will not need this Item_in_optimizer
1640
1640
      goto err;
1641
1641
  }
1642
1642
 
1643
 
  thd->lex->current_select= up= current->return_after_parsing();
 
1643
  session->lex->current_select= up= current->return_after_parsing();
1644
1644
  result= (!left_expr->fixed &&
1645
 
           left_expr->fix_fields(thd, optimizer->arguments()));
 
1645
           left_expr->fix_fields(session, optimizer->arguments()));
1646
1646
  /* fix_fields can change reference to left_expr, we need reassign it */
1647
1647
  left_expr= optimizer->arguments()[0];
1648
1648
 
1649
 
  thd->lex->current_select= current;
 
1649
  session->lex->current_select= current;
1650
1650
  if (result)
1651
1651
    goto err;
1652
1652
 
1677
1677
    res= row_value_transformer(join);
1678
1678
  }
1679
1679
err:
1680
 
  thd->where= save_where;
 
1680
  session->where= save_where;
1681
1681
  return(res);
1682
1682
}
1683
1683
 
1695
1695
}
1696
1696
 
1697
1697
 
1698
 
bool Item_in_subselect::fix_fields(Session *thd_arg, Item **ref)
 
1698
bool Item_in_subselect::fix_fields(Session *session_arg, Item **ref)
1699
1699
{
1700
1700
  bool result = 0;
1701
1701
 
1702
1702
  if (exec_method == SEMI_JOIN)
1703
1703
    return !( (*ref)= new Item_int(1));
1704
1704
 
1705
 
  return result || Item_subselect::fix_fields(thd_arg, ref);
 
1705
  return result || Item_subselect::fix_fields(session_arg, ref);
1706
1706
}
1707
1707
 
1708
1708
 
1742
1742
 
1743
1743
    old_engine= (subselect_single_select_engine*) engine;
1744
1744
 
1745
 
    if (!(new_engine= new subselect_hash_sj_engine(thd, this,
 
1745
    if (!(new_engine= new subselect_hash_sj_engine(session, this,
1746
1746
                                                   old_engine)) ||
1747
1747
        new_engine->init_permanent(unit->get_unit_column_types()))
1748
1748
    {
1830
1830
 
1831
1831
  for (uint32_t i= 0; i < left_expr->cols(); i++)
1832
1832
  {
1833
 
    Cached_item *cur_item_cache= new_Cached_item(thd,
 
1833
    Cached_item *cur_item_cache= new_Cached_item(session,
1834
1834
                                                 left_expr->element_index(i),
1835
1835
                                                 use_result_field);
1836
1836
    if (!cur_item_cache || left_expr_cache->push_front(cur_item_cache))
1884
1884
}
1885
1885
 
1886
1886
 
1887
 
void subselect_engine::set_thd(Session *thd_arg)
 
1887
void subselect_engine::set_session(Session *session_arg)
1888
1888
{
1889
 
  thd= thd_arg;
 
1889
  session= session_arg;
1890
1890
  if (result)
1891
 
    result->set_thd(thd_arg);
 
1891
    result->set_session(session_arg);
1892
1892
}
1893
1893
 
1894
1894
 
1997
1997
{
1998
1998
  if (prepared)
1999
1999
    return 0;
2000
 
  join= new JOIN(thd, select_lex->item_list,
 
2000
  join= new JOIN(session, select_lex->item_list,
2001
2001
                 select_lex->options | SELECT_NO_UNLOCK, result);
2002
2002
  if (!join || !result)
2003
2003
    return 1; /* Fatal error is set already. */
2004
2004
  prepared= 1;
2005
 
  SELECT_LEX *save_select= thd->lex->current_select;
2006
 
  thd->lex->current_select= select_lex;
 
2005
  SELECT_LEX *save_select= session->lex->current_select;
 
2006
  session->lex->current_select= select_lex;
2007
2007
  if (join->prepare(&select_lex->ref_pointer_array,
2008
2008
                    (TableList*) select_lex->table_list.first,
2009
2009
                    select_lex->with_wild,
2016
2016
                    (order_st*) 0, select_lex,
2017
2017
                    select_lex->master_unit()))
2018
2018
    return 1;
2019
 
  thd->lex->current_select= save_select;
 
2019
  session->lex->current_select= save_select;
2020
2020
  return 0;
2021
2021
}
2022
2022
 
2023
2023
int subselect_union_engine::prepare()
2024
2024
{
2025
 
  return unit->prepare(thd, result, SELECT_NO_UNLOCK);
 
2025
  return unit->prepare(session, result, SELECT_NO_UNLOCK);
2026
2026
}
2027
2027
 
2028
2028
int subselect_uniquesubquery_engine::prepare()
2118
2118
 
2119
2119
int subselect_single_select_engine::exec()
2120
2120
{
2121
 
  char const *save_where= thd->where;
2122
 
  SELECT_LEX *save_select= thd->lex->current_select;
2123
 
  thd->lex->current_select= select_lex;
 
2121
  char const *save_where= session->where;
 
2122
  SELECT_LEX *save_select= session->lex->current_select;
 
2123
  session->lex->current_select= select_lex;
2124
2124
  if (!join->optimized)
2125
2125
  {
2126
2126
    SELECT_LEX_UNIT *unit= select_lex->master_unit();
2128
2128
    unit->set_limit(unit->global_parameters);
2129
2129
    if (join->flatten_subqueries())
2130
2130
    {
2131
 
      thd->is_fatal_error= true;
 
2131
      session->is_fatal_error= true;
2132
2132
      return(1);
2133
2133
    }
2134
2134
    if (join->optimize())
2135
2135
    {
2136
 
      thd->where= save_where;
 
2136
      session->where= save_where;
2137
2137
      executed= 1;
2138
 
      thd->lex->current_select= save_select;
 
2138
      session->lex->current_select= save_select;
2139
2139
      return(join->error ? join->error : 1);
2140
2140
    }
2141
 
    if (!select_lex->uncacheable && thd->lex->describe && 
 
2141
    if (!select_lex->uncacheable && session->lex->describe && 
2142
2142
        !(join->select_options & SELECT_DESCRIBE) && 
2143
2143
        join->need_tmp && item->const_item())
2144
2144
    {
2164
2164
  {
2165
2165
    if (join->reinit())
2166
2166
    {
2167
 
      thd->where= save_where;
2168
 
      thd->lex->current_select= save_select;
 
2167
      session->where= save_where;
 
2168
      session->lex->current_select= save_select;
2169
2169
      return(1);
2170
2170
    }
2171
2171
    item->reset();
2199
2199
              tab->save_read_record= tab->read_record.read_record;
2200
2200
              tab->read_first_record= init_read_record_seq;
2201
2201
              tab->read_record.record= tab->table->record[0];
2202
 
              tab->read_record.thd= join->thd;
 
2202
              tab->read_record.session= join->session;
2203
2203
              tab->read_record.ref_length= tab->table->file->ref_length;
2204
2204
              *(last_changed_tab++)= tab;
2205
2205
              break;
2221
2221
      tab->read_record.read_record= tab->save_read_record;
2222
2222
    }
2223
2223
    executed= 1;
2224
 
    thd->where= save_where;
2225
 
    thd->lex->current_select= save_select;
2226
 
    return(join->error||thd->is_fatal_error);
 
2224
    session->where= save_where;
 
2225
    session->lex->current_select= save_select;
 
2226
    return(join->error||session->is_fatal_error);
2227
2227
  }
2228
 
  thd->where= save_where;
2229
 
  thd->lex->current_select= save_select;
 
2228
  session->where= save_where;
 
2229
  session->lex->current_select= save_select;
2230
2230
  return(0);
2231
2231
}
2232
2232
 
2233
2233
int subselect_union_engine::exec()
2234
2234
{
2235
 
  char const *save_where= thd->where;
 
2235
  char const *save_where= session->where;
2236
2236
  int res= unit->exec();
2237
 
  thd->where= save_where;
 
2237
  session->where= save_where;
2238
2238
  return res;
2239
2239
}
2240
2240
 
2267
2267
 
2268
2268
  table->file->ha_rnd_init(1);
2269
2269
  table->file->extra_opt(HA_EXTRA_CACHE,
2270
 
                         current_thd->variables.read_buff_size);
 
2270
                         current_session->variables.read_buff_size);
2271
2271
  table->null_row= 0;
2272
2272
  for (;;)
2273
2273
  {
2677
2677
void subselect_single_select_engine::print(String *str,
2678
2678
                                           enum_query_type query_type)
2679
2679
{
2680
 
  select_lex->print(thd, str, query_type);
 
2680
  select_lex->print(session, str, query_type);
2681
2681
}
2682
2682
 
2683
2683
 
2937
2937
  if (!(tmp_result_sink= new select_union))
2938
2938
    return(true);
2939
2939
  if (tmp_result_sink->create_result_table(
2940
 
                         thd, tmp_columns, true,
2941
 
                         thd->options | TMP_TABLE_ALL_COLUMNS,
 
2940
                         session, tmp_columns, true,
 
2941
                         session->options | TMP_TABLE_ALL_COLUMNS,
2942
2942
                         "materialized subselect", true))
2943
2943
    return(true);
2944
2944
 
2960
2960
      tmp_table->s->uniques ||
2961
2961
      tmp_table->key_info->key_length >= tmp_table->file->max_key_length() ||
2962
2962
      tmp_table->key_info->key_parts > tmp_table->file->max_key_parts());
2963
 
    tmp_table->free_tmp_table(thd);
 
2963
    tmp_table->free_tmp_table(session);
2964
2964
    delete result;
2965
2965
    result= NULL;
2966
2966
    return(true);
2983
2983
    - here we initialize only those members that are used by
2984
2984
      subselect_uniquesubquery_engine, so these objects are incomplete.
2985
2985
  */ 
2986
 
  if (!(tab= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB))))
 
2986
  if (!(tab= (JOIN_TAB*) session->alloc(sizeof(JOIN_TAB))))
2987
2987
    return(true);
2988
2988
  tab->table= tmp_table;
2989
2989
  tab->ref.key= 0; /* The only temp table index. */
2990
2990
  tab->ref.key_length= tmp_key->key_length;
2991
2991
  if (!(tab->ref.key_buff=
2992
 
        (unsigned char*) thd->calloc(ALIGN_SIZE(tmp_key->key_length) * 2)) ||
 
2992
        (unsigned char*) session->calloc(ALIGN_SIZE(tmp_key->key_length) * 2)) ||
2993
2993
      !(tab->ref.key_copy=
2994
 
        (store_key**) thd->alloc((sizeof(store_key*) *
 
2994
        (store_key**) session->alloc((sizeof(store_key*) *
2995
2995
                                  (tmp_key_parts + 1)))) ||
2996
2996
      !(tab->ref.items=
2997
 
        (Item**) thd->alloc(sizeof(Item*) * tmp_key_parts)))
 
2997
        (Item**) session->alloc(sizeof(Item*) * tmp_key_parts)))
2998
2998
    return(true);
2999
2999
 
3000
3000
  KEY_PART_INFO *cur_key_part= tmp_key->key_part;
3005
3005
  {
3006
3006
    tab->ref.items[i]= item_in->left_expr->element_index(i);
3007
3007
    int null_count= test(cur_key_part->field->real_maybe_null());
3008
 
    *ref_key= new store_key_item(thd, cur_key_part->field,
 
3008
    *ref_key= new store_key_item(session, cur_key_part->field,
3009
3009
                                 /* TODO:
3010
3010
                                    the NULL byte is taken into account in
3011
3011
                                    cur_key_part->store_length, so instead of
3051
3051
{
3052
3052
  delete result;
3053
3053
  if (tab)
3054
 
    tab->table->free_tmp_table(thd);
 
3054
    tab->table->free_tmp_table(session);
3055
3055
}
3056
3056
 
3057
3057
 
3093
3093
  if (!is_materialized)
3094
3094
  {
3095
3095
    int res= 0;
3096
 
    SELECT_LEX *save_select= thd->lex->current_select;
3097
 
    thd->lex->current_select= materialize_engine->select_lex;
 
3096
    SELECT_LEX *save_select= session->lex->current_select;
 
3097
    session->lex->current_select= materialize_engine->select_lex;
3098
3098
    if ((res= materialize_join->optimize()))
3099
3099
      goto err;
3100
3100
    materialize_join->exec();
3101
 
    if ((res= test(materialize_join->error || thd->is_fatal_error)))
 
3101
    if ((res= test(materialize_join->error || session->is_fatal_error)))
3102
3102
      goto err;
3103
3103
 
3104
3104
    /*
3131
3131
      tmp_param= NULL;
3132
3132
 
3133
3133
err:
3134
 
    thd->lex->current_select= save_select;
 
3134
    session->lex->current_select= save_select;
3135
3135
    if (res)
3136
3136
      return(res);
3137
3137
  }