~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/subselect.cc

Merge Monty - Added inter-plugin dependencies for controlling plugin load order

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    - add function from select_query that use JOIN* as parameter to JOIN
24
24
    methods (sql_select.h/sql_select.cc)
25
25
*/
26
 
#include <config.h>
 
26
#include "config.h"
27
27
 
28
28
#include <cstdio>
29
29
#include <limits.h>
30
30
 
31
 
#include <drizzled/session.h>
32
31
#include <drizzled/sql_select.h>
33
32
#include <drizzled/error.h>
34
33
#include <drizzled/item/cache.h>
40
39
#include <drizzled/item/ref_null_helper.h>
41
40
#include <drizzled/item/direct_ref.h>
42
41
#include <drizzled/join.h>
43
 
#include <drizzled/plugin/storage_engine.h>
44
 
#include <drizzled/select_singlerow_subselect.h>
45
 
#include <drizzled/select_max_min_finder_subselect.h>
46
 
#include <drizzled/select_exists_subselect.h>
47
 
#include <drizzled/select_union.h>
48
 
#include <drizzled/sql_lex.h>
49
 
#include <drizzled/system_variables.h>
50
42
 
51
 
namespace drizzled {
 
43
namespace drizzled
 
44
{
52
45
 
53
46
extern plugin::StorageEngine *myisam_engine;
54
47
 
187
180
 
188
181
bool Item_subselect::fix_fields(Session *session_param, Item **ref)
189
182
{
190
 
  char const *save_where= session_param->where();
 
183
  char const *save_where= session_param->where;
191
184
  bool res;
192
185
 
193
186
  assert(fixed == 0);
230
223
        engine->exclude();
231
224
      }
232
225
      substitution= 0;
233
 
      session->setWhere("checking transformed subquery");
 
226
      session->where= "checking transformed subquery";
234
227
      if (! (*ref)->fixed)
235
228
      {
236
229
        ret= (*ref)->fix_fields(session, ref);
237
230
      }
238
 
      session->setWhere(save_where);
239
 
 
 
231
      session->where= save_where;
240
232
      return ret;
241
233
    }
242
234
    // Is it one field subselect?
261
253
  fixed= 1;
262
254
 
263
255
err:
264
 
  session->setWhere(save_where);
 
256
  session->where= save_where;
265
257
  return res;
266
258
}
267
259
 
274
266
  {
275
267
    for (Select_Lex *lex= unit->first_select(); lex; lex= lex->next_select())
276
268
    {
277
 
      List<Item>::iterator li(lex->item_list.begin());
 
269
      List_iterator<Item> li(lex->item_list);
278
270
      Item *item;
279
271
      Order *order;
280
272
 
407
399
}
408
400
 
409
401
 
410
 
void Item_subselect::print(String *str)
 
402
void Item_subselect::print(String *str, enum_query_type query_type)
411
403
{
412
404
  str->append('(');
413
 
  engine->print(str);
 
405
  engine->print(str, query_type);
414
406
  str->append(')');
415
407
}
416
408
 
488
480
}
489
481
 
490
482
 
491
 
void Item_maxmin_subselect::print(String *str)
 
483
void Item_maxmin_subselect::print(String *str, enum_query_type query_type)
492
484
{
493
485
  str->append(max?"<max>":"<min>", 5);
494
 
  Item_singlerow_subselect::print(str);
 
486
  Item_singlerow_subselect::print(str, query_type);
495
487
}
496
488
 
497
489
 
523
515
 
524
516
  if (!select_lex->master_unit()->is_union() &&
525
517
      !select_lex->table_list.elements &&
526
 
      select_lex->item_list.size() == 1 &&
527
 
      !select_lex->item_list.front().with_sum_func &&
 
518
      select_lex->item_list.elements == 1 &&
 
519
      !select_lex->item_list.head()->with_sum_func &&
528
520
      /*
529
521
        We cant change name of Item_field or Item_ref, because it will
530
522
        prevent it's correct resolving, but we should save name of
532
524
        list is field or reference.
533
525
        TODO: solve above problem
534
526
      */
535
 
      !(select_lex->item_list.front().type() == FIELD_ITEM ||
536
 
        select_lex->item_list.front().type() == REF_ITEM) &&
 
527
      !(select_lex->item_list.head()->type() == FIELD_ITEM ||
 
528
        select_lex->item_list.head()->type() == REF_ITEM) &&
537
529
      !join->conds && !join->having
538
530
      )
