~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/join.cc

  • Committer: Brian Aker
  • Date: 2010-11-26 22:40:33 UTC
  • mto: This revision was merged to the branch mainline in revision 1958.
  • Revision ID: brian@tangent.org-20101126224033-yt9a3o82w2rhaihp
Adding select for update test with flush locks engaged.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008-2009 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
27
27
 * @{
28
28
 */
29
29
 
30
 
#include <config.h>
 
30
#include "config.h"
31
31
 
32
32
#include <float.h>
33
33
#include <math.h>
34
34
 
35
 
#include <drizzled/item/cache.h>
36
 
#include <drizzled/item/cmpfunc.h>
37
 
#include <drizzled/item/copy_string.h>
38
 
#include <drizzled/item/uint.h>
39
 
#include <drizzled/cached_item.h>
40
 
#include <drizzled/sql_base.h>
41
 
#include <drizzled/sql_select.h> /* include join.h */
42
 
#include <drizzled/lock.h>
43
 
#include <drizzled/nested_join.h>
44
 
#include <drizzled/join.h>
45
 
#include <drizzled/join_cache.h>
46
 
#include <drizzled/show.h>
47
 
#include <drizzled/field/blob.h>
48
 
#include <drizzled/optimizer/position.h>
49
 
#include <drizzled/optimizer/sargable_param.h>
50
 
#include <drizzled/optimizer/key_use.h>
51
 
#include <drizzled/optimizer/range.h>
52
 
#include <drizzled/optimizer/sum.h>
53
 
#include <drizzled/optimizer/explain_plan.h>
54
 
#include <drizzled/optimizer/access_method_factory.h>
55
 
#include <drizzled/optimizer/access_method.h>
56
 
#include <drizzled/records.h>
57
 
#include <drizzled/probes.h>
58
 
#include <drizzled/internal/my_bit.h>
59
 
#include <drizzled/internal/my_sys.h>
60
 
#include <drizzled/internal/iocache.h>
61
 
#include <drizzled/plugin/storage_engine.h>
62
 
#include <drizzled/session.h>
63
 
#include <drizzled/select_result.h>
64
 
 
65
 
#include <drizzled/debug.h>
 
35
#include "drizzled/item/cache.h"
 
36
#include "drizzled/item/cmpfunc.h"
 
37
#include "drizzled/item/copy_string.h"
 
38
#include "drizzled/item/uint.h"
 
39
#include "drizzled/cached_item.h"
 
40
#include "drizzled/sql_base.h"
 
41
#include "drizzled/sql_select.h" /* include join.h */
 
42
#include "drizzled/lock.h"
 
43
#include "drizzled/nested_join.h"
 
44
#include "drizzled/join.h"
 
45
#include "drizzled/join_cache.h"
 
46
#include "drizzled/show.h"
 
47
#include "drizzled/field/blob.h"
 
48
#include "drizzled/optimizer/position.h"
 
49
#include "drizzled/optimizer/sargable_param.h"
 
50
#include "drizzled/optimizer/key_use.h"
 
51
#include "drizzled/optimizer/range.h"
 
52
#include "drizzled/optimizer/sum.h"
 
53
#include "drizzled/optimizer/explain_plan.h"
 
54
#include "drizzled/optimizer/access_method_factory.h"
 
55
#include "drizzled/optimizer/access_method.h"
 
56
#include "drizzled/records.h"
 
57
#include "drizzled/probes.h"
 
58
#include "drizzled/internal/my_bit.h"
 
59
#include "drizzled/internal/my_sys.h"
 
60
#include "drizzled/internal/iocache.h"
66
61
 
67
62
#include <algorithm>
68
63
 
70
65
 
71
66
namespace drizzled
72
67
{
 
68
 
73
69
extern plugin::StorageEngine *heap_engine;
 
70
extern std::bitset<12> test_flags;
74
71
 
75
72
/** Declarations of static functions used in this source file. */
76
73
static bool make_group_fields(Join *main_join, Join *curr_join);
136
133
static bool add_ref_to_table_cond(Session *session, JoinTable *join_tab);
137
134
static void free_blobs(Field **ptr); /* Rename this method...conflicts with another in global namespace... */
138
135
 
139
 
Join::Join(Session *session_arg, 
140
 
           List<Item> &fields_arg, 
141
 
           uint64_t select_options_arg,
142
 
           select_result *result_arg) :
143
 
  join_tab(NULL),
144
 
  best_ref(NULL),
145
 
  map2table(NULL),
146
 
  join_tab_save(NULL),
147
 
  table(NULL),
148
 
  all_tables(NULL),
149
 
  sort_by_table(NULL),
150
 
  tables(0),
151
 
  outer_tables(0),
152
 
  const_tables(0),
153
 
  send_group_parts(0),
154
 
  sort_and_group(false),
155
 
  first_record(false),
156
 
  full_join(false),
157
 
  group(false),
158
 
  no_field_update(false),
159
 
  do_send_rows(true),
160
 
  resume_nested_loop(false),
161
 
  no_const_tables(false),
162
 
  select_distinct(false),
163
 
  group_optimized_away(false),
164
 
  simple_order(false),
165
 
  simple_group(false),
166
 
  no_order(false),
167
 
  skip_sort_order(false),
168
 
  union_part(false),
169
 
  optimized(false),
170
 
  need_tmp(false),
171
 
  hidden_group_fields(false),
172
 
  const_table_map(0),
173
 
  found_const_table_map(0),
174
 
  outer_join(0),
175
 
  send_records(0),
176
 
  found_records(0),
177
 
  examined_rows(0),
178
 
  row_limit(0),
179
 
  select_limit(0),
180
 
  fetch_limit(HA_POS_ERROR),
181
 
  session(session_arg),
182
 
  fields_list(fields_arg), 
183
 
  join_list(NULL),
184
 
  unit(NULL),
185
 
  select_lex(NULL),
186
 
  select(NULL),
187
 
  exec_tmp_table1(NULL),
188
 
  exec_tmp_table2(NULL),
189
 
  sum_funcs(NULL),
190
 
  sum_funcs2(NULL),
191
 
  having(NULL),
192
 
  tmp_having(NULL),
193
 
  having_history(NULL),
194
 
  select_options(select_options_arg),
195
 
  result(result_arg),
196
 
  lock(session_arg->lock),
197
 
  tmp_join(NULL),
198
 
  all_fields(fields_arg),
199
 
  error(0),
200
 
  cond_equal(NULL),
201
 
  return_tab(NULL),
202
 
  ref_pointer_array(NULL),
203
 
  items0(NULL),
204
 
  items1(NULL),
205
 
  items2(NULL),
206
 
  items3(NULL),
207
 
  ref_pointer_array_size(0),
208
 
  zero_result_cause(NULL),
209
 
  sortorder(NULL),
210
 
  table_reexec(NULL),
211
 
  join_tab_reexec(NULL)
212
 
{
213
 
  select_distinct= test(select_options & SELECT_DISTINCT);
214
 
  if (&fields_list != &fields_arg) /* only copy if not same*/
215
 
    fields_list= fields_arg;
216
 
  memset(&keyuse, 0, sizeof(keyuse));
217
 
  tmp_table_param.init();
218
 
  tmp_table_param.end_write_records= HA_POS_ERROR;
219
 
  rollup.setState(Rollup::STATE_NONE);
220
 
}
221
 
 
222
 
  /** 
223
 
   * This method is currently only used when a subselect EXPLAIN is performed.
224
 
   * I pulled out the init() method and have simply reset the values to what
225
 
   * was previously in the init() method.  See the note about the hack in 
226
 
   * sql_union.cc...
227
 
   */
228
 
void Join::reset(Session *session_arg, 
229
 
                 List<Item> &fields_arg, 
230
 
                 uint64_t select_options_arg,
231
 
                 select_result *result_arg)
232
 
{
233
 
  join_tab= NULL;
234
 
  best_ref= NULL;
235
 
  map2table= NULL;
236
 
  join_tab_save= NULL;
237
 
  table= NULL;
238
 
  all_tables= NULL;
239
 
  sort_by_table= NULL;
240
 
  tables= 0;
241
 
  outer_tables= 0;
242
 
  const_tables= 0;
243
 
  send_group_parts= 0;
244
 
  sort_and_group= false;
245
 
  first_record= false;
246
 
  full_join= false;
247
 
  group= false;
248
 
  no_field_update= false;
249
 
  do_send_rows= true;
250
 
  resume_nested_loop= false;
251
 
  no_const_tables= false;
252
 
  select_distinct= false;
253
 
  group_optimized_away= false;
254
 
  simple_order= false;
255
 
  simple_group= false;
256
 
  no_order= false;
257
 
  skip_sort_order= false;
258
 
  union_part= false;
259
 
  optimized= false;
260
 
  need_tmp= false;
261
 
  hidden_group_fields= false;
262
 
  const_table_map= 0;
263
 
  found_const_table_map= 0;
264
 
  outer_join= 0;
265
 
  send_records= 0;
266
 
  found_records= 0;
267
 
  examined_rows= 0;
268
 
  row_limit= 0;
269
 
  select_limit= 0;
270
 
  fetch_limit= HA_POS_ERROR;
271
 
  session= session_arg;
272
 
  fields_list= fields_arg; 
273
 
  join_list= NULL;
274
 
  unit= NULL;
275
 
  select_lex= NULL;
276
 
  select= NULL;
277
 
  exec_tmp_table1= NULL;
278
 
  exec_tmp_table2= NULL;
279
 
  sum_funcs= NULL;
280
 
  sum_funcs2= NULL;
281
 
  having= NULL;
282
 
  tmp_having= NULL;
283
 
  having_history= NULL;
284
 
  select_options= select_options_arg;
285
 
  result= result_arg;
286
 
  lock= session_arg->lock;
287
 
  tmp_join= NULL;
288
 
  all_fields= fields_arg;
289
 
  error= 0;
290
 
  cond_equal= NULL;
291
 
  return_tab= NULL;
292
 
  ref_pointer_array= NULL;
293
 
  items0= NULL;
294
 
  items1= NULL;
295
 
  items2= NULL;
296
 
  items3= NULL;
297
 
  ref_pointer_array_size= 0;
298
 
  zero_result_cause= NULL;
299
 
  sortorder= NULL;
300
 
  table_reexec= NULL;
301
 
  join_tab_reexec= NULL;
302
 
  select_distinct= test(select_options & SELECT_DISTINCT);
303
 
  if (&fields_list != &fields_arg) /* only copy if not same*/
304
 
    fields_list= fields_arg;
305
 
  memset(&keyuse, 0, sizeof(keyuse));
306
 
  tmp_table_param.init();
307
 
  tmp_table_param.end_write_records= HA_POS_ERROR;
308
 
  rollup.setState(Rollup::STATE_NONE);
309
 
}
310
 
 
311
 
bool Join::is_top_level_join() const
312
 
{
313
 
  return (unit == &session->getLex()->unit && (unit->fake_select_lex == 0 ||
314
 
                                          select_lex == unit->fake_select_lex));
315
 
}
316
 
 
317
136
/**
318
137
  Prepare of whole select (including sub queries in future).
319
138
 
351
170
  join_list= &select_lex->top_join_list;
352
171
  union_part= unit_arg->is_union();
353
172
 
354
 
  session->getLex()->current_select->is_item_list_lookup= 1;
 
173
  session->lex->current_select->is_item_list_lookup= 1;
355
174
  /*
356
175
    If we have already executed SELECT, then it have not sense to prevent
357
176
    its table from update (see unique_table())
373
192
  for (table_ptr= select_lex->leaf_tables;
374
193
       table_ptr;
375
194
       table_ptr= table_ptr->next_leaf)
376
 
  {
377
195
    tables++;
378
 
  }
379
 
 
380
196
 
381
197
  if (setup_wild(session, fields_list, &all_fields, wild_num) ||
382
198
      select_lex->setup_ref_array(session, og_num) ||
392
208
 
393
209
  if (having)
394
210
  {
395
 
    nesting_map save_allow_sum_func= session->getLex()->allow_sum_func;
396
 
    session->setWhere("having clause");
397
 
    session->getLex()->allow_sum_func|= 1 << select_lex_arg->nest_level;
 
211
    nesting_map save_allow_sum_func= session->lex->allow_sum_func;
 
212
    session->where="having clause";
 
213
    session->lex->allow_sum_func|= 1 << select_lex_arg->nest_level;
398
214
    select_lex->having_fix_field= 1;
399
215
    bool having_fix_rc= (!having->fixed &&
400
216
       (having->fix_fields(session, &having) ||
402
218
    select_lex->having_fix_field= 0;
403
219
    if (having_fix_rc || session->is_error())
404
220
      return(-1);
405
 
    session->getLex()->allow_sum_func= save_allow_sum_func;
 
221
    session->lex->allow_sum_func= save_allow_sum_func;
406
222
  }
407
223
 
408
224
  {
452
268
            in_subs  &&                                                   // 1
453
269
            !select_lex->master_unit()->first_select()->next_select() &&  // 2
454
270
            select_lex->master_unit()->first_select()->leaf_tables &&     // 3
455
 
            session->getLex()->sql_command == SQLCOM_SELECT)                       // *
 
271
            session->lex->sql_command == SQLCOM_SELECT)                       // *
456
272
        {
457
273
          if (in_subs->is_top_level_item() &&                             // 4
458
274
              !in_subs->is_correlated &&                                  // 5
625
441
    select_limit= HA_POS_ERROR;
626
442
  do_send_rows = (unit->select_limit_cnt) ? 1 : 0;
627
443
  // Ignore errors of execution if option IGNORE present
628
 
  if (session->getLex()->ignore)
629
 
    session->getLex()->current_select->no_error= 1;
 
444
  if (session->lex->ignore)
 
445
    session->lex->current_select->no_error= 1;
630
446
 
631
447
#ifdef HAVE_REF_TO_FIELDS     // Not done yet
632
448
  /* Add HAVING to WHERE if possible */
726
542
        conjunctions.
727
543
        Preserve conditions for EXPLAIN.
728
544
      */
729
 
      if (conds && !(session->getLex()->describe & DESCRIBE_EXTENDED))
 
545
      if (conds && !(session->lex->describe & DESCRIBE_EXTENDED))
730
546
      {
731
547
        COND *table_independent_conds= make_cond_for_table(conds, PSEUDO_TABLE_BITS, 0, 0);
732
548
        conds= table_independent_conds;
761
577
      !(select_options & SELECT_DESCRIBE) &&
762
578
      (!conds ||
763
579
       !(conds->used_tables() & RAND_TABLE_BIT) ||
764
 
       select_lex->master_unit() == &session->getLex()->unit)) // upper level SELECT
 
580
       select_lex->master_unit() == &session->lex->unit)) // upper level SELECT
