drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
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
28namespace drizzled {
29
30class KeyPartInfo;
31
32namespace optimizer {
33
40class QuickRangeSelect : public QuickSelectInterface
41{
42protected:
43 Cursor *cursor;
45
48 boost::dynamic_bitset<> *column_bitmap;
49 boost::dynamic_bitset<> *save_read_set;
50 boost::dynamic_bitset<> *save_write_set;
51 bool free_file;
52
53 /* Range pointers to be used when not using MRR interface */
55 QuickRange *last_range;
56
58 QuickRangeSequenceContext qr_traversal_ctx;
59 uint32_t mrr_buf_size;
60
62 KEY_PART *key_parts;
63 KeyPartInfo *key_part_info;
64
65 bool dont_free;
66
72 int cmp_next(QuickRange *range);
73
77 int cmp_prev(QuickRange *range);
78
96 bool row_in_ranges();
97
98public:
99
100 uint32_t mrr_flags;
101
102 memory::Root alloc;
103
104 QuickRangeSelect(Session *session,
105 Table *table,
106 uint32_t index_arg,
107 bool no_alloc,
108 memory::Root *parent_alloc);
109
110 ~QuickRangeSelect();
111
112 int init();
113
114 int reset(void);
115
130 int get_next();
131
132 void range_end();
133
161 int get_next_prefix(uint32_t prefix_length,
162 key_part_map keypart_map,
163 unsigned char *cur_prefix);
164
165 bool reverse_sorted() const
166 {
167 return false;
168 }
169
173 bool unique_key_range() const;
174
195 int init_ror_merged_scan(bool reuse_handler);
196
197 void save_last_pos();
198
199 int get_type() const
200 {
201 return QS_TYPE_RANGE;
202 }
203
204 void add_keys_and_lengths(std::string *key_names, std::string *used_lengths);
205
206 void add_info_string(std::string *str);
207
208 void resetCursor()
209 {
210 cursor= NULL;
211 }
212
213private:
214
215 /* Used only by QuickSelectDescending */
216 QuickRangeSelect(const QuickRangeSelect& org) : QuickSelectInterface()
217 {
218 memmove(static_cast<void *>(this), static_cast<const void *>(&org),
219 sizeof(*this));
220 /*
221 Use default MRR implementation for reverse scans. No table engine
222 currently can do an MRR scan with output in reverse index order.
223 */
224 mrr_flags|= HA_MRR_USE_DEFAULT_IMPL;
225 mrr_buf_size= 0;
226 }
227
228 friend class ::drizzled::RorIntersectReadPlan;
229
230 friend
231 QuickRangeSelect *get_quick_select_for_ref(Session *session, Table *table,
232 struct table_reference_st *ref,
233 ha_rows records);
234
235 friend bool get_quick_keys(Parameter *param,
236 QuickRangeSelect *quick,
237 KEY_PART *key,
238 SEL_ARG *key_tree,
239 unsigned char *min_key,
240 uint32_t min_key_flag,
241 unsigned char *max_key,
242 uint32_t max_key_flag);
243
244 friend QuickRangeSelect *get_quick_select(Parameter *,
245 uint32_t idx,
246 SEL_ARG *key_tree,
247 uint32_t mrr_flags,
248 uint32_t mrr_buf_size,
249 memory::Root *alloc);
250 friend class QuickSelectDescending;
251
252 friend class QuickIndexMergeSelect;
253
254 friend class QuickRorIntersectSelect;
255
256 friend class QuickGroupMinMaxSelect;
257
258 friend uint32_t quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range);
259
260 friend range_seq_t quick_range_seq_init(void *init_param,
261 uint32_t n_ranges,
262 uint32_t flags);
263
264 friend void select_describe(Join *join,
265 bool need_tmp_table,
266 bool need_order,
267 bool distinct,
268 const char *message);
269};
270
271class QuickSelectDescending : public QuickRangeSelect
272{
273public:
274
275 QuickSelectDescending(QuickRangeSelect *q,
276 uint32_t used_key_parts,
277 bool *create_err);
278
279 int get_next();
280
281 bool reverse_sorted() const
282 {
283 return true;
284 }
285
286 int get_type() const
287 {
288 return QS_TYPE_RANGE_DESC;
289 }
290
291private:
292
293 bool range_reads_after_key(QuickRange *range);
294
295 int reset(void)
296 {
297 rev_it= rev_ranges.begin();
299 }
300
301 std::vector<QuickRange *> rev_ranges;
302
303 std::vector<QuickRange *>::iterator rev_it;
304
305 uint32_t used_key_parts;
306};
307
308} /* namespace optimizer */
309
310} /* namespace drizzled */
void add_keys_and_lengths(std::string *key_names, std::string *used_lengths)
int get_next_prefix(uint32_t prefix_length, key_part_map keypart_map, unsigned char *cur_prefix)
QuickRangeSequenceContext qr_traversal_ctx
TODO: Rename this file - func.h is stupid.