539
531
  {
540
532
 
541
533
    have_to_be_excluded= 1;
542
 
    if (session->lex().describe)
 
534
    if (session->lex->describe)
543
535
    {
544
536
      char warn_buff[DRIZZLE_ERRMSG_SIZE];
545
537
      snprintf(warn_buff, sizeof(warn_buff), ER(ER_SELECT_REDUCED), select_lex->select_number);
546
538
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
547
539
                   ER_SELECT_REDUCED, warn_buff);
548
540
    }
549
 
    substitution= &select_lex->item_list.front();
 
541
    substitution= select_lex->item_list.head();
550
542
    /*
551
543
      as far as we moved content to upper level, field which depend of
552
544
      'upper' select is not really dependent => we remove this dependence
719
711
}
720
712
 
721
713
 
722
 
void Item_exists_subselect::print(String *str)
 
714
void Item_exists_subselect::print(String *str, enum_query_type query_type)
723
715
{
724
716
  str->append(STRING_WITH_LEN("exists"));
725
 
  Item_subselect::print(str);
 
717
  Item_subselect::print(str, query_type);
726
718
}
727
719
 
728
720
 
1003
995
    Check that the right part of the subselect contains no more than one
1004
996
    column. E.g. in SELECT 1 IN (SELECT * ..) the right part is (SELECT * ...)
1005
997
  */
1006
 
  if (select_lex->item_list.size() > 1)
 
998
  if (select_lex->item_list.elements > 1)
