~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_select.cc

  • Committer: Stewart Smith
  • Date: 2011-02-10 01:03:48 UTC
  • mto: (2154.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2155.
  • Revision ID: stewart@flamingspork.com-20110210010348-5l0zh0akjahvx3vi
fix Session::tx_isolation to be getTxIsolation to follow coding style, but look weird

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
  @defgroup Query_Optimizer  Query Optimizer
23
23
  @{
24
24
*/
25
 
#include <config.h>
 
25
#include "config.h"
26
26
 
27
27
#include <string>
28
28
#include <iostream>
29
29
#include <algorithm>
30
30
#include <vector>
31
31
 
32
 
#include <drizzled/sql_select.h> /* include join.h */
33
 
 
34
 
#include <drizzled/error.h>
35
 
#include <drizzled/gettext.h>
36
 
#include <drizzled/util/test.h>
37
 
#include <drizzled/name_resolution_context_state.h>
38
 
#include <drizzled/nested_join.h>
39
 
#include <drizzled/probes.h>
40
 
#include <drizzled/show.h>
41
 
#include <drizzled/item/cache.h>
42
 
#include <drizzled/item/cmpfunc.h>
43
 
#include <drizzled/item/copy_string.h>
44
 
#include <drizzled/item/uint.h>
45
 
#include <drizzled/cached_item.h>
46
 
#include <drizzled/sql_base.h>
47
 
#include <drizzled/field/blob.h>
48
 
#include <drizzled/check_stack_overrun.h>
49
 
#include <drizzled/lock.h>
50
 
#include <drizzled/item/outer_ref.h>
51
 
#include <drizzled/index_hint.h>
52
 
#include <drizzled/records.h>
53
 
#include <drizzled/internal/iocache.h>
54
 
#include <drizzled/drizzled.h>
55
 
#include <drizzled/plugin/storage_engine.h>
56
 
 
57
 
#include <drizzled/sql_union.h>
58
 
#include <drizzled/optimizer/key_field.h>
59
 
#include <drizzled/optimizer/position.h>
60
 
#include <drizzled/optimizer/sargable_param.h>
61
 
#include <drizzled/optimizer/key_use.h>
62
 
#include <drizzled/optimizer/range.h>
63
 
#include <drizzled/optimizer/quick_range_select.h>
64
 
#include <drizzled/optimizer/quick_ror_intersect_select.h>
65
 
 
66
 
#include <drizzled/filesort.h>
67
 
#include <drizzled/sql_lex.h>
68
 
#include <drizzled/session.h>
69
 
#include <drizzled/sort_field.h>
70
 
#include <drizzled/select_result.h>
 
32
#include "drizzled/sql_select.h" /* include join.h */
 
33
 
 
34
#include "drizzled/error.h"
 
35
#include "drizzled/gettext.h"
 
36
#include "drizzled/util/test.h"
 
37
#include "drizzled/name_resolution_context_state.h"
 
38
#include "drizzled/nested_join.h"
 
39
#include "drizzled/probes.h"
 
40
#include "drizzled/show.h"
 
41
#include "drizzled/item/cache.h"
 
42
#include "drizzled/item/cmpfunc.h"
 
43
#include "drizzled/item/copy_string.h"
 
44
#include "drizzled/item/uint.h"
 
45
#include "drizzled/cached_item.h"
 
46
#include "drizzled/sql_base.h"
 
47
#include "drizzled/field/blob.h"
 
48
#include "drizzled/check_stack_overrun.h"
 
49
#include "drizzled/lock.h"
 
50
#include "drizzled/item/outer_ref.h"
 
51
#include "drizzled/index_hint.h"
 
52
#include "drizzled/records.h"
 
53
#include "drizzled/internal/iocache.h"
 
54
#include "drizzled/drizzled.h"
 
55
 
 
56
#include "drizzled/sql_union.h"
 
57
#include "drizzled/optimizer/key_field.h"
 
58
#include "drizzled/optimizer/position.h"
 
59
#include "drizzled/optimizer/sargable_param.h"
 
60
#include "drizzled/optimizer/key_use.h"
 
61
#include "drizzled/optimizer/range.h"
 
62
#include "drizzled/optimizer/quick_range_select.h"
 
63
#include "drizzled/optimizer/quick_ror_intersect_select.h"
 
64
 
 
65
#include "drizzled/filesort.h"
71
66
 
72
67
using namespace std;
73
68
 
212
207
  bool res= false;
213
208
  bool direct_ref= false;
214
209
 
215
 
  List<Item_outer_ref>::iterator ref_it(select->inner_refs_list.begin());
 
210
  List_iterator<Item_outer_ref> ref_it(select->inner_refs_list);
216
211
  while ((ref= ref_it++))
217
212
  {
218
213
    Item *item= ref->outer_ref;
219
214
    Item **item_ref= ref->ref;
220
215
    Item_ref *new_ref;
221
216
    /*
222
 
      @todo this field item already might be present in the select list.
 
217
      TODO: this field item already might be present in the select list.
223
218
      In this case instead of adding new field item we could use an
224
219
      existing one. The change will lead to less operations for copying fields,
225
220
      smaller temporary tables and less data passed through filesort.
425
420
    goto err; // 1
426
421
  }
427
422
 
428
 
  if (session->getLex()->describe & DESCRIBE_EXTENDED)
 
423
  if (session->lex->describe & DESCRIBE_EXTENDED)
429
424
  {
430
425
    join->conds_history= join->conds;
431
426
    join->having_history= (join->having?join->having:join->tmp_having);
436
431
 
437
432
  join->exec();
438
433
 
439
 
  if (session->getLex()->describe & DESCRIBE_EXTENDED)
 
434
  if (session->lex->describe & DESCRIBE_EXTENDED)
440
435
  {
441
436
    select_lex->where= join->conds_history;
442
437
    select_lex->having= join->having_history;
575
570
    substitutions.
576
571
  */
577
572
  sz= sizeof(optimizer::KeyField) *
578
 
      (((session->getLex()->current_select->cond_count+1)*2 +
579
 
        session->getLex()->current_select->between_count)*m+1);
580
 
  if (! (key_fields= (optimizer::KeyField*) session->getMemRoot()->allocate(sz)))
 
573
      (((session->lex->current_select->cond_count+1)*2 +
 
574
        session->lex->current_select->between_count)*m+1);
 
575
  if (! (key_fields= (optimizer::KeyField*) session->alloc(sz)))
581
576
    return true;
582
577
  and_level= 0;
583
578
  field= end= key_fields;
618
613
 
619
614
  /* Process ON conditions for the nested joins */
620
615
  {
621
 
    List<TableList>::iterator li(join_tab->join->join_list->begin());
 
616
    List_iterator<TableList> li(*join_tab->join->join_list);
622
617
    TableList *table;
623
618
    while ((table= li++))
624
619
    {
752
747
void add_group_and_distinct_keys(Join *join, JoinTable *join_tab)
753
748
{
754
749
  List<Item_field> indexed_fields;
755
 
  List<Item_field>::iterator indexed_fields_it(indexed_fields.begin());
 
750
  List_iterator<Item_field> indexed_fields_it(indexed_fields);
756
751
  Order      *cur_group;
757
752
  Item_field *cur_item;
758
753
  key_map possible_keys(0);
766
761
  else if (join->select_distinct)
767
762
  { /* Collect all query fields referenced in the SELECT clause. */
768
763
    List<Item> &select_items= join->fields_list;
769
 
    List<Item>::iterator select_items_it(select_items.begin());
 
764
    List_iterator<Item> select_items_it(select_items);
770
765
    Item *item;
771
766
    while ((item= select_items_it++))
772
767
      item->walk(&Item::collect_item_field_processor, 0,
1009
1004
  j->ref.key_length=length;
1010
1005
  j->ref.key=(int) key;
1011
1006
  if (!(j->ref.key_buff= (unsigned char*) session->calloc(ALIGN_SIZE(length)*2)) ||
1012
 
      !(j->ref.key_copy= (StoredKey**) session->getMemRoot()->allocate((sizeof(StoredKey*) *
 
1007
      !(j->ref.key_copy= (StoredKey**) session->alloc((sizeof(StoredKey*) *
1013
1008
               (keyparts+1)))) ||
1014
 
      !(j->ref.items=    (Item**) session->getMemRoot()->allocate(sizeof(Item*)*keyparts)) ||
1015
 
      !(j->ref.cond_guards= (bool**) session->getMemRoot()->allocate(sizeof(uint*)*keyparts)))
 
1009
      !(j->ref.items=    (Item**) session->alloc(sizeof(Item*)*keyparts)) ||
 
1010
      !(j->ref.cond_guards= (bool**) session->alloc(sizeof(uint*)*keyparts)))
1016
1011
  {
1017
1012
    return(true);
1018
1013
  }
1221
1216
*/
1222
1217
void JoinTable::cleanup()
1223
1218
{
1224
 
  safe_delete(select);
1225
 
  safe_delete(quick);
1226
 
 
 
1219
  delete select;
 
1220
  select= 0;
 
1221
  delete quick;
 
1222
  quick= 0;
1227
1223
  if (cache.buff)
1228
1224
  {
1229
1225
    size_t size= cache.end - cache.buff;
1352
1348
  bool in_upper_level= false;
1353
1349
  while (cond_equal)
1354
1350
  {
1355
 
    List<Item_equal>::iterator li(cond_equal->current_level.begin());
 
1351
    List_iterator_fast<Item_equal> li(cond_equal->current_level);
1356
1352
    while ((item= li++))
1357
1353
    {
1358
1354
      if (item->contains(field))
1517
1513
        /* Merge two multiple equalities forming a new one */
1518
1514
        left_item_equal->merge(right_item_equal);
1519
1515
        /* Remove the merged multiple equality from the list */
1520
 
        List<Item_equal>::iterator li(cond_equal->current_level.begin());
 
1516
        List_iterator<Item_equal> li(cond_equal->current_level);
1521
1517
        while ((li++) != right_item_equal) {};
1522
1518
        li.remove();
1523
1519
      }
1657
1653
                                       (Item_row *) right_item,
1658
1654
                                       cond_equal, eq_list);
1659
1655
      if (!is_converted)
1660
 
        session->getLex()->current_select->cond_count++;
 
1656
        session->lex->current_select->cond_count++;
1661
1657
    }
1662
1658
    else
1663
1659
    {
1664
1660
      is_converted= check_simple_equality(left_item, right_item, 0, cond_equal);
1665
 
      session->getLex()->current_select->cond_count++;
 
1661
      session->lex->current_select->cond_count++;
1666
1662
    }
1667
1663
 
1668
1664
    if (!is_converted)
1718
1714
    if (left_item->type() == Item::ROW_ITEM &&
1719
1715
        right_item->type() == Item::ROW_ITEM)
1720
1716
    {
1721
 
      session->getLex()->current_select->cond_count--;
 
1717
      session->lex->current_select->cond_count--;
1722
1718
      return check_row_equality(session,
1723
1719
                                (Item_row *) left_item,
1724
1720
                                (Item_row *) right_item,
1749
1745
    just an argument of a comparison predicate.
1750
1746
    The function also determines the maximum number of members in
1751
1747
    equality lists of each Item_cond_and object assigning it to
1752
 
    session->getLex()->current_select->max_equal_elems.
 
1748
    session->lex->current_select->max_equal_elems.
1753
1749
 
1754
1750
  @note
1755
1751
    Multiple equality predicate =(f1,..fn) is equivalent to the conjuction of
1806
1802
      Item_func::COND_AND_FUNC;
1807
1803
    List<Item> *args= ((Item_cond*) cond)->argument_list();
1808
1804
 
1809
 
    List<Item>::iterator li(args->begin());
 
1805
    List_iterator<Item> li(*args);
1810
1806
    Item *item;
1811
1807
 
1812
1808
    if (and_level)
1828
1824
          li.remove();
1829
1825
      }
1830
1826
 
1831
 
      List<Item_equal>::iterator it(cond_equal.current_level.begin());
 
1827
      List_iterator_fast<Item_equal> it(cond_equal.current_level);
1832
1828
      while ((item_equal= it++))
1833
1829
      {
1834
1830
        item_equal->fix_length_and_dec();
1835
1831
        item_equal->update_used_tables();
1836
 
        set_if_bigger(session->getLex()->current_select->max_equal_elems,
 
1832
        set_if_bigger(session->lex->current_select->max_equal_elems,
1837
1833
                      item_equal->members());
1838
1834
      }
1839
1835
 
1844
1840
       Make replacement of equality predicates for lower levels
1845
1841
       of the condition expression.
1846
1842
    */
1847
 
    li= args->begin();
 
1843
    li.rewind();
1848
1844
    while ((item= li++))
1849
1845
    {
1850
1846
      Item *new_item;
1892
1888
        }
1893
1889
        else
1894
1890
          item_equal= (Item_equal *) eq_list.pop();
1895
 
        set_if_bigger(session->getLex()->current_select->max_equal_elems,
 
1891
        set_if_bigger(session->lex->current_select->max_equal_elems,
1896
1892
                      item_equal->members());
1897
1893
        return item_equal;
1898
1894
      }
1905
1901
        Item_cond_and *and_cond= new Item_cond_and(eq_list);
1906
1902
        and_cond->quick_fix_field();
1907
1903
        List<Item> *args= and_cond->argument_list();
1908
 
        List<Item_equal>::iterator it(cond_equal.current_level.begin());
 
1904
        List_iterator_fast<Item_equal> it(cond_equal.current_level);
1909
1905
        while ((item_equal= it++))
1910
1906
        {
1911
1907
          item_equal->fix_length_and_dec();
1912
1908
          item_equal->update_used_tables();
1913
 
          set_if_bigger(session->getLex()->current_select->max_equal_elems,
 
1909
          set_if_bigger(session->lex->current_select->max_equal_elems,
1914
1910
                        item_equal->members());
1915
1911
        }
1916
1912
        and_cond->cond_equal= cond_equal;
2031
2027
  if (join_list)
2032
2028
  {
2033
2029
    TableList *table;
2034
 
    List<TableList>::iterator li(join_list->begin());
 
2030
    List_iterator<TableList> li(*join_list);
2035
2031
 
2036
2032
    while ((table= li++))
2037
2033
    {
2246
2242
      cond_equal= &((Item_cond_and *) cond)->cond_equal;
2247
2243
      cond_list->disjoin((List<Item> *) &cond_equal->current_level);
2248
2244
 
2249
 
      List<Item_equal>::iterator it(cond_equal->current_level.begin());
 
2245
      List_iterator_fast<Item_equal> it(cond_equal->current_level);
2250
2246
      while ((item_equal= it++))
2251
2247
      {
2252
2248
        item_equal->sort(&compare_fields_by_table_order, table_join_idx);
2253
2249
      }
2254
2250
    }
2255
2251
 
2256
 
    List<Item>::iterator li(cond_list->begin());
 
2252
    List_iterator<Item> li(*cond_list);
2257
2253
    Item *item;
2258
2254
    while ((item= li++))
2259
2255
    {
2269
2265
 
2270
2266
    if (and_level)
2271
2267
    {
2272
 
      List<Item_equal>::iterator it(cond_equal->current_level.begin());
 
2268
      List_iterator_fast<Item_equal> it(cond_equal->current_level);
2273
2269
      while ((item_equal= it++))
2274
2270
      {
2275
2271
        cond= eliminate_item_equal(cond, cond_equal->upper_levels, item_equal);
2319
2315
  if (cond->type() == Item::COND_ITEM)
2320
2316
  {
2321
2317
    List<Item> *cond_list= ((Item_cond*) cond)->argument_list();
2322
 
    List<Item>::iterator li(cond_list->begin());
 
2318
    List_iterator_fast<Item> li(*cond_list);
2323
2319
    Item *item;
2324
2320
    while ((item= li++))
2325
2321
      update_const_equal_items(item, tab);
2377
2373
  if (cond->type() == Item::COND_ITEM)
2378
2374
  {
2379
2375
    bool and_level= ((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC;
2380
 
    List<Item>::iterator li(((Item_cond*) cond)->argument_list()->begin());
 
2376
    List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
2381
2377
    Item *item;
2382
2378
    while ((item=li++))
2383
2379
      change_cond_ref_to_const(session, save_list, and_level ? cond : item, item, field, value);
2457
2453
  if (conds->type() == Item::COND_ITEM)
2458
2454
  {
2459
2455
    Item_cond *cnd= (Item_cond*) conds;
2460
 
    List<Item>::iterator li(cnd->argument_list()->begin());
 
2456
    List_iterator<Item> li(*(cnd->argument_list()));
2461
2457
    Item *item;
2462
2458
    while ((item= li++))
2463
2459
    {
2481
2477
  if (cond->type() == Item::COND_ITEM)
2482
2478
  {
2483
2479
    bool and_level= ((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC;
2484
 
    List<Item>::iterator li(((Item_cond*) cond)->argument_list()->begin());
 
2480
    List_iterator_fast<Item> li(*((Item_cond*) cond)->argument_list());
2485
2481
    Item *item;
2486
2482
    list<COND_CMP> save;
2487
2483
    while ((item=li++))
2715
2711
  {
2716
2712
    bool and_level= (((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC);
2717
2713
 
2718
 
    List<Item>::iterator li(((Item_cond*) cond)->argument_list()->begin());
 
2714
    List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
2719
2715
    Item::cond_result tmp_cond_value;
2720
2716
    bool should_fix_fields= false;
2721
2717
 
2769
2765
    {                                           
2770
2766
      /* Argument list contains only one element, so reduce it so a single item, then remove list */
2771
2767
      item= ((Item_cond*) cond)->argument_list()->head();
2772
 
      ((Item_cond*) cond)->argument_list()->clear();
 
2768
      ((Item_cond*) cond)->argument_list()->empty();
2773
2769
      return item;
2774
2770
    }
2775
2771
  }
2847
2843
  }
2848
2844
  else if (cond->const_item() && !cond->is_expensive())
2849
2845
  /*
2850
 
    @todo
 
2846
    TODO:
2851
2847
    Excluding all expensive functions is too restritive we should exclude only
2852
2848
    materialized IN subquery predicates because they can't yet be evaluated
2853
2849
    here (they need additional initialization that is done later on).
2919
2915
  {
2920
2916
    bool and_level= (((Item_cond*) cond)->functype()
2921
2917
                     == Item_func::COND_AND_FUNC);
2922
 
    List<Item>::iterator li(((Item_cond*) cond)->argument_list()->begin());
 
2918
    List_iterator_fast<Item> li(*((Item_cond*) cond)->argument_list());
2923
2919
    Item *item;
2924
2920
    while ((item=li++))
2925
2921
    {
3449
3445
    }
3450
3446
  }
3451
3447
 
3452
 
  /* @todo Why don't we do "Late NULLs Filtering" here? */
 
3448
  /* TODO: Why don't we do "Late NULLs Filtering" here? */
3453
3449
  if (cmp_buffer_with_ref(tab) ||
3454
3450
      (table->status & (STATUS_GARBAGE | STATUS_NO_PARENT | STATUS_NULL_ROW)))
3455
3451
  {
3640
3636
 
3641
3637
int test_if_quick_select(JoinTable *tab)
3642
3638
{
3643
 
  safe_delete(tab->select->quick);
3644
 
 
 
3639
  delete tab->select->quick;
 
3640
  tab->select->quick= 0;
3645
3641
  return tab->select->test_quick_select(tab->join->session, tab->keys,
3646
3642
                                        (table_map) 0, HA_POS_ERROR, 0, false);
3647
3643
}
3819
3815
        {
3820
3816
          if (!join->first_record)
3821
3817
          {
3822
 
                  List<Item>::iterator it(join->fields->begin());
 
3818
                  List_iterator_fast<Item> it(*join->fields);
3823
3819
                  Item *item;
3824
3820
            /* No matching rows for group function */
3825
3821
            join->clear();
4058
4054
      Item_cond_and *new_cond=new Item_cond_and;
4059
4055
      if (!new_cond)
4060
4056
        return (COND*) 0;
4061
 
      List<Item>::iterator li(((Item_cond*) cond)->argument_list()->begin());
 
4057
      List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
4062
4058
      Item *item;
4063
4059
      while ((item=li++))
4064
4060
      {
4088
4084
      Item_cond_or *new_cond=new Item_cond_or;
4089
4085
      if (!new_cond)
4090
4086
        return (COND*) 0;
4091
 
      List<Item>::iterator li(((Item_cond*) cond)->argument_list()->begin());
 
4087
      List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
4092
4088
      Item *item;
4093
4089
      while ((item=li++))
4094
4090
      {
4440
4436
{
4441
4437
  List<Item> *fields= (List<Item> *) data;
4442
4438
  bool part_found= 0;
4443
 
  List<Item>::iterator li(fields->begin());
 
4439
  List_iterator<Item> li(*fields);
4444
4440
  Item *item;
4445
4441
 
4446
4442
  while ((item= li++))
4525
4521
    save_quick= select->quick;
4526
4522
    /*
4527
4523
      assume results are not ordered when index merge is used
4528
 
      @todo sergeyp: Results of all index merge selects actually are ordered
 
4524
      TODO: sergeyp: Results of all index merge selects actually are ordered
4529
4525
      by clustered PK values.
4530
4526
    */
4531
4527
 
4800
4796
          tab->type= AM_NEXT;           // Read with index_first(), index_next()
4801
4797
          if (select && select->quick)
4802
4798
          {
4803
 
            safe_delete(select->quick);
 
4799
            delete select->quick;
 
4800
            select->quick= 0;
4804
4801
          }
4805
4802
          if (table->covering_keys.test(best_key))
4806
4803
          {
4873
4870
          tab->limit= 0;
4874
4871
          return 0; // Reverse sort not supported
4875
4872
        }
4876
 
        select->quick= tmp;
 
4873
        select->quick=tmp;
4877
4874
      }
4878
4875
    }
4879
4876
    else if (tab->type != AM_NEXT &&
5569
5566
    Item *item;
5570
5567
    Item_field *field;
5571
5568
    int cur_pos_in_select_list= 0;
5572
 
    List<Item>::iterator li(fields.begin());
5573
 
    List<Item_field>::iterator naf_it(session->getLex()->current_select->non_agg_fields.begin());
 
5569
    List_iterator<Item> li(fields);
 
5570
    List_iterator<Item_field> naf_it(session->lex->current_select->non_agg_fields);
5574
5571
 
5575
5572
    field= naf_it++;
5576
5573
    while (field && (item=li++))
5596
5593
            if ((*ord->item)->eq((Item*)field, 0))
5597
5594
              goto next_field;
5598
5595
          /*
5599
 
            @todo change ER_WRONG_FIELD_WITH_GROUP to more detailed ER_NON_GROUPING_FIELD_USED
 
5596
            TODO: change ER_WRONG_FIELD_WITH_GROUP to more detailed
 
5597
            ER_NON_GROUPING_FIELD_USED
5600
5598
          */
5601
5599
          my_error(ER_WRONG_FIELD_WITH_GROUP, MYF(0), field->full_name());
5602
5600
          return 1;
5625
5623
                                List<Item> &,
5626
5624
                                bool *all_order_by_fields_used)
5627
5625
{
5628
 
  List<Item>::iterator li(fields.begin());
 
5626
  List_iterator<Item> li(fields);
5629
5627
  Item *item;
5630
5628
  Order *order,*group,**prev;
5631
5629
 
5638
5636
  {
5639
5637
    if (order->in_field_list)
5640
5638
    {
5641
 
      Order *ord=(Order*) session->getMemRoot()->duplicate((char*) order,sizeof(Order));
 
5639
      Order *ord=(Order*) session->memdup((char*) order,sizeof(Order));
5642
5640
      if (!ord)
5643
5641
        return 0;
5644
5642
      *prev=ord;
5649
5647
      *all_order_by_fields_used= 0;
5650
5648
  }
5651
5649
 
5652
 
  li= fields.begin();
 
5650
  li.rewind();
5653
5651
  while ((item=li++))
5654
5652
  {
5655
5653
    if (!item->const_item() && !item->with_sum_func && !item->marker)
5689
5687
*/
5690
5688
void count_field_types(Select_Lex *select_lex, Tmp_Table_Param *param, List<Item> &fields, bool reset_with_sum_func)
5691
5689
{
5692
 
  List<Item>::iterator li(fields.begin());
 
5690
  List_iterator<Item> li(fields);
5693
5691
  Item *field;
5694
5692
 
5695
5693
  param->field_count=param->sum_func_count=param->func_count=
5746
5744
*/
5747
5745
int test_if_item_cache_changed(List<Cached_item> &list)
5748
5746
{
5749
 
  List<Cached_item>::iterator li(list.begin());
 
5747
  List_iterator<Cached_item> li(list);
5750
5748
  int idx= -1,i;
5751
5749
  Cached_item *buff;
5752
5750
 
5795
5793
                       List<Item> &all_fields)
5796
5794
{
5797
5795
  Item *pos;
5798
 
  List<Item>::iterator li(all_fields.begin());
 
5796
  List_iterator_fast<Item> li(all_fields);
5799
5797
  CopyField *copy= NULL;
5800
 
  res_selected_fields.clear();
5801
 
  res_all_fields.clear();
5802
 
  List<Item>::iterator itr(res_all_fields.begin());
 
5798
  res_selected_fields.empty();
 
5799
  res_all_fields.empty();
 
5800
  List_iterator_fast<Item> itr(res_all_fields);
5803
5801
  List<Item> extra_funcs;
5804
5802
  uint32_t i, border= all_fields.elements - elements;
5805
5803
 
5807
5805
      !(copy=param->copy_field= new CopyField[param->field_count]))
5808
5806
    goto err2;
5809
5807
 
5810
 
  param->copy_funcs.clear();
 
5808
  param->copy_funcs.empty();
5811
5809
  for (i= 0; (pos= li++); i++)
5812
5810
  {
5813
5811
    Field *field;
5876
5874
             !real_pos->with_sum_func)
5877
5875
    {                                           // Save for send fields
5878
5876
      pos= real_pos;
5879
 
      /* 
5880
 
        @todo In most cases this result will be sent to the user.
 
5877
      /* TODO:
 
5878
        In most cases this result will be sent to the user.
5881
5879
        This should be changed to use copy_int or copy_real depending
5882
5880
        on how the value is to be used: In some cases this may be an
5883
5881
        argument in a group function, like: IF(ISNULL(col),0,COUNT(*))
5931
5929
  for (; ptr != end; ptr++)
5932
5930
    (*ptr->do_copy)(ptr);
5933
5931
 
5934
 
  List<Item>::iterator it(param->copy_funcs.begin());
 
5932
  List_iterator_fast<Item> it(param->copy_funcs);
5935
5933
  Item_copy_string *item;
5936
5934
  while ((item = (Item_copy_string*) it++))
5937
5935
    item->copy();
5960
5958
                                                uint32_t elements,
5961
5959
                              List<Item> &all_fields)
5962
5960
{
5963
 
  List<Item>::iterator it(all_fields.begin());
 
5961
  List_iterator_fast<Item> it(all_fields);
5964
5962
  Item *item_field,*item;
5965
5963
 
5966
 
  res_selected_fields.clear();
5967
 
  res_all_fields.clear();
 
5964
  res_selected_fields.empty();
 
5965
  res_all_fields.empty();
5968
5966
 
5969
5967
  uint32_t i, border= all_fields.elements - elements;
5970
5968
  for (i= 0; (item= it++); i++)
6009
6007
      item_field;
6010
6008
  }
6011
6009
 
6012
 
  List<Item>::iterator itr(res_all_fields.begin());
 
6010
  List_iterator_fast<Item> itr(res_all_fields);
6013
6011
  for (i= 0; i < border; i++)
6014
6012
    itr++;
6015
6013
  itr.sublist(res_selected_fields, elements);
6039
6037
                               uint32_t elements,
6040
6038
                                                 List<Item> &all_fields)
6041
6039
{
6042
 
  List<Item>::iterator it(all_fields.begin());
 
6040
  List_iterator_fast<Item> it(all_fields);
6043
6041
  Item *item, *new_item;
6044
 
  res_selected_fields.clear();
6045
 
  res_all_fields.clear();
 
6042
  res_selected_fields.empty();
 
6043
  res_all_fields.empty();
6046
6044
 
6047
6045
  uint32_t i, border= all_fields.elements - elements;
6048
6046
  for (i= 0; (item= it++); i++)
6052
6050
      new_item;
6053
6051
  }
6054
6052
 
6055
 
  List<Item>::iterator itr(res_all_fields.begin());
 
6053
  List_iterator_fast<Item> itr(res_all_fields);
6056
6054
  for (i= 0; i < border; i++)
6057
6055
    itr++;
6058
6056
  itr.sublist(res_selected_fields, elements);
6144
6142
    /*
6145
6143
      Need to check the THD error state because Item::val_xxx() don't
6146
6144
      return error code, but can generate errors
6147
 
      @todo change it for a real status check when Item::val_xxx()
 
6145
      TODO: change it for a real status check when Item::val_xxx()
6148
6146
      are extended to return status code.
6149
6147
    */
6150
6148
    if (session->is_error())
6202
6200
  @param changed        out:  returns 1 if item contains a replaced field item
6203
6201
 
6204
6202
  @todo
6205
 
    - @todo Some functions are not null-preserving. For those functions
 
6203
    - TODO: Some functions are not null-preserving. For those functions
6206
6204
    updating of the maybe_null attribute is an overkill.
6207
6205
 
6208
6206
  @retval
6214
6212
{
6215
6213
  if (expr->arg_count)
6216
6214
  {
6217
 
    Name_resolution_context *context= &session->getLex()->current_select->context;
 
6215
    Name_resolution_context *context= &session->lex->current_select->context;
6218
6216
    Item **arg,**arg_end;
6219
6217
    bool arg_changed= false;
6220
6218
    for (arg= expr->arguments(),
6292
6290
                List<TableList> *tables, enum_query_type)
6293
6291
{
6294
6292
  /* List is reversed => we should reverse it before using */
6295
 
  List<TableList>::iterator ti(tables->begin());
6296
 
  TableList **table= (TableList **)session->getMemRoot()->allocate(sizeof(TableList*) *
 
6293
  List_iterator_fast<TableList> ti(*tables);
 
6294
  TableList **table= (TableList **)session->alloc(sizeof(TableList*) *
6297
6295
                                                tables->elements);
6298
6296
  if (table == 0)
6299
6297
    return;  // out of memory
6329
6327
 
6330
6328
  //Item List
6331
6329
  bool first= 1;
6332
 
  List<Item>::iterator it(item_list.begin());
 
6330
  List_iterator_fast<Item> it(item_list);
6333
6331
  Item *item;
6334
6332
  while ((item= it++))
6335
6333
  {
6342
6340
 
6343
6341
  /*
6344
6342
    from clause
6345
 
    @todo support USING/FORCE/IGNORE index
 
6343
    TODO: support USING/FORCE/IGNORE index
6346
6344
  */
6347
6345
  if (table_list.elements)
6348
6346
  {