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