1007
999
  {
1008
1000
    my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
1009
1001
    return(RES_ERROR);
1058
1050
        upper_item->set_sum_test(item);
1059
1051
      *select_lex->ref_pointer_array= item;
1060
1052
      {
1061
 
        List<Item>::iterator it(select_lex->item_list.begin());
 
1053
        List_iterator<Item> it(select_lex->item_list);
1062
1054
        it++;
1063
1055
        it.replace(item);
1064
1056
      }
1065
1057
 
1066
 
      save_allow_sum_func= session->lex().allow_sum_func;
1067
 
      session->lex().allow_sum_func|= 1 << session->lex().current_select->nest_level;
 
1058
      save_allow_sum_func= session->lex->allow_sum_func;
 
1059
      session->lex->allow_sum_func|= 1 << session->lex->current_select->nest_level;
1068
1060
      /*
1069
1061
        Item_sum_(max|min) can't substitute other item => we can use 0 as
1070
1062
        reference, also Item_sum_(max|min) can't be fixed after creation, so
1072
1064
      */
1073
1065
      if (item->fix_fields(session, 0))
1074
1066
        return(RES_ERROR);
1075
 
      session->lex().allow_sum_func= save_allow_sum_func;
 
1067
      session->lex->allow_sum_func= save_allow_sum_func;
1076
1068
      /* we added aggregate function => we have to change statistic */
1077
1069
      count_field_types(select_lex, &join->tmp_table_param, join->all_fields,
1078
1070
                        0);
1097
1089
    Select_Lex_Unit *master_unit= select_lex->master_unit();
1098
1090
    substitution= optimizer;
1099
1091
 
1100
 
    Select_Lex *current= session->lex().current_select, *up;
 
1092
    Select_Lex *current= session->lex->current_select, *up;
1101
1093
 
1102
 
    session->lex().current_select= up= current->return_after_parsing();
 
1094
    session->lex->current_select= up= current->return_after_parsing();
1103
1095
    //optimizer never use Item **ref => we can pass 0 as parameter
1104
1096
    if (!optimizer || optimizer->fix_left(session, 0))
1105
1097
    {
1106
 
      session->lex().current_select= current;
 
1098
      session->lex->current_select= current;
1107
1099
      return(RES_ERROR);
1108
1100
    }
1109
 
    session->lex().current_select= current;
 
1101
    session->lex->current_select= current;
1110
1102
 
1111
1103
    /*
1112
1104
      As far as  Item_ref_in_optimizer do not substitute itself on fix_fields
1122
1114
 
1123
1115
  if (!abort_on_null && left_expr->maybe_null && !pushed_cond_guards)
1124
1116
  {
1125
 
    if (!(pushed_cond_guards= (bool*)join->session->getMemRoot()->allocate(sizeof(bool))))
 
1117
    if (!(pushed_cond_guards= (bool*)join->session->alloc(sizeof(bool))))
1126
1118
      return(RES_ERROR);
1127
1119
    pushed_cond_guards[0]= true;
1128
1120
  }
1209
1201
    select_lex->having= join->having= and_items(join->having, item);
1210
1202
    if (join->having == item)
1211
1203
      item->name= (char*)in_having_cond;
1212
 
    select_lex->having->top_level_item();
1213
1204
    select_lex->having_fix_field= 1;
1214
1205
    /*
1215
1206
      we do not check join->having->fixed, because Item_and (from and_items)
1222
1213
  }
1223
1214
  else
1224
1215
  {
1225
 
    Item *item= &select_lex->item_list.front();
 
1216
    Item *item= (Item*) select_lex->item_list.head();
1226
1217
 
1227
1218
    if (select_lex->table_list.elements)
1228
1219
    {
1229
1220
      bool tmp;
1230
1221
      Item *having= item, *orig_item= item;
1231
 
      select_lex->item_list.clear();
 
1222
      select_lex->item_list.empty();
1232
1223
      select_lex->item_list.push_back(new Item_int("Not_used",
1233
1224
                                                   (int64_t) 1,
1234
1225
                                                   MY_INT64_NUM_DECIMAL_DIGITS));
1235
 
      select_lex->ref_pointer_array[0]= &select_lex->item_list.front();
 
1226
      select_lex->ref_pointer_array[0]= select_lex->item_list.head();
1236
1227
 
1237
1228
      item= func->create(expr, item);
1238
1229
      if (!abort_on_null && orig_item->maybe_null)
1336
1327
        // fix_field of item will be done in time of substituting
1337
1328
        substitution= item;
1338
1329
        have_to_be_excluded= 1;
1339
 
        if (session->lex().describe)
 
1330
        if (session->lex->describe)
1340
1331
        {
1341
1332
          char warn_buff[DRIZZLE_ERRMSG_SIZE];
1342
1333
          snprintf(warn_buff, sizeof(warn_buff), ER(ER_SELECT_REDUCED), select_lex->select_number);
1358
1349
  Select_Lex *select_lex= join->select_lex;
1359
1350
  uint32_t cols_num= left_expr->cols();
1360
1351
 
1361
 
  if (select_lex->item_list.size() != left_expr->cols())
 
1352
  if (select_lex->item_list.elements != left_expr->cols())
1362
1353
  {
1363
1354
    my_error(ER_OPERAND_COLUMNS, MYF(0), left_expr->cols());
1364
1355
    return(RES_ERROR);
1374
1365
    Select_Lex_Unit *master_unit= select_lex->master_unit();
1375
1366
    substitution= optimizer;
1376
1367
 
1377
 
    Select_Lex *current= session->lex().current_select, *up;
1378
 
    session->lex().current_select= up= current->return_after_parsing();
 
1368
    Select_Lex *current= session->lex->current_select, *up;
 
1369
    session->lex->current_select= up= current->return_after_parsing();
1379
1370
    //optimizer never use Item **ref => we can pass 0 as parameter
1380
1371
    if (!optimizer || optimizer->fix_left(session, 0))
1381
1372
    {
1382
 
      session->lex().current_select= current;
 
1373
      session->lex->current_select= current;
1383
1374
      return(RES_ERROR);
1384
1375
    }
1385
1376
 
1386
1377
    // we will refer to upper level cache array => we have to save it in PS
1387
1378
    optimizer->keep_top_level_cache();
1388
1379
 
1389
 
    session->lex().current_select= current;
 
1380
    session->lex->current_select= current;
1390
1381
    master_unit->uncacheable.set(UNCACHEABLE_DEPENDENT);
1391
1382
 
1392
1383
    if (!abort_on_null && left_expr->maybe_null && !pushed_cond_guards)
1393
1384
    {
1394
 
      if (!(pushed_cond_guards= (bool*)join->session->getMemRoot()->allocate(sizeof(bool) *
 
1385
      if (!(pushed_cond_guards= (bool*)join->session->alloc(sizeof(bool) *
1395
1386
                                                        left_expr->cols())))
1396
1387
        return(RES_ERROR);
1397
1388
      for (uint32_t i= 0; i < cols_num; i++)
1658
1649
Item_subselect::trans_res
1659
1650
Item_in_subselect::select_in_like_transformer(Join *join, const Comp_creator *func)
1660
1651
{
1661
 
  Select_Lex *current= session->lex().current_select, *up;
1662
 
  const char *save_where= session->where();
 
1652
  Select_Lex *current= session->lex->current_select, *up;
 
1653
  const char *save_where= session->where;
1663
1654
  Item_subselect::trans_res res= RES_ERROR;
1664
1655
  bool result;
1665
1656
 
1679
1670
  if (changed)
1680
1671
    return(RES_OK);
1681
1672
 
1682
 
  session->setWhere("IN/ALL/ANY subquery");
 
1673
  session->where= "IN/ALL/ANY subquery";
1683
1674
 
1684
1675
  /*
1685
1676
    In some optimisation cases we will not need this Item_in_optimizer
1693
1684
      goto err;
1694
1685
  }
1695
1686
 
1696
 
  session->lex().current_select= up= current->return_after_parsing();
 
1687
  session->lex->current_select= up= current->return_after_parsing();
1697
1688
  result= (!left_expr->fixed &&
1698
1689
           left_expr->fix_fields(session, optimizer->arguments()));
1699
1690
  /* fix_fields can change reference to left_expr, we need reassign it */
1700
1691
  left_expr= optimizer->arguments()[0];
1701
1692
 
1702
 
  session->lex().current_select= current;
 
1693
  session->lex->current_select= current;
1703
1694
  if (result)
1704
1695
    goto err;
1705
1696
 
1730
1721
    res= row_value_transformer(join);
1731
1722
  }
