~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/optimizer/quick_range_select.h

  • Committer: Monty Taylor
  • Date: 2010-03-02 19:10:25 UTC
  • mto: (1317.1.8)
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: mordred@inaugust.com-20100302191025-zoxjz4xwkoa6160h
Prevent unauthorized users from changing schema.

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
22
22
 
23
23
#include "drizzled/optimizer/range.h"
24
24
 
25
 
#include <boost/dynamic_bitset.hpp>
26
25
#include <vector>
27
26
 
28
27
namespace drizzled
41
40
 */
42
41
class QuickRangeSelect : public QuickSelectInterface
43
42
{
44
 
protected:
45
 
  Cursor *cursor;
46
 
  DYNAMIC_ARRAY ranges; /**< ordered array of range ptrs */
47
 
 
48
 
  /** Members to deal with case when this quick select is a ROR-merged scan */
49
 
  bool in_ror_merged_scan;
50
 
  boost::dynamic_bitset<> *column_bitmap;
51
 
  boost::dynamic_bitset<> *save_read_set;
52
 
  boost::dynamic_bitset<> *save_write_set;
53
 
  bool free_file; /**< True when this->file is "owned" by this quick select */
54
 
 
55
 
  /* Range pointers to be used when not using MRR interface */
56
 
  QuickRange **cur_range; /**< current element in ranges  */
57
 
  QuickRange *last_range;
58
 
 
59
 
  /** Members needed to use the MRR interface */
60
 
  QuickRangeSequenceContext qr_traversal_ctx;
61
 
  uint32_t mrr_buf_size; /**< copy from session->variables.read_rnd_buff_size */
62
 
 
63
 
  /** Info about index we're scanning */
64
 
  KEY_PART *key_parts;
65
 
  KeyPartInfo *key_part_info;
66
 
 
67
 
  bool dont_free; /**< Used by QuickSelectDescending */
68
 
 
69
 
  /**
70
 
   * Compare if found key is over max-value
71
 
   * @return 0 if key <= range->max_key
72
 
   * @todo: Figure out why can't this function be as simple as cmp_prev().
73
 
   */
74
 
  int cmp_next(QuickRange *range);
75
 
 
76
 
  /**
77
 
   * @return 0 if found key is inside range (found key >= range->min_key).
78
 
   */
79
 
  int cmp_prev(QuickRange *range);
80
 
 
81
 
  /**
82
 
   * Check if current row will be retrieved by this QuickRangeSelect
83
 
   *
84
 
   * NOTES
85
 
   * It is assumed that currently a scan is being done on another index
86
 
   * which reads all necessary parts of the index that is scanned by this
87
 
   * quick select.
88
 
   * The implementation does a binary search on sorted array of disjoint
89
 
   * ranges, without taking size of range into account.
90
 
   *
91
 
   * This function is used to filter out clustered PK scan rows in
92
 
   * index_merge quick select.
93
 
   *
94
 
   * RETURN
95
 
   * @retval true  if current row will be retrieved by this quick select
96
 
   * false if not
97
 
   */
98
 
  bool row_in_ranges();
99
43
 
100
44
public:
101
45
 
107
51
                     Table *table,
108
52
                     uint32_t index_arg,
109
53
                     bool no_alloc,
110
 
                     memory::Root *parent_alloc);
 
54
                     memory::Root *parent_alloc,
 
55
                     bool *create_err);
111
56
 
112
57
  ~QuickRangeSelect();
113
58
 
122
67
   * QuickRangeSelect::get_next()
123
68
   *
124
69
   * NOTES
125
 
   * Record is read into table->getInsertRecord()
 
70
   * Record is read into table->record[0]
126
71
   *
127
72
   * RETURN
128
73
   * @retval 0                  Found row
212
157
    cursor= NULL;
213
158
  }
214
159
 
 
160
protected:
 
161
 
 
162
  Cursor *cursor;
 
163
  DYNAMIC_ARRAY ranges; /**< ordered array of range ptrs */
 
164
 
 
165
  /** Members to deal with case when this quick select is a ROR-merged scan */
 
166
  bool in_ror_merged_scan;
 
167
  MyBitmap column_bitmap;
 
168
  MyBitmap *save_read_set;
 
169
  MyBitmap *save_write_set;
 
170
  bool free_file; /**< True when this->file is "owned" by this quick select */
 
171
 
 
172
  /* Range pointers to be used when not using MRR interface */
 
173
  QuickRange **cur_range; /**< current element in ranges  */
 
174
  QuickRange *last_range;
 
175
 
 
176
  /** Members needed to use the MRR interface */
 
177
  QuickRangeSequenceContext qr_traversal_ctx;
 
178
  uint32_t mrr_buf_size; /**< copy from session->variables.read_rnd_buff_size */
 
179
  HANDLER_BUFFER *mrr_buf_desc; /**< the Cursor buffer */
 
180
 
 
181
  /** Info about index we're scanning */
 
182
  KEY_PART *key_parts;
 
183
  KEY_PART_INFO *key_part_info;
 
184
 
 
185
  bool dont_free; /**< Used by QuickSelectDescending */
 
186
 
 
187
  /**
 
188
   * Compare if found key is over max-value
 
189
   * @return 0 if key <= range->max_key
 
190
   * @todo: Figure out why can't this function be as simple as cmp_prev().
 
191
   */
 
192
  int cmp_next(QuickRange *range);
 
193
 
 
194
  /**
 
195
   * @return 0 if found key is inside range (found key >= range->min_key).
 
196
   */
 
197
  int cmp_prev(QuickRange *range);
 
198
 
 
199
  /**
 
200
   * Check if current row will be retrieved by this QuickRangeSelect
 
201
   *
 
202
   * NOTES
 
203
   * It is assumed that currently a scan is being done on another index
 
204
   * which reads all necessary parts of the index that is scanned by this
 
205
   * quick select.
 
206
   * The implementation does a binary search on sorted array of disjoint
 
207
   * ranges, without taking size of range into account.
 
208
   *
 
209
   * This function is used to filter out clustered PK scan rows in
 
210
   * index_merge quick select.
 
211
   *
 
212
   * RETURN
 
213
   * @retval true  if current row will be retrieved by this quick select
 
214
   * false if not
 
215
   */
 
216
  bool row_in_ranges();
 
217
 
215
218
private:
216
219
 
217
220
  /* Used only by QuickSelectDescending */
222
225
      Use default MRR implementation for reverse scans. No table engine
223
226
      currently can do an MRR scan with output in reverse index order.
224
227
    */
 
228
    mrr_buf_desc= NULL;
225
229
    mrr_flags|= HA_MRR_USE_DEFAULT_IMPL;
226
230
    mrr_buf_size= 0;
227
231
  }
262
266
                                          uint32_t n_ranges, 
263
267
                                          uint32_t flags);
264
268
 
265
 
  friend void select_describe(Join *join, 
 
269
  friend void select_describe(JOIN *join, 
266
270
                              bool need_tmp_table, 
267
271
                              bool need_order,
268
272
                              bool distinct,