Drizzled Public API Documentation

table_read_plan.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/memory/sql_alloc.h>
23 #include <drizzled/util/functors.h>
24 #include <algorithm>
25 
26 namespace drizzled {
27 namespace optimizer {
28 
29 /*
30  Table rows retrieval plan. Range optimizer creates QuickSelectInterface-derived
31  objects from table read plans.
32 */
34 {
35 public:
36  /*
37  Plan read cost, with or without cost of full row retrieval, depending
38  on plan creation parameters.
39  */
40  double read_cost;
41  ha_rows records; /* estimate of #rows to be examined */
42 
43  /*
44  If true, the scan returns rows in rowid order. This is used only for
45  scans that can be both ROR and non-ROR.
46  */
47  bool is_ror;
48 
49  /*
50  Create quick select for this plan.
51  SYNOPSIS
52  make_quick()
53  param Parameter from test_quick_select
54  retrieve_full_rows If true, created quick select will do full record
55  retrieval.
56  parent_alloc Memory pool to use, if any.
57 
58  NOTES
59  retrieve_full_rows is ignored by some implementations.
60 
61  RETURN
62  created quick select
63  NULL on any error.
64  */
65  virtual QuickSelectInterface *make_quick(Parameter *param,
66  bool retrieve_full_rows,
67  memory::Root *parent_alloc= NULL) = 0;
68 
69  virtual ~TableReadPlan() {} /* Remove gcc warning */
70 };
71 
72 
73 /*
74  Plan for a QuickRangeSelect scan.
75  RangeReadPlan::make_quick ignores retrieve_full_rows parameter because
76  QuickRangeSelect doesn't distinguish between 'index only' scans and full
77  record retrieval scans.
78 */
80 {
81 public:
82  SEL_ARG *key; /* set of intervals to be used in "range" method retrieval */
83  uint32_t key_idx; /* key number in Parameter::key */
84  uint32_t mrr_flags;
85  uint32_t mrr_buf_size;
86 
87  RangeReadPlan(SEL_ARG *key_arg, uint32_t idx_arg, uint32_t mrr_flags_arg)
88  :
89  key(key_arg),
90  key_idx(idx_arg),
91  mrr_flags(mrr_flags_arg)
92  {}
93 
94  QuickSelectInterface *make_quick(Parameter *param, bool, memory::Root *parent_alloc);
95 };
96 
97 
98 /* Plan for QuickRorIntersectSelect scan. */
100 {
101 public:
102  QuickSelectInterface *make_quick(Parameter *param,
103  bool retrieve_full_rows,
104  memory::Root *parent_alloc);
105 
106  /* Array of pointers to ROR range scans used in this intersection */
107  RorScanInfo **first_scan;
108  RorScanInfo **last_scan; /* End of the above array */
109  RorScanInfo *cpk_scan; /* Clustered PK scan, if there is one */
110 
111  bool is_covering; /* true if no row retrieval phase is necessary */
112  double index_scan_costs; /* SUM(cost(index_scan)) */
113 
114 };
115 
116 
117 /*
118  Plan for QuickRorUnionSelect scan.
119  QuickRorUnionSelect always retrieves full rows, so retrieve_full_rows
120  is ignored by make_quick.
121 */
122 
124 {
125 public:
126  QuickSelectInterface *make_quick(Parameter *param,
127  bool retrieve_full_rows,
128  memory::Root *parent_alloc);
129  TableReadPlan **first_ror; /* array of ptrs to plans for merged scans */
130  TableReadPlan **last_ror; /* end of the above array */
131 };
132 
133 
134 /*
135  Plan for QuickIndexMergeSelect scan.
136  QuickRorIntersectSelect always retrieves full rows, so retrieve_full_rows
137  is ignored by make_quick.
138 */
139 
141 {
142 public:
143  QuickSelectInterface *make_quick(Parameter *param,
144  bool retrieve_full_rows,
145  memory::Root *parent_alloc);
146  RangeReadPlan **range_scans; /* array of ptrs to plans of merged scans */
147  RangeReadPlan **range_scans_end; /* end of the array */
148 };
149 
150 
151 /*
152  Plan for a QuickGroupMinMaxSelect scan.
153 */
154 
156 {
157 private:
158  bool have_min;
159  bool have_max;
160  KeyPartInfo *min_max_arg_part;
161  uint32_t group_prefix_len;
162  uint32_t used_key_parts;
163  uint32_t group_key_parts;
164  KeyInfo *index_info;
165  uint32_t index;
166  uint32_t key_infix_len;
167  unsigned char key_infix[MAX_KEY_LENGTH];
168  SEL_TREE *range_tree; /* Represents all range predicates in the query. */
169  SEL_ARG *index_tree; /* The SEL_ARG sub-tree corresponding to index_info. */
170  uint32_t param_idx; /* Index of used key in param->key. */
171  /* Number of records selected by the ranges in index_tree. */
172 public:
173  ha_rows quick_prefix_records;
174 
175 public:
176  GroupMinMaxReadPlan(bool have_min_arg,
177  bool have_max_arg,
178  KeyPartInfo *min_max_arg_part_arg,
179  uint32_t group_prefix_len_arg,
180  uint32_t used_key_parts_arg,
181  uint32_t group_key_parts_arg,
182  KeyInfo *index_info_arg,
183  uint32_t index_arg,
184  uint32_t key_infix_len_arg,
185  unsigned char *key_infix_arg,
186  SEL_TREE *tree_arg,
187  SEL_ARG *index_tree_arg,
188  uint32_t param_idx_arg,
189  ha_rows quick_prefix_records_arg)
190  :
191  have_min(have_min_arg),
192  have_max(have_max_arg),
193  min_max_arg_part(min_max_arg_part_arg),
194  group_prefix_len(group_prefix_len_arg),
195  used_key_parts(used_key_parts_arg),
196  group_key_parts(group_key_parts_arg),
197  index_info(index_info_arg),
198  index(index_arg),
199  key_infix_len(key_infix_len_arg),
200  range_tree(tree_arg),
201  index_tree(index_tree_arg),
202  param_idx(param_idx_arg),
203  quick_prefix_records(quick_prefix_records_arg)
204  {
205  if (key_infix_len)
206  memcpy(this->key_infix, key_infix_arg, key_infix_len);
207  }
208 
209  QuickSelectInterface *make_quick(Parameter *param,
210  bool retrieve_full_rows,
211  memory::Root *parent_alloc);
212 };
213 
214 
215 } /* namespace optimizer */
216 
217 } /* namespace drizzled */
218