1732
1723
err:
1733
 
  session->setWhere(save_where);
 
1724
  session->where= save_where;
1734
1725
  return(res);
1735
1726
}
1736
1727
 
1737
1728
 
1738
 
void Item_in_subselect::print(String *str)
 
1729
void Item_in_subselect::print(String *str, enum_query_type query_type)
1739
1730
{
1740
1731
  if (exec_method == IN_TO_EXISTS)
1741
1732
    str->append(STRING_WITH_LEN("<exists>"));
1742
1733
  else
1743
1734
  {
1744
 
    left_expr->print(str);
 
1735
    left_expr->print(str, query_type);
1745
1736
    str->append(STRING_WITH_LEN(" in "));
1746
1737
  }
1747
 
  Item_subselect::print(str);
 
1738
  Item_subselect::print(str, query_type);
1748
1739
}
1749
1740
 
1750
1741
 
1871
1862
  for (uint32_t i= 0; i < left_expr->cols(); i++)
1872
1863
  {
1873
1864
    Cached_item *cur_item_cache= new_Cached_item(session, left_expr->element_index(i));
1874
 
    if (!cur_item_cache)
 
1865
    if (!cur_item_cache || left_expr_cache->push_front(cur_item_cache))
1875
1866
      return true;
1876
 
                left_expr_cache->push_front(cur_item_cache);
1877
1867
  }
1878
1868
  return false;
1879
1869
}
1908
1898
}
1909
1899
 
1910
1900
 
1911
 
void Item_allany_subselect::print(String *str)
 
1901
void Item_allany_subselect::print(String *str, enum_query_type query_type)
1912
1902
{
1913
1903
  if (exec_method == IN_TO_EXISTS)
1914
1904
    str->append(STRING_WITH_LEN("<exists>"));
1915
1905
  else
1916
1906
  {
1917
 
    left_expr->print(str);
 
1907
    left_expr->print(str, query_type);
1918
1908
    str->append(' ');
1919
1909
    str->append(func->symbol(all));
1920
1910
    str->append(all ? " all " : " any ", 5);
1921
1911
  }
1922
 
  Item_subselect::print(str);
 
1912
  Item_subselect::print(str, query_type);
1923
1913
}
1924
1914
 
1925
1915
 
2041
2031
  if (!join || !result)
2042
2032
    return 1; /* Fatal error is set already. */
2043
2033
  prepared= 1;
2044
 
  Select_Lex *save_select= session->lex().current_select;
2045
 
  session->lex().current_select= select_lex;
 