765
581
  {
766
582
    zero_result_cause= "no matching row in const table";
767
583
    goto setup_subq_exit;
821
637
 
822
638
  if (conds &&!outer_join && const_table_map != found_const_table_map &&
823
639
      (select_options & SELECT_DESCRIBE) &&
824
 
      select_lex->master_unit() == &session->getLex()->unit) // upper level SELECT
 
640
      select_lex->master_unit() == &session->lex->unit) // upper level SELECT
825
641
  {
826
642
    conds=new Item_int((int64_t) 0,1);  // Always false
827
643
  }
909
725
  }
910
726
  if (group_list || tmp_table_param.sum_func_count)
911
727
  {
912
 
    if (! hidden_group_fields && rollup.getState() == Rollup::STATE_NONE)
 
728
    if (! hidden_group_fields && rollup.state == ROLLUP::STATE_NONE)
913
729
      select_distinct=0;
914
730
  }
915
731
  else if (select_distinct && tables - const_tables == 1)
973
789
  {
974
790
    Order *old_group_list;
975
791
    group_list= remove_constants(this, (old_group_list= group_list), conds,
976
 
                                 rollup.getState() == Rollup::STATE_NONE,
 
792
                                 rollup.state == ROLLUP::STATE_NONE,
977
793
                                 &simple_group);
978
794
    if (session->is_error())
979
795
    {
1165
981
 
1166
982
    tmp_table_param.hidden_field_count= (all_fields.elements -
1167
983
           fields_list.elements);
1168
 
    Order *tmp_group= (((not simple_group) or not (getDebug().test(debug::NO_KEY_GROUP))) ? group_list : (Order*) 0);
1169
 
 
 
984
    Order *tmp_group= ((!simple_group &&
 
985
                           ! (test_flags.test(TEST_NO_KEY_GROUP))) ? group_list :
 
986
                                                                     (Order*) 0);
1170
987
    /*
1171
988
      Pushing LIMIT to the temporary table creation is not applicable
1172
989
      when there is ORDER BY or GROUP BY or there is no GROUP BY, but
1175
992
    */
1176
993
    ha_rows tmp_rows_limit= ((order == 0 || skip_sort_order) &&
1177
994
                             !tmp_group &&
1178
 
                             !session->getLex()->current_select->with_sum_func) ?
 
995
                             !session->lex->current_select->with_sum_func) ?
1179
996
                            select_limit : HA_POS_ERROR;
1180
997
 
1181
998
    if (!(exec_tmp_table1=
1352
1169
*/
1353
1170
bool Join::init_save_join_tab()
1354
1171
{
1355
 
  if (!(tmp_join= (Join*)session->getMemRoot()->allocate(sizeof(Join))))
 
1172
  if (!(tmp_join= (Join*)session->alloc(sizeof(Join))))
1356
1173
    return 1;
1357
1174
 
1358
1175
  error= 0;              // Ensure that tmp_join.error= 0
1365
1182
{
1366
1183
  if (! join_tab_save && select_lex->master_unit()->uncacheable.any())
1367
1184
  {
1368
 
    if (!(join_tab_save= (JoinTable*)session->getMemRoot()->duplicate((unsigned char*) join_tab,
 
1185
    if (!(join_tab_save= (JoinTable*)session->memdup((unsigned char*) join_tab,
1369
1186
            sizeof(JoinTable) * tables)))
1370
1187
      return 1;
1371
1188
  }
1767
1584
      if (sort_table_cond)
1768
1585
      {
1769
1586
        if (!curr_table->select)
1770
 
          if (!(curr_table->select= new optimizer::SqlSelect()))
 
1587
          if (!(curr_table->select= new optimizer::SqlSelect))
1771
1588
            return;
1772
1589
        if (!curr_table->select->cond)
1773
1590
          curr_table->select->cond= sort_table_cond;
1871
1688
    for a derived table which is always materialized.
1872
1689
    Otherwise we would not be able to print the query  correctly.
1873
1690
  */
1874
 
  if (items0 && (session->getLex()->describe & DESCRIBE_EXTENDED) && select_lex->linkage == DERIVED_TABLE_TYPE)
 
1691
  if (items0 && (session->lex->describe & DESCRIBE_EXTENDED) && select_lex->linkage == DERIVED_TABLE_TYPE)
1875
1692
    set_items_ref_array(items0);
1876
1693
 
1877
1694
  return;
2003
1820
    Optimization: if not EXPLAIN and we are done with the Join,
2004
1821
    free all tables.
2005
1822
  */
2006
 
  bool full= (select_lex->uncacheable.none() && ! session->getLex()->describe);
 
1823
  bool full= (select_lex->uncacheable.none() && ! session->lex->describe);
2007
1824
  bool can_unlock= full;
2008
1825
 
2009
1826
  cleanup(full);
2014
1831
    for (sl= tmp_unit->first_select(); sl; sl= sl->next_select())
2015
1832
    {
2016
1833
      Item_subselect *subselect= sl->master_unit()->item;
2017
 
      bool full_local= full && (!subselect || 
2018
 
                                (subselect->is_evaluated() &&
2019
 
                                !subselect->is_uncacheable()));
 
1834
      bool full_local= full && (!subselect || subselect->is_evaluated());
2020
1835
      /*
2021
1836
        If this join is evaluated, we can fully clean it up and clean up all
2022
1837
        its underlying joins even if they are correlated -- they will not be
2038
1853
  if (can_unlock && lock && session->lock &&
2039
1854
      !(select_options & SELECT_NO_UNLOCK) &&
2040
1855
      !select_lex->subquery_in_having &&
2041
 
      (select_lex == (session->getLex()->unit.fake_select_lex ?
2042
 
                      session->getLex()->unit.fake_select_lex : &session->getLex()->select_lex)))
 
1856
      (select_lex == (session->lex->unit.fake_select_lex ?
 
1857
                      session->lex->unit.fake_select_lex : &session->lex->select_lex)))
2043
1858
  {
2044
1859
    /*
2045
1860
      TODO: unlock tables even if the join isn't top level select in the
2068
1883
{
2069
1884
  if (table)
2070
1885
  {
 
1886
    JoinTable *tab,*end;
2071
1887
    /*
2072
1888
      Only a sorted table may be cached.  This sorted table is always the
2073
1889
      first non const table in join->table
2077
1893
      table[const_tables]->free_io_cache();
2078
1894
      table[const_tables]->filesort_free_buffers(full);
2079
1895
    }
2080
 
  }
2081
 
 
2082
 
  if (join_tab)
2083
 
  {
2084
 
    JoinTable *tab,*end;
2085
1896
 
2086
1897
    if (full)
2087
1898
    {
2098
1909
      }
2099
1910
    }
2100
1911
  }
2101
 
 
2102
1912
  /*
2103
1913
    We are not using tables anymore
2104
1914
    Unlock all tables. We may be in an INSERT .... SELECT statement.
2112
1922
      We can't call delete_elements() on copy_funcs as this will cause
2113
1923
      problems in free_elements() as some of the elements are then deleted.
2114
1924
    */
2115
 
    tmp_table_param.copy_funcs.clear();
 
1925
    tmp_table_param.copy_funcs.empty();
2116
1926
    /*
2117
1927
      If we have tmp_join and 'this' Join is not tmp_join and
2118
1928
      tmp_table_param.copy_field's  of them are equal then we have to remove
2142
1952
    are not re-calculated.
2143
1953
  */
2144
1954
  for (uint32_t i= join->const_tables; i < join->tables; i++)
2145
 
  {
2146
1955
    join->table[i]->mark_as_null_row();   // All fields are NULL
2147
 
  }
2148
1956
}
2149
1957
 
2150
1958
/**
2165
1973
    If we are using rollup, we need a copy of the summary functions for
2166
1974
    each level
2167
1975
  */
2168
 
  if (rollup.getState() != Rollup::STATE_NONE)
 
1976
  if (rollup.state != ROLLUP::STATE_NONE)
2169
1977
    func_count*= (send_group_parts+1);
2170
1978
 
2171
1979
  group_parts= send_group_parts;
2213
2021
                              bool before_group_by, 
2214
2022
                              bool recompute)
2215
2023
{
2216
 
  List<Item>::iterator it(field_list.begin());
 
2024
  List_iterator_fast<Item> it(field_list);
2217
2025
  Item_sum **func;
2218
2026
  Item *item;
2219
2027
 
2228
2036
         ((Item_sum *)item)->depended_from() == select_lex))
2229
2037
      *func++= (Item_sum*) item;
2230
2038
  }
2231
 
  if (before_group_by && rollup.getState() == Rollup::STATE_INITED)
 
2039
  if (before_group_by && rollup.state == ROLLUP::STATE_INITED)
2232
2040
  {
2233
 
    rollup.setState(Rollup::STATE_READY);
 
2041
    rollup.state= ROLLUP::STATE_READY;
2234
2042
    if (rollup_make_fields(field_list, send_fields, &func))
2235
 
      return true;     // Should never happen
 
2043
      return(true);     // Should never happen
2236
2044
  }
2237
 
  else if (rollup.getState() == Rollup::STATE_NONE)
 
2045
  else if (rollup.state == ROLLUP::STATE_NONE)
2238
2046
  {
2239
2047
    for (uint32_t i=0 ; i <= send_group_parts ;i++)
2240
2048
      sum_funcs_end[i]= func;
2241
2049
  }
2242
 
  else if (rollup.getState() == Rollup::STATE_READY)
 
2050
  else if (rollup.state == ROLLUP::STATE_READY)
2243
2051
    return(false);                         // Don't put end marker
2244
2052
  *func=0;          // End marker
2245
2053
  return(false);
2248
2056
/** Allocate memory needed for other rollup functions. */
2249
2057
bool Join::rollup_init()
2250
2058
{
 
2059
  uint32_t i,j;
2251
2060
  Item **ref_array;
2252
2061
 
2253
2062
  tmp_table_param.quick_group= 0; // Can't create groups in tmp table
2254
 
  rollup.setState(Rollup::STATE_INITED);
 
2063
  rollup.state= ROLLUP::STATE_INITED;
2255
2064
 
2256
2065
  /*
2257
2066
    Create pointers to the different sum function groups
2259
2068
  */
2260
2069
  tmp_table_param.group_parts= send_group_parts;
2261
2070
 
2262
 
  rollup.setNullItems((Item_null_result**) session->getMemRoot()->allocate((sizeof(Item*) +
2263
 
                                                                sizeof(Item**) +
2264
 
                                                                sizeof(List<Item>) +
2265
 
                                                                ref_pointer_array_size)
2266
 
                                                               * send_group_parts ));
2267
 
  if (! rollup.getNullItems())
2268
 
  {
 
2071
  if (!(rollup.null_items= (Item_null_result**) session->alloc((sizeof(Item*) +
 
2072
                                                sizeof(Item**) +
 
2073
                                                sizeof(List<Item>) +
 
2074
                        ref_pointer_array_size)
 
2075
                        * send_group_parts )))
2269
2076
    return 1;
2270
 
  }
2271
2077
 
2272
 
  rollup.setFields((List<Item>*) (rollup.getNullItems() + send_group_parts));
2273
 
  rollup.setRefPointerArrays((Item***) (rollup.getFields() + send_group_parts));
2274
 
  ref_array= (Item**) (rollup.getRefPointerArrays()+send_group_parts);
 
2078
  rollup.fields= (List<Item>*) (rollup.null_items + send_group_parts);
 
2079
  rollup.ref_pointer_arrays= (Item***) (rollup.fields + send_group_parts);
 
2080
  ref_array= (Item**) (rollup.ref_pointer_arrays+send_group_parts);
2275
2081
 
2276
2082
  /*
2277
2083
    Prepare space for field list for the different levels
2278
2084
    These will be filled up in rollup_make_fields()
2279
2085
  */
2280
 
  for (uint32_t i= 0 ; i < send_group_parts ; i++)
 
2086
  for (i= 0 ; i < send_group_parts ; i++)
2281
2087
  {
2282
 
    rollup.getNullItems()[i]= new (session->mem_root) Item_null_result();
2283
 
    List<Item> *rollup_fields= &rollup.getFields()[i];
2284
 
    rollup_fields->clear();
2285
 
    rollup.getRefPointerArrays()[i]= ref_array;
 
2088
    rollup.null_items[i]= new (session->mem_root) Item_null_result();
 
2089
    List<Item> *rollup_fields= &rollup.fields[i];
 
2090
    rollup_fields->empty();
 
2091
    rollup.ref_pointer_arrays[i]= ref_array;
2286
2092
    ref_array+= all_fields.elements;
2287
2093
  }
2288
 
 
2289
 
  for (uint32_t i= 0 ; i < send_group_parts; i++)
 
2094
  for (i= 0 ; i < send_group_parts; i++)
2290
2095
  {
2291
 
    for (uint32_t j= 0 ; j < fields_list.elements ; j++)
2292
 
    {
2293
 
      rollup.getFields()[i].push_back(rollup.getNullItems()[i]);
2294
 
    }
 
2096
    for (j=0 ; j < fields_list.elements ; j++)
 
2097
      rollup.fields[i].push_back(rollup.null_items[i]);
2295
2098
  }
2296
 
 
2297
 
  List<Item>::iterator it(all_fields.begin());
 
2099
  List_iterator<Item> it(all_fields);
2298
2100
  Item *item;
2299
2101
  while ((item= it++))
2300
2102
  {
2369
2171
*/
2370
2172
bool Join::rollup_make_fields(List<Item> &fields_arg, List<Item> &sel_fields, Item_sum ***func)
2371
2173
{
2372
 
  List<Item>::iterator it(fields_arg.begin());
 
2174
  List_iterator_fast<Item> it(fields_arg);
2373
2175
  Item *first_field= sel_fields.head();
2374
2176
  uint32_t level;
2375
2177
 
2400
2202
    uint32_t pos= send_group_parts - level -1;
2401
2203
    bool real_fields= 0;
2402
2204
    Item *item;
2403
 
    List<Item>::iterator new_it(rollup.getFields()[pos].begin());
2404
 
    Item **ref_array_start= rollup.getRefPointerArrays()[pos];
 
2205
    List_iterator<Item> new_it(rollup.fields[pos]);
 
2206
    Item **ref_array_start= rollup.ref_pointer_arrays[pos];
2405
2207
    Order *start_group;
2406
2208
 
2407
2209
    /* Point to first hidden field */
2414
2216
    for (i= 0, start_group= group_list ;i++ < pos ;start_group= start_group->next)
2415
2217
    {}
2416
2218
 
2417
 
    it= fields_arg.begin();
 
2219
    it.rewind();
2418
2220
    while ((item= it++))
2419
2221
    {
2420
2222
      if (item == first_field)
2499
2301
*/
2500
2302
int Join::rollup_send_data(uint32_t idx)
2501
2303
{
2502
 
  for (uint32_t i= send_group_parts ; i-- > idx ; )
 
2304
  uint32_t i;
 
2305
  for (i= send_group_parts ; i-- > idx ; )
2503
2306
  {
2504
2307
    /* Get reference pointers to sum functions in place */
2505
 
    memcpy(ref_pointer_array, rollup.getRefPointerArrays()[i], ref_pointer_array_size);
2506
 
 
 
2308
    memcpy(ref_pointer_array, rollup.ref_pointer_arrays[i],
 
2309
     ref_pointer_array_size);
2507
2310
    if ((!having || having->val_int()))
2508
2311
    {
2509
 
      if (send_records < unit->select_limit_cnt && do_send_rows && result->send_data(rollup.getFields()[i]))
2510
 
      {
2511
 
        return 1;
2512
 
      }
 
2312
      if (send_records < unit->select_limit_cnt && do_send_rows &&
 
2313
    result->send_data(rollup.fields[i]))
 
2314
  return 1;
2513
2315
      send_records++;
2514
2316
    }
2515
2317
  }
2516
2318
  /* Restore ref_pointer_array */
2517
2319
  set_items_ref_array(current_ref_pointer_array);
2518
 
 
2519
2320
  return 0;
2520
2321
}
2521
2322
 
2540
2341
*/
2541
2342
int Join::rollup_write_data(uint32_t idx, Table *table_arg)
2542
2343
{
2543
 
  for (uint32_t i= send_group_parts ; i-- > idx ; )
 
2344
  uint32_t i;
 
2345
  for (i= send_group_parts ; i-- > idx ; )
2544
2346
  {
2545
2347
    /* Get reference pointers to sum functions in place */
2546
 
    memcpy(ref_pointer_array, rollup.getRefPointerArrays()[i],
 
2348
    memcpy(ref_pointer_array, rollup.ref_pointer_arrays[i],
2547
2349
           ref_pointer_array_size);
2548
2350
    if ((!having || having->val_int()))
2549
2351
    {
2550
2352
      int write_error;
2551
2353
      Item *item;
2552
 
      List<Item>::iterator it(rollup.getFields()[i].begin());
 
2354
      List_iterator_fast<Item> it(rollup.fields[i]);
2553
2355
      while ((item= it++))
2554
2356
      {
2555
2357
        if (item->type() == Item::NULL_ITEM && item->is_result_field())
2565
2367
  }
2566
2368
  /* Restore ref_pointer_array */
2567
2369
  set_items_ref_array(current_ref_pointer_array);
2568
 
 
2569
2370
  return 0;
2570
2371
}
2571
2372
 
3013
2814
  if (!end_of_records)
3014
2815
  {
3015
2816
    copy_fields(&join->tmp_table_param);
3016
 
    if (copy_funcs(join->tmp_table_param.items_to_copy, join->session))
3017
 
      return NESTED_LOOP_ERROR;
 
2817
    copy_funcs(join->tmp_table_param.items_to_copy);
3018
2818
    if (!join->having || join->having->val_int())
3019
2819
    {
3020
2820
      int error;
3099
2899
      memcpy(table->getInsertRecord()+key_part->offset, group->buff, 1);
3100
2900
  }
3101
2901
  init_tmptable_sum_functions(join->sum_funcs);
3102
 
  if (copy_funcs(join->tmp_table_param.items_to_copy, join->session))
3103
 
    return NESTED_LOOP_ERROR;
 
2902
  copy_funcs(join->tmp_table_param.items_to_copy);
3104
2903
  if ((error=table->cursor->insertRecord(table->getInsertRecord())))
3105
2904
  {
3106
2905
    my_error(ER_USE_SQL_BIG_RESULT, MYF(0));
3126
2925
 
3127
2926
  init_tmptable_sum_functions(join->sum_funcs);
3128
2927
  copy_fields(&join->tmp_table_param);          // Groups are copied twice.
3129
 
  if (copy_funcs(join->tmp_table_param.items_to_copy, join->session))
3130
 
    return NESTED_LOOP_ERROR;
 
2928
  copy_funcs(join->tmp_table_param.items_to_copy);
3131
2929
 
3132
2930
  if (!(error= table->cursor->insertRecord(table->getInsertRecord())))
3133
2931
    join->send_records++;                       // New group
3212
3010
      case REAL_RESULT:
3213
3011
        key_length+= sizeof(double);
3214
3012
        break;
3215
 
 
3216
3013
      case INT_RESULT:
3217
3014
        key_length+= sizeof(int64_t);
3218
3015
        break;
3219
 
 
3220
3016
      case DECIMAL_RESULT:
3221
 
        key_length+= class_decimal_get_binary_size(group_item->max_length -
 
3017
        key_length+= my_decimal_get_binary_size(group_item->max_length -
3222
3018
                                                (group_item->decimals ? 1 : 0),
3223
3019
                                                group_item->decimals);
3224
3020
        break;
3225
 
 
3226
3021
      case STRING_RESULT:
3227
 
        {
3228
 
          enum enum_field_types type= group_item->field_type();
 
3022
      {
 
3023
        enum enum_field_types type= group_item->field_type();
 
3024
        /*
 
3025
          As items represented as DATE/TIME fields in the group buffer
 
3026
          have STRING_RESULT result type, we increase the length
 
3027
          by 8 as maximum pack length of such fields.
 
3028
        */
 
3029
        if (type == DRIZZLE_TYPE_DATE ||
 
3030
            type == DRIZZLE_TYPE_DATETIME ||
 
3031
            type == DRIZZLE_TYPE_TIMESTAMP)
 
3032
        {
 
3033
          key_length+= 8;
 
3034
        }
 
3035
        else
 
3036
        {
3229
3037
          /*
3230
 
            As items represented as DATE/TIME fields in the group buffer
3231
 
            have STRING_RESULT result type, we increase the length
3232
 
            by 8 as maximum pack length of such fields.
 
3038
            Group strings are taken as varstrings and require an length field.
 
3039
            A field is not yet created by create_tmp_field()
 
3040
            and the sizes should match up.
3233
3041
          */
3234
 
          if (field::isDateTime(type))
3235
 
          {
3236
 
            key_length+= 8;
3237
 
          }
3238
 
          else
3239
 
          {
3240
 
            /*
3241
 
              Group strings are taken as varstrings and require an length field.
3242
 
              A field is not yet created by create_tmp_field()
3243
 
              and the sizes should match up.
3244
 
            */
3245
 
            key_length+= group_item->max_length + HA_KEY_BLOB_LENGTH;
3246
 
          }
3247
 
 
3248
 
          break;
 
3042
          key_length+= group_item->max_length + HA_KEY_BLOB_LENGTH;
3249
3043
        }
3250
 
 
3251
 
      case ROW_RESULT:
 
3044
        break;
 
3045
      }
 
3046
      default:
3252
3047
        /* This case should never be choosen */
3253
3048
        assert(0);
3254
3049
        my_error(ER_OUT_OF_RESOURCES, MYF(ME_FATALERROR));
3255
3050
      }
3256
3051
    }
3257
 
 
3258
3052
    parts++;
3259
 
 
3260
3053
    if (group_item->maybe_null)
3261
3054
      null_parts++;
3262
3055
  }
3263
 
 
3264
3056
  join->tmp_table_param.group_length=key_length+null_parts;
3265
3057
  join->tmp_table_param.group_parts=parts;
3266
3058
  join->tmp_table_param.group_null_parts=null_parts;
3403
3195
 
3404
3196
  table_count=join->tables;
3405
3197
  if (!(join->join_tab=join_tab=
3406
 
  (JoinTable*) session->getMemRoot()->allocate(sizeof(JoinTable)*table_count)))
 
3198
  (JoinTable*) session->alloc(sizeof(JoinTable)*table_count)))
3407
3199
    return(true);
3408
3200
 
3409
 
  for (i= 0; i < table_count; i++)
3410
 
    new (join_tab+i) JoinTable();
3411
 
 
3412
3201
  join->full_join=0;
3413
3202
 
3414
3203
  used_tables= OUTER_REF_TABLE_BIT;   // Outer row is already read
3527
3316
    i.e. they have subqueries, unions or call stored procedures.
3528
3317
    TODO: calculate a correct cost for a query with subqueries and UNIONs.
3529
3318
  */
3530
 
  if (join->session->getLex()->is_single_level_stmt())
 
3319
  if (join->session->lex->is_single_level_stmt())
3531
3320
    join->session->status_var.last_query_cost= join->best_read;
3532
3321
  return(false);
3533
3322
}
4040
3829
        will ensure that this will be used
4041
3830
      */
4042
3831
      best= tmp;
4043
 
      records= rnd_records;
 
3832
      records= rows2double(rnd_records);
4044
3833
      best_key= 0;
4045
3834
      /* range/index_merge/ALL/index access method are "independent", so: */
4046
3835
      best_ref_depends_map= 0;
4561
4350
  */
4562
4351
  if (!join->table_reexec)
4563
4352
  {
4564
 
    if (!(join->table_reexec= (Table**) join->session->getMemRoot()->allocate(sizeof(Table*))))
 
4353
    if (!(join->table_reexec= (Table**) join->session->alloc(sizeof(Table*))))
4565
4354
      return(true);
4566
4355
    if (join->tmp_join)
4567
4356
      join->tmp_join->table_reexec= join->table_reexec;
4569
4358
  if (!join->join_tab_reexec)
4570
4359
  {
4571
4360
    if (!(join->join_tab_reexec=
4572
 
          (JoinTable*) join->session->getMemRoot()->allocate(sizeof(JoinTable))))
 
4361
          (JoinTable*) join->session->alloc(sizeof(JoinTable))))
4573
4362
      return(true);
4574
 
    new (join->join_tab_reexec) JoinTable();
4575
4363
    if (join->tmp_join)
4576
4364
      join->tmp_join->join_tab_reexec= join->join_tab_reexec;
4577
4365
  }
4592
4380
  join->row_limit=join->unit->select_limit_cnt;
4593
4381
  join->do_send_rows = (join->row_limit) ? 1 : 0;
4594
4382
 
 
4383
  join_tab->cache.buff=0;                       /* No caching */
4595
4384
  join_tab->table=tmp_table;
4596
4385
  join_tab->select=0;
4597
4386
  join_tab->select_cond=0;
4682
4471
      /* Ignore sj-nests: */
4683
4472
      if (!embedding->on_expr)
4684
4473
        continue;
4685
 
      NestedJoin *nested_join= embedding->getNestedJoin();
 
4474
      nested_join_st *nested_join= embedding->getNestedJoin();
4686
4475
      if (!nested_join->counter_)
4687
4476
      {
4688
4477
        /*
4721
4510
      if (join->tables > 1)
4722
4511
        cond->update_used_tables();             // Tablenr may have changed
4723
4512
      if (join->const_tables == join->tables &&
4724
 
          session->getLex()->current_select->master_unit() ==
4725
 
          &session->getLex()->unit)             // not upper level SELECT
 
4513
          session->lex->current_select->master_unit() ==
 
4514
          &session->lex->unit)          // not upper level SELECT
4726
4515
        join->const_table_map|=RAND_TABLE_BIT;
4727
4516
      {                                         // Check const tables
4728
4517
        COND *const_cond=
4791
4580
        tab->ref.key= -1;
4792
4581
        tab->ref.key_parts= 0;          // Don't use ref key.
4793
4582
        cur_pos= join->getPosFromOptimalPlan(i);
4794
 
        cur_pos.setFanout(tab->quick->records);
 
4583
        cur_pos.setFanout(rows2double(tab->quick->records));
4795
4584
        /*
4796
4585
           We will use join cache here : prevent sorting of the first
4797
4586
           table only and sort at the end.
4800
4589
          join->full_join= 1;
4801
4590
      }
4802
4591
 
4803
 
      if (join->full_join and not session->getLex()->current_select->is_cross and not cond)
4804
 
      {
4805
 
        my_error(ER_CARTESIAN_JOIN_ATTEMPTED, MYF(0));
4806
 
        return 1;
4807
 
      }
4808
 
 
4809
4592
      tmp= NULL;
4810
4593
      if (cond)
4811
4594
        tmp= make_cond_for_table(cond,used_tables,current_map, 0);
4836
4619
          tab->type == AM_EQ_REF)
4837
4620
      {
4838
4621
        optimizer::SqlSelect *sel= tab->select= ((optimizer::SqlSelect*)
4839
 
            session->getMemRoot()->duplicate((unsigned char*) select,
 
4622
            session->memdup((unsigned char*) select,
4840
4623
              sizeof(*select)));
4841
4624
        if (! sel)
4842
4625
          return 1;                     // End of memory
4974
4757
                                         current_map, 0)))
4975
4758
            {
4976
4759
              tab->cache.select= (optimizer::SqlSelect*)
4977
 
                session->getMemRoot()->duplicate((unsigned char*) sel, sizeof(optimizer::SqlSelect));
 
4760
                session->memdup((unsigned char*) sel, sizeof(optimizer::SqlSelect));
4978
4761
              tab->cache.select->cond= tmp;
4979
4762
              tab->cache.select->read_tables= join->const_table_map;
4980
4763
            }
5110
4893
 
5111
4894
    if (tab->insideout_match_tab)
5112
4895
    {
5113
 
      if (! (tab->insideout_buf= (unsigned char*) join->session->getMemRoot()->allocate(tab->table->key_info
 
4896
      if (! (tab->insideout_buf= (unsigned char*) join->session->alloc(tab->table->key_info
5114
4897
                                                                       [tab->index].
5115
4898
                                                                       key_length)))
5116
4899
        return true;
5292
5075
  {
5293
5076
    if (send_row)
5294
5077
    {
5295
 
      List<Item>::iterator it(fields.begin());
 
5078
      List_iterator_fast<Item> it(fields);
5296
5079
      Item *item;
5297
5080
      while ((item= it++))
5298
5081
        item->no_rows_in_result();
5428
5211
static COND *simplify_joins(Join *join, List<TableList> *join_list, COND *conds, bool top)
5429
5212
{
5430
5213
  TableList *table;
5431
 
  NestedJoin *nested_join;
 
5214
  nested_join_st *nested_join;
5432
5215
  TableList *prev_table= 0;
5433
 
  List<TableList>::iterator li(join_list->begin());
 
5216
  List_iterator<TableList> li(*join_list);
5434
5217
 
5435
5218
  /*
5436
5219
    Try to simplify join operations from join_list.
5566
5349
    Flatten nested joins that can be flattened.
5567
5350
    no ON expression and not a semi-join => can be flattened.
5568
5351
  */
5569
 
  li= join_list->begin();
 
5352
  li.rewind();
5570
5353
  while ((table= li++))
5571
5354
  {
5572
5355
    nested_join= table->getNestedJoin();
5573
5356
    if (nested_join && !table->on_expr)
5574
5357
    {
5575
5358
      TableList *tbl;
5576
 
      List<TableList>::iterator it(nested_join->join_list.begin());
 
5359
      List_iterator<TableList> it(nested_join->join_list);
5577
5360
      while ((tbl= it++))
5578
5361
      {
5579
5362
        tbl->setEmbedding(table->getEmbedding());
5596
5379
 
5597
5380
  /* Calculate how many saved fields there is in list */
5598
5381
  field_count=0;
5599
 
  List<Item>::iterator it(fields.begin());
 
5382
  List_iterator<Item> it(fields);
5600
5383
  Item *item;
5601
5384
  while ((item=it++))
5602
5385
  {
5650
5433
                               bool *hidden_group_fields)
5651
5434
{
5652
5435
  int res;
5653
 
  nesting_map save_allow_sum_func=session->getLex()->allow_sum_func ;
 
5436
  nesting_map save_allow_sum_func=session->lex->allow_sum_func ;
5654
5437
 
5655
 
  session->getLex()->allow_sum_func&= ~(1 << session->getLex()->current_select->nest_level);
 
5438
  session->lex->allow_sum_func&= ~(1 << session->lex->current_select->nest_level);
5656
5439
  res= session->setup_conds(tables, conds);
5657
5440
 
5658
 
  session->getLex()->allow_sum_func|= 1 << session->getLex()->current_select->nest_level;
 
5441
  session->lex->allow_sum_func|= 1 << session->lex->current_select->nest_level;
5659
5442
  res= res || setup_order(session, ref_pointer_array, tables, fields, all_fields,
5660
5443
                          order);
5661
 
  session->getLex()->allow_sum_func&= ~(1 << session->getLex()->current_select->nest_level);
 
5444
  session->lex->allow_sum_func&= ~(1 << session->lex->current_select->nest_level);
5662
5445
  res= res || setup_group(session, ref_pointer_array, tables, fields, all_fields,
5663
5446
                          group, hidden_group_fields);
5664
 
  session->getLex()->allow_sum_func= save_allow_sum_func;
 
5447
  session->lex->allow_sum_func= save_allow_sum_func;
5665
5448
  return(res);
5666
5449
}
5667
5450
 
5701
5484
 
5702
5485
  table_count= join->tables;
5703
5486
  stat= (JoinTable*) join->session->calloc(sizeof(JoinTable)*table_count);
5704
 
  stat_ref= (JoinTable**) join->session->getMemRoot()->allocate(sizeof(JoinTable*)*MAX_TABLES);
5705
 
  table_vector= (Table**) join->session->getMemRoot()->allocate(sizeof(Table*)*(table_count*2));
 
5487
  stat_ref= (JoinTable**) join->session->alloc(sizeof(JoinTable*)*MAX_TABLES);
 
5488
  table_vector= (Table**) join->session->alloc(sizeof(Table*)*(table_count*2));
5706
5489
  if (! stat || ! stat_ref || ! table_vector)
5707
5490
    return 1;
5708
5491
 
5766
5549
      s->embedding_map.reset();
5767
5550
      do
5768
5551
      {
5769
 
        NestedJoin *nested_join= embedding->getNestedJoin();
 
5552
        nested_join_st *nested_join= embedding->getNestedJoin();
5770
5553
        s->embedding_map|= nested_join->nj_map;
5771
5554
        s->dependent|= embedding->getDepTables();
5772
5555
        embedding= embedding->getEmbedding();
5795
5578
       As we use bitmaps to represent the relation the complexity
5796
5579
       of the algorithm is O((number of tables)^2).
5797
5580
    */
5798
 
    for (i= 0; i < table_count; i++)
 
5581
    for (i= 0, s= stat ; i < table_count ; i++, s++)
5799
5582
    {
5800
 
      uint32_t j;
5801
 
      table= stat[i].table;
5802
 
 
5803
 
      if (!table->reginfo.join_tab->dependent)
5804
 
        continue;
5805
 
 
5806
 
      for (j= 0, s= stat; j < table_count; j++, s++)
 
5583
      for (uint32_t j= 0 ; j < table_count ; j++)
5807
5584
      {
 
5585
        table= stat[j].table;
5808
5586
        if (s->dependent & table->map)
5809
 
        {
5810
 
          table_map was_dependent= s->dependent;
5811
5587
          s->dependent |= table->reginfo.join_tab->dependent;
5812
 
          if (i > j && s->dependent != was_dependent)
5813
 
          {
5814
 
            i= j= 1;
5815
 
            break;
5816
 
          }
5817
 
        }
5818
5588
      }
 
5589
      if (s->dependent)
 
5590
        s->table->maybe_null= 1;
5819
5591
    }
5820
5592
    /* Catch illegal cross references for outer joins */
5821
5593
    for (i= 0, s= stat ; i < table_count ; i++, s++)
5826
5598
        my_message(ER_WRONG_OUTER_JOIN, ER(ER_WRONG_OUTER_JOIN), MYF(0));
5827
5599
        return 1;
5828
5600
      }
5829
 
      if (outer_join & s->table->map)
5830
 
        s->table->maybe_null= 1;
5831
 
 
5832
5601
      s->key_dependent= s->dependent;
5833
5602
    }
5834
5603
  }
5850
5619
    s= p_pos->getJoinTable();
5851
5620
    s->type= AM_SYSTEM;
5852
5621
    join->const_table_map|=s->table->map;
5853
 
    if ((tmp= s->joinReadConstTable(p_pos)))
 
5622
    if ((tmp= join_read_const_table(s, p_pos)))
5854
5623
    {
5855
5624
      if (tmp > 0)
5856
5625
        return 1;                       // Fatal error
5924
5693
          join->const_table_map|=table->map;
5925
5694
          set_position(join, const_count++, s, (optimizer::KeyUse*) 0);
5926
5695
          partial_pos= join->getSpecificPosInPartialPlan(const_count - 1);
5927
 
          if ((tmp= s->joinReadConstTable(partial_pos)))
 
5696
          if ((tmp= join_read_const_table(s, partial_pos)))
5928
5697
          {
5929
5698
            if (tmp > 0)
5930
5699
              return 1;                 // Fatal error
5976
5745
                if (create_ref_for_key(join, s, start_keyuse, found_const_table_map))
5977
5746
                  return 1;
5978
5747
                partial_pos= join->getSpecificPosInPartialPlan(const_count - 1);
5979
 
                if ((tmp=s->joinReadConstTable(partial_pos)))
 
5748
                if ((tmp=join_read_const_table(s, partial_pos)))
5980
5749
                {
5981
5750
                  if (tmp > 0)
5982
5751
                    return 1;                   // Fatal error
6060
5829
      s->quick=select->quick;
6061
5830
      s->needed_reg=select->needed_reg;
6062
5831
      select->quick=0;
6063
 
 
6064
5832
      if (records == 0 && s->table->reginfo.impossible_range)
6065
5833
      {
6066
5834
        /*
6138
5906
*/
6139
5907
static uint32_t build_bitmap_for_nested_joins(List<TableList> *join_list, uint32_t first_unused)
6140
5908
{
6141
 
  List<TableList>::iterator li(join_list->begin());
 
5909
  List_iterator<TableList> li(*join_list);
6142
5910
  TableList *table;
6143
5911
  while ((table= li++))
6144
5912
  {
6145
 
    NestedJoin *nested_join;
 
5913
    nested_join_st *nested_join;
6146
5914
    if ((nested_join= table->getNestedJoin()))
6147
5915
    {
6148
5916
      /*
6199
5967
}
6200
5968
 
6201
5969
/**
6202
 
  Set NestedJoin::counter=0 in all nested joins in passed list.
 
5970
  Set nested_join_st::counter=0 in all nested joins in passed list.
6203
5971
 
6204
 
    Recursively set NestedJoin::counter=0 for all nested joins contained in
 
5972
    Recursively set nested_join_st::counter=0 for all nested joins contained in
6205
5973
    the passed join_list.
6206
5974
 
6207
5975
  @param join_list  List of nested joins to process. It may also contain base
6209
5977
*/
6210
5978
static void reset_nj_counters(List<TableList> *join_list)
6211
5979
{
6212
 
  List<TableList>::iterator li(join_list->begin());
 
5980
  List_iterator<TableList> li(*join_list);
6213
5981
  TableList *table;
6214
5982
  while ((table= li++))
6215
5983
  {
6216
 
    NestedJoin *nested_join;
 
5984
    nested_join_st *nested_join;
6217
5985
    if ((nested_join= table->getNestedJoin()))
6218
5986
    {
6219
5987
      nested_join->counter_= 0;
6299
6067
  Join *join= last->join;
6300
6068
  for (;last_emb != NULL; last_emb= last_emb->getEmbedding())
6301
6069
  {
6302
 
    NestedJoin *nest= last_emb->getNestedJoin();
 
6070
    nested_join_st *nest= last_emb->getNestedJoin();
6303
6071
    
6304
6072
    bool was_fully_covered= nest->is_fully_covered();
6305
6073