~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/optimizer/sum.cc

  • Committer: Brian Aker
  • Date: 2010-05-28 01:36:09 UTC
  • Revision ID: brian@gaz-20100528013609-lvsd6znyufrpmddk
Rollup patch for hiding tableshare.

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
51
51
  (assuming a index for column d of table t2 is defined)
52
52
*/
53
53
 
54
 
#include <config.h>
55
 
 
56
 
#include <drizzled/sql_select.h>
57
 
#include <drizzled/item/sum.h>
58
 
#include <drizzled/item/cmpfunc.h>
59
 
#include <drizzled/optimizer/sum.h>
60
 
#include <drizzled/plugin/storage_engine.h>
61
 
#include <drizzled/table_list.h>
62
 
#include <drizzled/key.h>
 
54
#include "config.h"
 
55
#include "drizzled/sql_select.h"
 
56
#include "drizzled/item/sum.h"
 
57
#include "drizzled/item/cmpfunc.h"
 
58
#include "drizzled/optimizer/sum.h"
63
59
 
64
60
namespace drizzled
65
61
{
114
110
 
115
111
int optimizer::sum_query(TableList *tables, List<Item> &all_fields, COND *conds)
116
112
{
117
 
  List<Item>::iterator it(all_fields.begin());
 
113
  List_iterator_fast<Item> it(all_fields);
118
114
  int const_result= 1;
119
115
  bool recalc_const_item= false;
120
116
  uint64_t count= 1;
139
135
  for (TableList *tl= tables; tl; tl= tl->next_leaf)
140
136
  {
141
137
    TableList *embedded= NULL;
142
 
    for (embedded= tl; embedded; embedded= embedded->getEmbedding())
 
138
    for (embedded= tl; embedded; embedded= embedded->embedding)
143
139
    {
144
140
      if (embedded->on_expr)
145
141
        break;
243
239
 
244
240
              ref.key_buff= key_buff;
245
241
              Item_field *item_field= (Item_field*) (expr->real_item());
246
 
              Table *table= item_field->field->getTable();
 
242
              Table *table= item_field->field->table;
247
243
 
248
244
              /*
249
245
                 Look for a partial key that can be used for optimization.
266
262
                break;
267
263
              }
268
264
              error= table->cursor->startIndexScan(static_cast<uint32_t>(ref.key), 1);
269
 
              if (error)
270
 
              {
271
 
                if (table->key_read)
272
 
                {
273
 
                  table->key_read= 0;
274
 
                  table->cursor->extra(HA_EXTRA_NO_KEYREAD);
275
 
                }
276
 
                table->print_error(error, MYF(0));
277
 
                return error;
278
 
              }
279
265
 
280
266
              if (! ref.key_length)
281
267
              {
421
407
 
422
408
              ref.key_buff= key_buff;
423
409
              Item_field *item_field= (Item_field*) (expr->real_item());
424
 
              Table *table= item_field->field->getTable();
 
410
              Table *table= item_field->field->table;
425
411
 
426
412
              /*
427
413
                 Look for a partial key that can be used for optimization.
676
662
 
677
663
  field->setWriteSet();
678
664
 
679
 
  if (! (cond->used_tables() & field->getTable()->map))
 
665
  if (! (cond->used_tables() & field->table->map))
680
666
  {
681
667
    /* Condition doesn't restrict the used table */
682
668
    return 1;
689
675
    }
690
676
 
691
677
    /* AND */
692
 
    List<Item>::iterator li(((Item_cond*) cond)->argument_list()->begin());
 
678
    List_iterator_fast<Item> li(*((Item_cond*) cond)->argument_list());
693
679
    Item *item;
694
680
    while ((item= li++))
695
681
    {
921
907
    return 0; // Not key field
922
908
  }
923
909
 
924
 
  Table *table= field->getTable();
 
910
  Table *table= field->table;
925
911
  uint32_t idx= 0;
926
912
 
927
913
  KeyInfo *keyinfo,*keyinfo_end= NULL;
928
 
  for (keyinfo= table->key_info, keyinfo_end= keyinfo+table->getShare()->sizeKeys();
 
914
  for (keyinfo= table->key_info, keyinfo_end= keyinfo+table->getShare()->keys;
929
915
       keyinfo != keyinfo_end;
930
916
       keyinfo++,idx++)
931
917
  {
952
938
      }
953
939
 
954
940
      /* Check whether the index component is partial */
955
 
      Field *part_field= table->getField(part->fieldnr-1);
 
941
      Field *part_field= table->field[part->fieldnr-1];
956
942
      part_field->setWriteSet();
957
943
 
958
944
      if ((part_field->flags & BLOB_FLAG) ||
1042
1028
                           uint32_t range_fl,
1043
1029
                           uint32_t prefix_len)
1044
1030
{
1045
 
  if (key_cmp_if_same(field->getTable(), ref->key_buff, ref->key, prefix_len))
 
1031
  if (key_cmp_if_same(field->table, ref->key_buff, ref->key, prefix_len))
1046
1032
  {
1047
1033
    return 1;
1048
1034
  }
1071
1057
  /* If AND/OR condition */
1072
1058
  if (cond->type() == Item::COND_ITEM)
1073
1059
  {
1074
 
    List<Item>::iterator li(((Item_cond*) cond)->argument_list()->begin());
 
1060
    List_iterator_fast<Item> li(*((Item_cond*) cond)->argument_list());
1075
1061
    Item *item;
1076
1062
    while ((item= li++))
1077
1063
    {
1083
1069
    return 0;
1084
1070
  }
1085
1071
 
1086
 
  if (cond->used_tables() != field->getTable()->map)
 
1072
  if (cond->used_tables() != field->table->map)
1087
1073
  {
1088
1074
    return 0;
1089
1075
  }