~ubuntu-branches/ubuntu/quantal/drizzle/quantal

« back to all changes in this revision

Viewing changes to drizzled/optimizer/quick_range_select.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.2.11) (2.1.16 sid)
  • Revision ID: package-import@ubuntu.com-20120619104649-9ij634mxm4x8pp4l
Tags: 1:7.1.36-stable-1ubuntu1
* Merge from Debian unstable. (LP: #987575)
  Remaining changes:
  - Added upstart script.
* debian/drizzle.upstart: dropped logger since upstart logs job
  output now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include <drizzled/current_session.h>
27
27
#include <drizzled/key.h>
28
28
#include <drizzled/table.h>
 
29
#include <drizzled/util/test.h>
 
30
#include <drizzled/system_variables.h>
29
31
 
30
32
#include <fcntl.h>
31
33
 
32
34
using namespace std;
33
35
 
34
 
namespace drizzled
35
 
{
 
36
namespace drizzled {
36
37
 
37
38
 
38
39
optimizer::QuickRangeSelect::QuickRangeSelect(Session *session,
61
62
  index= key_nr;
62
63
  head= table;
63
64
  key_part_info= head->key_info[index].key_part;
64
 
  my_init_dynamic_array(&ranges, sizeof(optimizer::QuickRange*), 16, 16);
 
65
  ranges.init(sizeof(optimizer::QuickRange*), 16, 16);
65
66
 
66
67
  /* 'session' is not accessible in QuickRangeSelect::reset(). */
67
68
  mrr_buf_size= session->variables.read_rnd_buff_size;
69
70
  if (! no_alloc && ! parent_alloc)
70
71
  {
71
72
    // Allocates everything through the internal memroot
72
 
    memory::init_sql_alloc(&alloc, session->variables.range_alloc_block_size, 0);
 
73
    alloc.init(session->variables.range_alloc_block_size);
73
74
    session->mem_root= &alloc;
74
75
  }
75
76
  else
120
121
        delete cursor;
121
122
      }
122
123
    }
123
 
    delete_dynamic(&ranges); /* ranges are allocated in alloc */
 
124
    ranges.free(); /* ranges are allocated in alloc */
124
125
    delete column_bitmap;
125
126
    alloc.free_root(MYF(0));
126
127
  }
130
131
 
131
132
int optimizer::QuickRangeSelect::init_ror_merged_scan(bool reuse_handler)
132
133
{
133
 
  Cursor *save_file= cursor, *org_file;
134
 
  Session *session;
 
134
  Cursor* org_file;
 
135
  Cursor* save_file= cursor;
 
136
  Session* session;
135
137
 
136
138
  in_ror_merged_scan= 1;
137
139
  if (reuse_handler)
152
154
  }
153
155
 
154
156
  session= head->in_use;
155
 
  if (! (cursor= head->cursor->clone(session->mem_root)))
 
157
  if (not (cursor= head->cursor->clone(session->mem_root)))
156
158
  {
157
159
    /*
158
160
      Manually set the error flag. Note: there seems to be quite a few
190
192
  org_file= head->cursor;
191
193
  head->cursor= cursor;
192
194
  /* We don't have to set 'head->keyread' here as the 'cursor' is unique */
193
 
  if (! head->no_keyread)
 
195
  if (not head->no_keyread)
194
196
  {
195
197
    head->key_read= 1;
196
198
    head->mark_columns_used_by_index(index);
449
451
  which handle the ranges and implement the get_next() function.  But
450
452
  for now, this seems to work right at least.
451
453
 */
452
 
optimizer::QuickSelectDescending::QuickSelectDescending(optimizer::QuickRangeSelect *q, uint32_t, bool *)
 
454
optimizer::QuickSelectDescending::QuickSelectDescending(optimizer::QuickRangeSelect *q, uint32_t used_key_parts_arg, bool *)
453
455
  :
454
 
    optimizer::QuickRangeSelect(*q)
 
456
  optimizer::QuickRangeSelect(*q),
 
457
  used_key_parts(used_key_parts_arg)
455
458
{
456
459
  optimizer::QuickRange **pr= (optimizer::QuickRange**) ranges.buffer;
457
460
  optimizer::QuickRange **end_range= pr + ranges.size();
462
465
  rev_it= rev_ranges.begin();
463
466
 
464
467
  /* Remove EQ_RANGE flag for keys that are not using the full key */
465
 
  for (vector<optimizer::QuickRange *>::iterator it= rev_ranges.begin();
466
 
       it != rev_ranges.end();
467
 
       ++it)
 
468
  BOOST_FOREACH(QuickRange* it, rev_ranges)
468
469
  {
469
 
    optimizer::QuickRange *r= *it;
470
 
    if ((r->flag & EQ_RANGE) &&
471
 
        head->key_info[index].key_length != r->max_length)
 
470
    if ((it->flag & EQ_RANGE) && head->key_info[index].key_length != it->max_length)
472
471
    {
473
 
      r->flag&= ~EQ_RANGE;
 
472
      it->flag&= ~EQ_RANGE;
474
473
    }
475
474
  }
476
475
  q->dont_free= 1; // Don't free shared mem
495
494
    int result;
496
495
    if (last_range)
497
496
    {                                           // Already read through key
498
 
      result= ((last_range->flag & EQ_RANGE) ?
 
497
      result= ((last_range->flag & EQ_RANGE &&
 
498
               used_key_parts <= head->key_info[index].key_parts) ?
499
499
                           cursor->index_next_same(record, last_range->min_key,
500
500
                                                                     last_range->min_length) :
501
501
                           cursor->index_prev(record));
526
526
      continue;
527
527
    }
528
528
 
529
 
    if (last_range->flag & EQ_RANGE)
 
529
    if (last_range->flag & EQ_RANGE
 
530
        && used_key_parts <= head->key_info[index].key_parts)
530
531
    {
531
532
      result = cursor->index_read_map(record,
532
533
                                      last_range->max_key,
536
537
    else
537
538
    {
538
539
      assert(last_range->flag & NEAR_MAX ||
 
540
             (last_range->flag & EQ_RANGE &&
 
541
              used_key_parts > head->key_info[index].key_parts) ||
539
542
             range_reads_after_key(last_range));
540
543
      result= cursor->index_read_map(record,
541
544
                                     last_range->max_key,