~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/optimizer/quick_group_min_max_select.cc

Merge Padraig

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "drizzled/optimizer/quick_range_select.h"
28
28
#include "drizzled/optimizer/sel_arg.h"
29
29
#include "drizzled/internal/m_string.h"
 
30
#include "drizzled/util/functors.h"
 
31
 
 
32
#include <vector>
30
33
 
31
34
using namespace std;
32
35
using namespace drizzled;
120
123
 
121
124
  if (min_max_arg_part)
122
125
  {
123
 
    if (my_init_dynamic_array(&min_max_ranges, sizeof(optimizer::QuickRange*), 16, 16))
124
 
      return 1;
125
 
 
126
126
    if (have_min)
127
127
    {
128
128
      if (! (min_functions= new List<Item_sum>))
160
160
        return 1;
161
161
    }
162
162
  }
163
 
  else
164
 
    min_max_ranges.elements= 0;
165
163
 
166
164
  return 0;
167
165
}
175
173
  }
176
174
  if (min_max_arg_part)
177
175
  {
178
 
    delete_dynamic(&min_max_ranges);
 
176
    for_each(min_max_ranges.begin(),
 
177
             min_max_ranges.end(),
 
178
             DeletePtr());
179
179
  }
 
180
  min_max_ranges.clear();
180
181
  free_root(&alloc,MYF(0));
181
182
  delete min_functions_it;
182
183
  delete max_functions_it;
212
213
                                   range_flag);
213
214
  if (! range)
214
215
    return true;
215
 
  if (insert_dynamic(&min_max_ranges, (unsigned char*)&range))
216
 
    return true;
 
216
  min_max_ranges.push_back(range);
217
217
  return false;
218
218
}
219
219
 
240
240
void optimizer::QuickGroupMinMaxSelect::update_key_stat()
241
241
{
242
242
  max_used_key_length= real_prefix_len;
243
 
  if (min_max_ranges.elements > 0)
 
243
  if (! min_max_ranges.empty())
244
244
  {
245
245
    optimizer::QuickRange *cur_range= NULL;
246
246
    if (have_min)
247
247
    { /* Check if the right-most range has a lower boundary. */
248
 
      get_dynamic(&min_max_ranges,
249
 
                  (unsigned char*) &cur_range,
250
 
                  min_max_ranges.elements - 1);
 
248
      cur_range= min_max_ranges.back();
251
249
      if (! (cur_range->flag & NO_MIN_RANGE))
252
250
      {
253
251
        max_used_key_length+= min_max_arg_len;
257
255
    }
258
256
    if (have_max)
259
257
    { /* Check if the left-most range has an upper boundary. */
260
 
      get_dynamic(&min_max_ranges, (unsigned char*)&cur_range, 0);
 
258
      cur_range= min_max_ranges.front();
261
259
      if (! (cur_range->flag & NO_MAX_RANGE))
262
260
      {
263
261
        max_used_key_length+= min_max_arg_len;
387
385
  int result= 0;
388
386
 
389
387
  /* Find the MIN key using the eventually extended group prefix. */
390
 
  if (min_max_ranges.elements > 0)
 
388
  if (! min_max_ranges.empty())
391
389
  {
392
390
    if ((result= next_min_in_range()))
393
391
      return result;
452
450
  int result= 0;
453
451
 
454
452
  /* Get the last key in the (possibly extended) group. */
455
 
  if (min_max_ranges.elements > 0)
 
453
  if (! min_max_ranges.empty())
456
454
    result= next_max_in_range();
457
455
  else
458
456
    result= cursor->index_read_map(record,
520
518
 
521
519
  max_key.reserve(real_prefix_len + min_max_arg_len);
522
520
 
523
 
  assert(min_max_ranges.elements > 0);
 
521
  assert(! min_max_ranges.empty());
524
522
 
525
 
  for (uint32_t range_idx= 0; range_idx < min_max_ranges.elements; range_idx++)
 
523
  for (vector<optimizer::QuickRange *>::iterator it= min_max_ranges.begin();
 
524
       it != min_max_ranges.end();
 
525
       ++it)
526
526
  { /* Search from the left-most range to the right. */
527
 
    get_dynamic(&min_max_ranges, (unsigned char*)&cur_range, range_idx);
 
527
    cur_range= *it;
528
528
 
529
529
    /*
530
530
      If the current value for the min/max argument is bigger than the right
531
531
      boundary of cur_range, there is no need to check this range.
532
532
    */
533
 
    if (range_idx != 0 && !(cur_range->flag & NO_MAX_RANGE) &&
 
533
    if (it != min_max_ranges.begin() && 
 
534
        ! (cur_range->flag & NO_MAX_RANGE) &&
534
535
        (key_cmp(min_max_arg_part,
535
536
                 (const unsigned char*) cur_range->max_key,
536
537
                 min_max_arg_len) == 1))
635
636
  basic_string<unsigned char> min_key;
636
637
  min_key.reserve(real_prefix_len + min_max_arg_len);
637
638
 
638
 
  assert(min_max_ranges.elements > 0);
 
639
  assert(! min_max_ranges.empty());
639
640
 
640
 
  for (uint32_t range_idx= min_max_ranges.elements; range_idx > 0; range_idx--)
 
641
  for (vector<optimizer::QuickRange *>::reverse_iterator rit= min_max_ranges.rbegin();
 
642
       rit != min_max_ranges.rend();
 
643
       ++rit)
641
644
  { /* Search from the right-most range to the left. */
642
 
    get_dynamic(&min_max_ranges, (unsigned char*)&cur_range, range_idx - 1);
 
645
    cur_range= *rit;
643
646
 
644
647
    /*
645
648
      If the current value for the min/max argument is smaller than the left
646
649
      boundary of cur_range, there is no need to check this range.
647
650
    */
648
 
    if (range_idx != min_max_ranges.elements &&
 
651
    if (rit != min_max_ranges.rbegin() &&
649
652
        ! (cur_range->flag & NO_MIN_RANGE) &&
650
653
        (key_cmp(min_max_arg_part,
651
654
                 (const unsigned char*) cur_range->min_key,