Drizzled Public API Documentation

range_param.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 <boost/dynamic_bitset.hpp>
23 
24 #include <drizzled/field.h>
25 
26 namespace drizzled {
27 
28 typedef struct st_key_part KEY_PART;
29 
30 namespace optimizer {
31 
33 {
34 public:
35  RorScanInfo()
36  :
37  idx(0),
38  keynr(0),
39  records(0),
40  sel_arg(NULL),
41  covered_fields(0),
42  covered_fields_size(0),
43  used_fields_covered(0),
44  key_rec_length(0),
45  index_read_cost(0.0),
46  first_uncovered_field(0),
47  key_components(0)
48  {}
49 
50  boost::dynamic_bitset<> bitsToBitset() const;
51 
52  void subtractBitset(const boost::dynamic_bitset<>& in_bitset);
53 
54  uint32_t findFirstNotSet() const;
55 
56  size_t getBitCount() const;
57 
58  uint32_t idx; /* # of used key in param->keys */
59  uint32_t keynr; /* # of used key in table */
60  ha_rows records; /* estimate of # records this scan will return */
61 
62  /* Set of intervals over key fields that will be used for row retrieval. */
63  optimizer::SEL_ARG *sel_arg;
64 
65  /* Fields used in the query and covered by this ROR scan. */
66  uint64_t covered_fields;
67  size_t covered_fields_size;
68  uint32_t used_fields_covered; /* # of set bits in covered_fields */
69  int key_rec_length; /* length of key record (including rowid) */
70 
71  /*
72  Cost of reading all index records with values in sel_arg intervals set
73  (assuming there is no need to access full table records)
74  */
75  double index_read_cost;
76  uint32_t first_uncovered_field; /* first unused bit in covered_fields */
77  uint32_t key_components; /* # of parts in the key */
78 };
79 
81 {
82 public:
83 
85  :
86  session(NULL),
87  table(NULL),
88  cond(NULL),
89  prev_tables(),
90  read_tables(),
91  current_table(),
92  key_parts(NULL),
93  key_parts_end(NULL),
94  mem_root(NULL),
95  old_root(NULL),
96  keys(0),
97  using_real_indexes(false),
98  remove_jump_scans(false),
99  alloced_sel_args(0),
100  force_default_mrr(false)
101  {}
102 
103  Session *session; /* Current thread handle */
104  Table *table; /* Table being analyzed */
105  COND *cond; /* Used inside get_mm_tree(). */
106  table_map prev_tables;
107  table_map read_tables;
108  table_map current_table; /* Bit of the table being analyzed */
109 
110  /* Array of parts of all keys for which range analysis is performed */
111  KEY_PART *key_parts;
112  KEY_PART *key_parts_end;
113  memory::Root *mem_root; /* Memory that will be freed when range analysis completes */
114  memory::Root *old_root; /* Memory that will last until the query end */
115  /*
116  Number of indexes used in range analysis (In SEL_TREE::keys only first
117  #keys elements are not empty)
118  */
119  uint32_t keys;
120 
121  /*
122  If true, the index descriptions describe real indexes (and it is ok to
123  call field->optimize_range(real_keynr[...], ...).
124  Otherwise index description describes fake indexes.
125  */
126  bool using_real_indexes;
127 
128  bool remove_jump_scans;
129 
130  /*
131  used_key_no -> table_key_no translation table. Only makes sense if
132  using_real_indexes==true
133  */
134  uint32_t real_keynr[MAX_KEY];
135  /* Number of SEL_ARG objects allocated by optimizer::SEL_ARG::clone_tree operations */
136  uint32_t alloced_sel_args;
137  bool force_default_mrr;
138 };
139 
140 class Parameter : public RangeParameter
141 {
142 public:
143 
144  Parameter()
145  :
146  RangeParameter(),
147  max_key_part(0),
148  range_count(0),
149  quick(false),
150  needed_fields(),
151  tmp_covered_fields(),
152  needed_reg(NULL),
153  imerge_cost_buff(NULL),
154  imerge_cost_buff_size(0),
155  is_ror_scan(false),
156  n_ranges(0)
157  {}
158 
159  KEY_PART *key[MAX_KEY]; /* First key parts of keys used in the query */
160  uint32_t max_key_part;
161  /* Number of ranges in the last checked tree->key */
162  uint32_t range_count;
163  unsigned char min_key[MAX_KEY_LENGTH+MAX_FIELD_WIDTH];
164  unsigned char max_key[MAX_KEY_LENGTH+MAX_FIELD_WIDTH];
165  bool quick; // Don't calulate possible keys
166 
167  boost::dynamic_bitset<> needed_fields; /* bitmask of fields needed by the query */
168  boost::dynamic_bitset<> tmp_covered_fields;
169 
170  key_map *needed_reg; /* ptr to SqlSelect::needed_reg */
171 
172  uint32_t *imerge_cost_buff; /* buffer for index_merge cost estimates */
173  uint32_t imerge_cost_buff_size; /* size of the buffer */
174 
175  /* true if last checked tree->key can be used for ROR-scan */
176  bool is_ror_scan;
177  /* Number of ranges in the last checked tree->key */
178  uint32_t n_ranges;
179 };
180 
181 } /* namespace optimizer */
182 
183 } /* namespace drizzled */
184