2034
  Select_Lex *save_select= session->lex->current_select;
 
2035
  session->lex->current_select= select_lex;
2046
2036
  if (join->prepare(&select_lex->ref_pointer_array,
2047
2037
                    (TableList*) select_lex->table_list.first,
2048
2038
                    select_lex->with_wild,
2054
2044
                    select_lex->having,
2055
2045
                    select_lex, select_lex->master_unit()))
2056
2046
    return 1;
2057
 
  session->lex().current_select= save_select;
 
2047
  session->lex->current_select= save_select;
2058
2048
  return 0;
2059
2049
}
2060
2050
 
2099
2089
void subselect_engine::set_row(List<Item> &item_list, Item_cache **row)
2100
2090
{
2101
2091
  Item *sel_item;
2102
 
  List<Item>::iterator li(item_list.begin());
 
2092
  List_iterator_fast<Item> li(item_list);
2103
2093
  res_type= STRING_RESULT;
2104
2094
  res_field_type= DRIZZLE_TYPE_VARCHAR;
2105
2095
  for (uint32_t i= 0; (sel_item= li++); i++)
2114
2104
      return;
2115
2105
    row[i]->setup(sel_item);
2116
2106
  }
2117
 
  if (item_list.size() > 1)
 
2107
  if (item_list.elements > 1)
2118
2108
    res_type= ROW_RESULT;
2119
2109
}
2120
2110
 
