Drizzled Public API Documentation

quick_range_select.h
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2008-2009 Sun Microsystems, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #pragma once
21 
22 #include <drizzled/dynamic_array.h>
23 #include <drizzled/optimizer/range.h>
24 
25 #include <boost/dynamic_bitset.hpp>
26 #include <vector>
27 
28 namespace drizzled {
29 namespace optimizer {
30 
38 {
39 protected:
40  Cursor *cursor;
45  boost::dynamic_bitset<> *column_bitmap;
46  boost::dynamic_bitset<> *save_read_set;
47  boost::dynamic_bitset<> *save_write_set;
48  bool free_file;
50  /* Range pointers to be used when not using MRR interface */
52  QuickRange *last_range;
53 
56  uint32_t mrr_buf_size;
60  KeyPartInfo *key_part_info;
61 
62  bool dont_free;
69  int cmp_next(QuickRange *range);
70 
74  int cmp_prev(QuickRange *range);
75 
93  bool row_in_ranges();
94 
95 public:
96 
97  uint32_t mrr_flags;
99  memory::Root alloc;
100 
101  QuickRangeSelect(Session *session,
102  Table *table,
103  uint32_t index_arg,
104  bool no_alloc,
105  memory::Root *parent_alloc);
106 
107  ~QuickRangeSelect();
108 
109  int init();
110 
111  int reset(void);
112 
127  int get_next();
128 
129  void range_end();
130 
158  int get_next_prefix(uint32_t prefix_length,
159  key_part_map keypart_map,
160  unsigned char *cur_prefix);
161 
162  bool reverse_sorted() const
163  {
164  return false;
165  }
166 
170  bool unique_key_range() const;
171 
192  int init_ror_merged_scan(bool reuse_handler);
193 
194  void save_last_pos();
195 
196  int get_type() const
197  {
198  return QS_TYPE_RANGE;
199  }
200 
201  void add_keys_and_lengths(std::string *key_names, std::string *used_lengths);
202 
203  void add_info_string(std::string *str);
204 
205  void resetCursor()
206  {
207  cursor= NULL;
208  }
209 
210 private:
211 
212  /* Used only by QuickSelectDescending */
213  QuickRangeSelect(const QuickRangeSelect& org) : QuickSelectInterface()
214  {
215  memmove(this, &org, sizeof(*this));
216  /*
217  Use default MRR implementation for reverse scans. No table engine
218  currently can do an MRR scan with output in reverse index order.
219  */
220  mrr_flags|= HA_MRR_USE_DEFAULT_IMPL;
221  mrr_buf_size= 0;
222  }
223 
224  friend class ::drizzled::RorIntersectReadPlan;
225 
226  friend
227  QuickRangeSelect *get_quick_select_for_ref(Session *session, Table *table,
228  struct table_reference_st *ref,
229  ha_rows records);
230 
231  friend bool get_quick_keys(Parameter *param,
232  QuickRangeSelect *quick,
233  KEY_PART *key,
234  SEL_ARG *key_tree,
235  unsigned char *min_key,
236  uint32_t min_key_flag,
237  unsigned char *max_key,
238  uint32_t max_key_flag);
239 
240  friend QuickRangeSelect *get_quick_select(Parameter *,
241  uint32_t idx,
242  SEL_ARG *key_tree,
243  uint32_t mrr_flags,
244  uint32_t mrr_buf_size,
245  memory::Root *alloc);
246  friend class QuickSelectDescending;
247 
248  friend class QuickIndexMergeSelect;
249 
250  friend class QuickRorIntersectSelect;
251 
252  friend class QuickGroupMinMaxSelect;
253 
254  friend uint32_t quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range);
255 
256  friend range_seq_t quick_range_seq_init(void *init_param,
257  uint32_t n_ranges,
258  uint32_t flags);
259 
260  friend void select_describe(Join *join,
261  bool need_tmp_table,
262  bool need_order,
263  bool distinct,
264  const char *message);
265 };
266 
268 {
269 public:
270 
272  uint32_t used_key_parts,
273  bool *create_err);
274 
275  int get_next();
276 
277  bool reverse_sorted() const
278  {
279  return true;
280  }
281 
282  int get_type() const
283  {
284  return QS_TYPE_RANGE_DESC;
285  }
286 
287 private:
288 
289  bool range_reads_after_key(QuickRange *range);
290 
291  int reset(void)
292  {
293  rev_it= rev_ranges.begin();
294  return QuickRangeSelect::reset();
295  }
296 
297  std::vector<QuickRange *> rev_ranges;
298 
299  std::vector<QuickRange *>::iterator rev_it;
300 
301  uint32_t used_key_parts;
302 };
303 
304 } /* namespace optimizer */
305 
306 } /* namespace drizzled */
307