1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008-2009 Sun Microsystems
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.
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.
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
20
#ifndef DRIZZLED_OPTIMIZER_TABLE_READ_PLAN_H
21
#define DRIZZLED_OPTIMIZER_TABLE_READ_PLAN_H
23
#include "drizzled/util/functors.h"
29
struct st_ror_scan_info;
39
Table rows retrieval plan. Range optimizer creates QuickSelectInterface-derived
40
objects from table read plans.
46
Plan read cost, with or without cost of full row retrieval, depending
47
on plan creation parameters.
50
ha_rows records; /* estimate of #rows to be examined */
53
If true, the scan returns rows in rowid order. This is used only for
54
scans that can be both ROR and non-ROR.
59
Create quick select for this plan.
62
param Parameter from test_quick_select
63
retrieve_full_rows If true, created quick select will do full record
65
parent_alloc Memory pool to use, if any.
68
retrieve_full_rows is ignored by some implementations.
74
virtual QuickSelectInterface *make_quick(Parameter *param,
75
bool retrieve_full_rows,
76
memory::Root *parent_alloc= NULL) = 0;
78
/* Table read plans are allocated on memory::Root and are never deleted */
79
static void *operator new(size_t size, memory::Root *mem_root)
81
return (void*) mem_root->alloc_root((uint32_t) size);
84
static void operator delete(void *, size_t)
87
static void operator delete(void *, memory::Root *)
88
{ /* Never called */ }
90
virtual ~TableReadPlan() {} /* Remove gcc warning */
96
Plan for a QuickRangeSelect scan.
97
RangeReadPlan::make_quick ignores retrieve_full_rows parameter because
98
QuickRangeSelect doesn't distinguish between 'index only' scans and full
99
record retrieval scans.
101
class RangeReadPlan : public TableReadPlan
106
SEL_ARG *key; /* set of intervals to be used in "range" method retrieval */
107
uint32_t key_idx; /* key number in Parameter::key */
109
uint32_t mrr_buf_size;
111
RangeReadPlan(SEL_ARG *key_arg, uint32_t idx_arg, uint32_t mrr_flags_arg)
115
mrr_flags(mrr_flags_arg)
117
virtual ~RangeReadPlan() {} /* Remove gcc warning */
119
QuickSelectInterface *make_quick(Parameter *param, bool, memory::Root *parent_alloc);
124
/* Plan for QuickRorIntersectSelect scan. */
125
class RorIntersectReadPlan : public TableReadPlan
129
RorIntersectReadPlan() {} /* Remove gcc warning */
130
virtual ~RorIntersectReadPlan() {} /* Remove gcc warning */
132
QuickSelectInterface *make_quick(Parameter *param,
133
bool retrieve_full_rows,
134
memory::Root *parent_alloc);
136
/* Array of pointers to ROR range scans used in this intersection */
137
struct st_ror_scan_info **first_scan;
138
struct st_ror_scan_info **last_scan; /* End of the above array */
139
struct st_ror_scan_info *cpk_scan; /* Clustered PK scan, if there is one */
141
bool is_covering; /* true if no row retrieval phase is necessary */
142
double index_scan_costs; /* SUM(cost(index_scan)) */
148
Plan for QuickRorUnionSelect scan.
149
QuickRorUnionSelect always retrieves full rows, so retrieve_full_rows
150
is ignored by make_quick.
153
class RorUnionReadPlan : public TableReadPlan
156
RorUnionReadPlan() {} /* Remove gcc warning */
157
virtual ~RorUnionReadPlan() {} /* Remove gcc warning */
158
QuickSelectInterface *make_quick(Parameter *param,
159
bool retrieve_full_rows,
160
memory::Root *parent_alloc);
161
TableReadPlan **first_ror; /* array of ptrs to plans for merged scans */
162
TableReadPlan **last_ror; /* end of the above array */
167
Plan for QuickIndexMergeSelect scan.
168
QuickRorIntersectSelect always retrieves full rows, so retrieve_full_rows
169
is ignored by make_quick.
172
class IndexMergeReadPlan : public TableReadPlan
175
IndexMergeReadPlan() {} /* Remove gcc warning */
176
virtual ~IndexMergeReadPlan() {} /* Remove gcc warning */
177
QuickSelectInterface *make_quick(Parameter *param,
178
bool retrieve_full_rows,
179
memory::Root *parent_alloc);
180
RangeReadPlan **range_scans; /* array of ptrs to plans of merged scans */
181
RangeReadPlan **range_scans_end; /* end of the array */
186
Plan for a QuickGroupMinMaxSelect scan.
189
class GroupMinMaxReadPlan : public TableReadPlan
194
KeyPartInfo *min_max_arg_part;
195
uint32_t group_prefix_len;
196
uint32_t used_key_parts;
197
uint32_t group_key_parts;
200
uint32_t key_infix_len;
201
unsigned char key_infix[MAX_KEY_LENGTH];
202
SEL_TREE *range_tree; /* Represents all range predicates in the query. */
203
SEL_ARG *index_tree; /* The SEL_ARG sub-tree corresponding to index_info. */
204
uint32_t param_idx; /* Index of used key in param->key. */
205
/* Number of records selected by the ranges in index_tree. */
207
ha_rows quick_prefix_records;
210
GroupMinMaxReadPlan(bool have_min_arg,
212
KeyPartInfo *min_max_arg_part_arg,
213
uint32_t group_prefix_len_arg,
214
uint32_t used_key_parts_arg,
215
uint32_t group_key_parts_arg,
216
KeyInfo *index_info_arg,
218
uint32_t key_infix_len_arg,
219
unsigned char *key_infix_arg,
221
SEL_ARG *index_tree_arg,
222
uint32_t param_idx_arg,
223
ha_rows quick_prefix_records_arg)
225
have_min(have_min_arg),
226
have_max(have_max_arg),
227
min_max_arg_part(min_max_arg_part_arg),
228
group_prefix_len(group_prefix_len_arg),
229
used_key_parts(used_key_parts_arg),
230
group_key_parts(group_key_parts_arg),
231
index_info(index_info_arg),
233
key_infix_len(key_infix_len_arg),
234
range_tree(tree_arg),
235
index_tree(index_tree_arg),
236
param_idx(param_idx_arg),
237
quick_prefix_records(quick_prefix_records_arg)
240
memcpy(this->key_infix, key_infix_arg, key_infix_len);
242
virtual ~GroupMinMaxReadPlan() {} /* Remove gcc warning */
244
QuickSelectInterface *make_quick(Parameter *param,
245
bool retrieve_full_rows,
246
memory::Root *parent_alloc);
250
} /* namespace optimizer */
252
} /* namespace drizzled */
254
#endif /* DRIZZLED_OPTIMIZER_TABLE_READ_PLAN_H */