2121
2111
void subselect_single_select_engine::fix_length_and_dec(Item_cache **row)
2122
2112
{
2123
 
  assert(row || select_lex->item_list.size() == 1);
 
2113
  assert(row || select_lex->item_list.elements==1);
2124
2114
  set_row(select_lex->item_list, row);
2125
2115
  item->collation.set(row[0]->collation);
2126
2116
  if (cols() != 1)
2129
2119
 
2130
2120
void subselect_union_engine::fix_length_and_dec(Item_cache **row)
2131
2121
{
2132
 
  assert(row || unit->first_select()->item_list.size() == 1);
 
2122
  assert(row || unit->first_select()->item_list.elements==1);
2133
2123
 
2134
 
  if (unit->first_select()->item_list.size() == 1)
 
2124
  if (unit->first_select()->item_list.elements == 1)
2135
2125
  {
2136
2126
    set_row(unit->types, row);
2137
2127
    item->collation.set(row[0]->collation);
2152
2142
 
2153
2143
int subselect_single_select_engine::exec()
2154
2144
{
2155
 
  char const *save_where= session->where();
2156
 
  Select_Lex *save_select= session->lex().current_select;
2157
 
  session->lex().current_select= select_lex;
 
2145
  char const *save_where= session->where;
 
2146
  Select_Lex *save_select= session->lex->current_select;
 
2147
  session->lex->current_select= select_lex;
2158
2148
  if (!join->optimized)
2159
2149
  {
2160
2150
    Select_Lex_Unit *unit= select_lex->master_unit();
2162
2152
    unit->set_limit(unit->global_parameters);
2163
2153
    if (join->optimize())
2164
2154
    {
2165
 
      session->setWhere(save_where);
 
2155
      session->where= save_where;
2166
2156
      executed= 1;
2167
 
      session->lex().current_select= save_select;
 
2157
      session->lex->current_select= save_select;
2168
2158
      return(join->error ? join->error : 1);
2169
2159
    }
2170
2160
    if (save_join_if_explain())
2181
2171
  {
2182
2172
    if (join->reinit())
2183
2173
    {
2184
 
      session->setWhere(save_where);
2185
 
      session->lex().current_select= save_select;
 
2174
      session->where= save_where;
 
2175
      session->lex->current_select= save_select;
2186
2176
      return 1;
2187
2177
    }
2188
2178
    item->reset();
2240
2230
      tab->read_record.read_record= tab->save_read_record;
2241
2231
    }
2242
2232
    executed= 1;
2243
 
    session->setWhere(save_where);
2244
 
    session->lex().current_select= save_select;
 
2233
    session->where= save_where;
 
2234
    session->lex->current_select= save_select;
2245
2235
    return(join->error||session->is_fatal_error);
2246
2236
  }
2247
 
  session->setWhere(save_where);
2248
 
  session->lex().current_select= save_select;
 
2237
  session->where= save_where;
 
2238
  session->lex->current_select= save_select;
2249
2239
  return(0);
2250
2240
}
2251
2241
 
2265
2255
        make a replacement JOIN by calling make_simple_join(). 
2266
2256
     5) The Item_subselect is cacheable
2267
2257
  */
2268
 
  if (session->lex().describe &&                          // 1
 
2258
  if (session->lex->describe &&                          // 1
2269
2259
      select_lex->uncacheable.none() &&                  // 2
2270
2260
      !(join->select_options & SELECT_DESCRIBE) &&       // 3
2271
2261
      join->need_tmp &&                                  // 4
2289
2279
 
2290
2280
int subselect_union_engine::exec()
2291
2281
{
2292
 
  char const *save_where= session->where();
 
2282
  char const *save_where= session->where;
2293
2283
  int res= unit->exec();
2294
 
  session->setWhere(save_where);
2295
 
 
 
2284
  session->where= save_where;
2296
2285
  return res;
2297
2286
}
2298
2287
 
2329
2318
    return 1;
2330
2319
  }
2331
2320
 
2332
 
  assert(table->getSession());
2333
2321
  table->cursor->extra_opt(HA_EXTRA_CACHE,
2334
 
                           table->getSession()->variables.read_buff_size);
 
2322
                           current_session->variables.read_buff_size);
2335
2323
  table->null_row= 0;
2336
2324
  for (;;)
2337
2325
  {
2688
2676
 
2689
2677
uint32_t subselect_single_select_engine::cols()
2690
2678
{
2691
 
  return select_lex->item_list.size();
 
2679
  return select_lex->item_list.elements;
2692
2680
}
2693
2681
 
2694
2682
 
2695
2683
uint32_t subselect_union_engine::cols()
2696
2684
{
2697
 
  return unit->types.size();
 
2685
  return unit->types.elements;
2698
2686
}
2699
2687
 
2700
2688
 
2766
2754
}
2767
2755
 
2768
2756
 
2769
 
void subselect_single_select_engine::print(String *str)
2770
 
{
2771
 
  select_lex->print(session, str);
2772
 
}
2773
 
 
2774
 
 
2775
 
void subselect_union_engine::print(String *str)
2776
 
{
2777
 
  unit->print(str);
2778
 
}
2779
 
 
2780
 
 
2781
 
void subselect_uniquesubquery_engine::print(String *str)
2782
 
{
2783
 
  const char *table_name= tab->table->getShare()->getTableName();
 
2757
void subselect_single_select_engine::print(String *str,
 
2758
                                           enum_query_type query_type)
 
2759
{
 
2760
  select_lex->print(session, str, query_type);
 
2761
}
 
2762
 
 
2763
 
 
2764
void subselect_union_engine::print(String *str, enum_query_type query_type)
 
2765
{
 
2766
  unit->print(str, query_type);
 
2767
}
 
2768
 
 
2769
 
 
2770
void subselect_uniquesubquery_engine::print(String *str,
 
2771
                                            enum_query_type query_type)
 
2772
{
 
2773
  char *table_name= const_cast<char *>(tab->table->getShare()->getTableName());
2784
2774
  str->append(STRING_WITH_LEN("<primary_index_lookup>("));
2785
 
  tab->ref.items[0]->print(str);
 
2775
  tab->ref.items[0]->print(str, query_type);
2786
2776
  str->append(STRING_WITH_LEN(" in "));
2787
2777
  if (tab->table->getShare()->isTemporaryCategory())
2788
2778
  {
2800
2790
  if (cond)
2801
2791
  {
2802
2792
    str->append(STRING_WITH_LEN(" where "));
2803
 
    cond->print(str);
 
2793
    cond->print(str, query_type);
2804
2794
  }
2805
2795
  str->append(')');
2806
2796
}
2829
2819
}
2830
2820
*/
2831
2821
 
2832
 
void subselect_indexsubquery_engine::print(String *str)
 
2822
void subselect_indexsubquery_engine::print(String *str,
 
2823
                                           enum_query_type query_type)
2833
2824
{
2834
2825
  str->append(STRING_WITH_LEN("<index_lookup>("));
2835
 
  tab->ref.items[0]->print(str);
 
2826
  tab->ref.items[0]->print(str, query_type);
2836
2827
  str->append(STRING_WITH_LEN(" in "));
2837
2828
  str->append(tab->table->getShare()->getTableName(), tab->table->getShare()->getTableNameSize());
2838
2829
  KeyInfo *key_info= tab->table->key_info+ tab->ref.key;
2843
2834
  if (cond)
2844
2835
  {
2845
2836
    str->append(STRING_WITH_LEN(" where "));
2846
 
    cond->print(str);
 
2837
    cond->print(str, query_type);
2847
2838
  }
2848
2839
  if (having)
2849
2840
  {
2850
2841
    str->append(STRING_WITH_LEN(" having "));
2851
 
    having->print(str);
 
2842
    having->print(str, query_type);
2852
2843
  }
2853
2844
  str->append(')');
2854
2845
}
3061
3052
    Make sure there is only one index on the temp table, and it doesn't have
3062
3053
    the extra key part created when s->uniques > 0.
3063
3054
  */
3064
 
  assert(tmp_table->getShare()->sizeKeys() == 1 && tmp_columns->size() == tmp_key_parts);
 
3055
  assert(tmp_table->getShare()->sizeKeys() == 1 && tmp_columns->elements == tmp_key_parts);
3065
3056
 
3066
3057
 
3067
3058
  /* 2. Create/initialize execution related objects. */
3073
3064
    - here we initialize only those members that are used by
3074
3065
      subselect_uniquesubquery_engine, so these objects are incomplete.
3075
3066
  */
3076
 
  if (!(tab= (JoinTable*) session->getMemRoot()->allocate(sizeof(JoinTable))))
 
3067
  if (!(tab= (JoinTable*) session->alloc(sizeof(JoinTable))))
3077
3068
    return(true);
3078
3069
  new (tab) JoinTable();
3079
3070
  tab->table= tmp_table;
3082
3073
  if (!(tab->ref.key_buff=
3083
3074
        (unsigned char*) session->calloc(ALIGN_SIZE(tmp_key->key_length) * 2)) ||
3084
3075
      !(tab->ref.key_copy=
3085
 
        (StoredKey**) session->getMemRoot()->allocate((sizeof(StoredKey*) *
 
3076
        (StoredKey**) session->alloc((sizeof(StoredKey*) *
3086
3077
                                  (tmp_key_parts + 1)))) ||
3087
3078
      !(tab->ref.items=
3088
 
        (Item**) session->getMemRoot()->allocate(sizeof(Item*) * tmp_key_parts)))
 
3079
        (Item**) session->alloc(sizeof(Item*) * tmp_key_parts)))
3089
3080
    return(true);
3090
3081
 
3091
3082
  KeyPartInfo *cur_key_part= tmp_key->key_part;
3186
3177
  if (!is_materialized)
3187
3178
  {
3188
3179
    int res= 0;
3189
 
    Select_Lex *save_select= session->lex().current_select;
3190
 
    session->lex().current_select= materialize_engine->select_lex;
 
3180
    Select_Lex *save_select= session->lex->current_select;
 
3181
    session->lex->current_select= materialize_engine->select_lex;
3191
3182
    if ((res= materialize_join->optimize()))
3192
3183
      goto err;
3193
3184
 
3228
3219
      tmp_param= NULL;
3229
3220
 
3230
3221
err:
3231
 
    session->lex().current_select= save_select;
 
3222
    session->lex->current_select= save_select;
3232
3223
    if (res)
3233
3224
      return(res);
3234
3225
  }
3244
3235
  Print the state of this engine into a string for debugging and views.
3245
3236
*/
3246
3237
 
3247
 
void subselect_hash_sj_engine::print(String *str)
 
3238
void subselect_hash_sj_engine::print(String *str, enum_query_type query_type)
3248
3239
{
3249
3240
  str->append(STRING_WITH_LEN(" <materialize> ("));
3250
 
  materialize_engine->print(str);
 
3241
  materialize_engine->print(str, query_type);
3251
3242
  str->append(STRING_WITH_LEN(" ), "));
3252
3243
  if (tab)
3253
 
    subselect_uniquesubquery_engine::print(str);
 
3244
    subselect_uniquesubquery_engine::print(str, query_type);
3254
3245
  else
3255
3246
    str->append(STRING_WITH_LEN(
3256
3247
           "<the access method for lookups is not yet created>"