Drizzled Public API Documentation

range.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 /* classes to use when handling where clause */
21 
22 #pragma once
23 
24 #include <drizzled/field.h>
25 #include <drizzled/item/sum.h>
27 
28 #include <queue>
29 
30 #include <boost/dynamic_bitset.hpp>
31 
32 namespace drizzled {
33 
34 typedef struct st_key_part
35 {
36  uint16_t key;
37  uint16_t part;
38  /* See KeyPartInfo for meaning of the next two: */
39  uint16_t store_length;
40  uint16_t length;
41  uint8_t null_bit;
46  uint8_t flag;
47  Field *field;
48 } KEY_PART;
49 
50 
51 namespace optimizer {
52 
96 {
97 public:
98  bool sorted;
99  ha_rows records;
100  double read_time;
101  Table *head;
106  uint32_t index;
119  uint32_t used_key_parts;
124  unsigned char *last_rowid;
125 
129  unsigned char *record;
130 
132  virtual ~QuickSelectInterface(){};
133 
152  virtual int init() = 0;
153 
171  virtual int reset(void) = 0;
173  virtual int get_next() = 0;
174 
176  virtual void range_end() {}
177 
178  virtual bool reverse_sorted() const = 0;
179 
180  virtual bool unique_key_range() const
181  {
182  return false;
183  }
184 
185  enum
186  {
187  QS_TYPE_RANGE= 0,
188  QS_TYPE_INDEX_MERGE= 1,
189  QS_TYPE_RANGE_DESC= 2,
190  QS_TYPE_ROR_INTERSECT= 4,
191  QS_TYPE_ROR_UNION= 5,
192  QS_TYPE_GROUP_MIN_MAX= 6
193  };
194 
196  virtual int get_type() const = 0;
197 
212  virtual int init_ror_merged_scan(bool)
213  {
214  assert(0);
215  return 1;
216  }
217 
221  virtual void save_last_pos(){};
222 
229  virtual void add_keys_and_lengths(std::string *key_names,
230  std::string *used_lengths)=0;
231 
241  virtual void add_info_string(std::string *)
242  {}
243 
248  virtual bool is_keys_used(const boost::dynamic_bitset<>& fields);
249 };
250 
256 {
257  QuickRange **first;
258  QuickRange **cur;
259  QuickRange **last;
261 
262 range_seq_t quick_range_seq_init(void *init_param, uint32_t n_ranges, uint32_t flags);
263 
264 uint32_t quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range);
265 
275 {
276  public:
279  Table *head;
281  ha_rows records;
282  double read_time;
283  key_map quick_keys;
284  key_map needed_reg;
285  table_map const_tables;
286  table_map read_tables;
287  bool free_cond;
288 
289  SqlSelect();
290  ~SqlSelect();
291  void cleanup();
292  bool check_quick(Session *session, bool force_quick_range, ha_rows limit);
293  bool skip_record();
294  int test_quick_select(Session *session, key_map keys, table_map prev_tables,
295  ha_rows limit, bool force_quick_range,
296  bool ordered_output);
297 };
298 
299 QuickRangeSelect *get_quick_select_for_ref(Session *session,
300  Table *table,
301  table_reference_st *ref,
302  ha_rows records);
303 
304 /*
305  Create a QuickRangeSelect from given key and SEL_ARG tree for that key.
306 
307  SYNOPSIS
308  get_quick_select()
309  param
310  idx Index of used key in param->key.
311  key_tree SEL_ARG tree for the used key
312  mrr_flags MRR parameter for quick select
313  mrr_buf_size MRR parameter for quick select
314  parent_alloc If not NULL, use it to allocate memory for
315  quick select data. Otherwise use quick->alloc.
316  NOTES
317  The caller must call QUICK_SELECT::init for returned quick select.
318 
319  CAUTION! This function may change session->mem_root to a memory::Root which will be
320  deallocated when the returned quick select is deleted.
321 
322  RETURN
323  NULL on error
324  otherwise created quick select
325 */
326 QuickRangeSelect *get_quick_select(Parameter *param,
327  uint32_t index,
328  SEL_ARG *key_tree,
329  uint32_t mrr_flags,
330  uint32_t mrr_buf_size,
331  memory::Root *alloc);
332 
333 uint32_t get_index_for_order(Table *table, Order *order, ha_rows limit);
334 
335 SqlSelect *make_select(Table *head,
336  table_map const_tables,
337  table_map read_tables,
338  COND *conds,
339  bool allow_null_cond,
340  int *error);
341 
342 bool get_quick_keys(Parameter *param,
343  QuickRangeSelect *quick,
344  KEY_PART *key,
345  SEL_ARG *key_tree,
346  unsigned char *min_key,
347  uint32_t min_key_flag,
348  unsigned char *max_key,
349  uint32_t max_key_flag);
350 
351 } /* namespace optimizer */
352 
353 } /* namespace drizzled */
354 
virtual void add_info_string(std::string *)
Definition: range.h:241
virtual bool is_keys_used(const boost::dynamic_bitset<> &fields)
Definition: range.cc:4125
TODO: Rename this file - func.h is stupid.
QuickSelectInterface * quick
Definition: range.h:277
virtual void add_keys_and_lengths(std::string *key_names, std::string *used_lengths)=0
internal::io_cache_st * file
Definition: range.h:280
virtual int init_ror_merged_scan(bool)
Definition: range.h:212