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
24
struct st_ror_scan_info;
36
Table rows retrieval plan. Range optimizer creates QuickSelectInterface-derived
37
objects from table read plans.
43
Plan read cost, with or without cost of full row retrieval, depending
44
on plan creation parameters.
47
ha_rows records; /* estimate of #rows to be examined */
50
If true, the scan returns rows in rowid order. This is used only for
51
scans that can be both ROR and non-ROR.
56
Create quick select for this plan.
59
param Parameter from test_quick_select
60
retrieve_full_rows If true, created quick select will do full record
62
parent_alloc Memory pool to use, if any.
65
retrieve_full_rows is ignored by some implementations.
71
virtual QuickSelectInterface *make_quick(Parameter *param,
72
bool retrieve_full_rows,
73
drizzled::memory::Root *parent_alloc= NULL) = 0;
75
/* Table read plans are allocated on drizzled::memory::Root and are never deleted */
76
static void *operator new(size_t size, drizzled::memory::Root *mem_root)
78
return (void*) alloc_root(mem_root, (uint32_t) size);
81
static void operator delete(void *, size_t)
84
static void operator delete(void *, drizzled::memory::Root *)
85
{ /* Never called */ }
87
virtual ~TableReadPlan() {} /* Remove gcc warning */
93
Plan for a QuickRangeSelect scan.
94
RangeReadPlan::make_quick ignores retrieve_full_rows parameter because
95
QuickRangeSelect doesn't distinguish between 'index only' scans and full
96
record retrieval scans.
98
class RangeReadPlan : public TableReadPlan
103
SEL_ARG *key; /* set of intervals to be used in "range" method retrieval */
104
uint32_t key_idx; /* key number in Parameter::key */
106
uint32_t mrr_buf_size;
108
RangeReadPlan(SEL_ARG *key_arg, uint32_t idx_arg, uint32_t mrr_flags_arg)
112
mrr_flags(mrr_flags_arg)
114
virtual ~RangeReadPlan() {} /* Remove gcc warning */
116
QuickSelectInterface *make_quick(Parameter *param, bool, drizzled::memory::Root *parent_alloc);
121
/* Plan for QuickRorIntersectSelect scan. */
122
class RorIntersectReadPlan : public TableReadPlan
125
RorIntersectReadPlan() {} /* Remove gcc warning */
126
virtual ~RorIntersectReadPlan() {} /* Remove gcc warning */
127
QuickSelectInterface *make_quick(Parameter *param,
128
bool retrieve_full_rows,
129
drizzled::memory::Root *parent_alloc);
131
/* Array of pointers to ROR range scans used in this intersection */
132
struct st_ror_scan_info **first_scan;
133
struct st_ror_scan_info **last_scan; /* End of the above array */
134
struct st_ror_scan_info *cpk_scan; /* Clustered PK scan, if there is one */
135
bool is_covering; /* true if no row retrieval phase is necessary */
136
double index_scan_costs; /* SUM(cost(index_scan)) */
141
Plan for QuickRorUnionSelect scan.
142
QuickRorUnionSelect always retrieves full rows, so retrieve_full_rows
143
is ignored by make_quick.
146
class RorUnionReadPlan : public TableReadPlan
149
RorUnionReadPlan() {} /* Remove gcc warning */
150
virtual ~RorUnionReadPlan() {} /* Remove gcc warning */
151
QuickSelectInterface *make_quick(Parameter *param,
152
bool retrieve_full_rows,
153
drizzled::memory::Root *parent_alloc);
154
TableReadPlan **first_ror; /* array of ptrs to plans for merged scans */
155
TableReadPlan **last_ror; /* end of the above array */
160
Plan for QuickIndexMergeSelect scan.
161
QuickRorIntersectSelect always retrieves full rows, so retrieve_full_rows
162
is ignored by make_quick.
165
class IndexMergeReadPlan : public TableReadPlan
168
IndexMergeReadPlan() {} /* Remove gcc warning */
169
virtual ~IndexMergeReadPlan() {} /* Remove gcc warning */
170
QuickSelectInterface *make_quick(Parameter *param,
171
bool retrieve_full_rows,
172
drizzled::memory::Root *parent_alloc);
173
RangeReadPlan **range_scans; /* array of ptrs to plans of merged scans */
174
RangeReadPlan **range_scans_end; /* end of the array */
179
Plan for a QuickGroupMinMaxSelect scan.
182
class GroupMinMaxReadPlan : public TableReadPlan
187
KEY_PART_INFO *min_max_arg_part;
188
uint32_t group_prefix_len;
189
uint32_t used_key_parts;
190
uint32_t group_key_parts;
193
uint32_t key_infix_len;
194
unsigned char key_infix[MAX_KEY_LENGTH];
195
SEL_TREE *range_tree; /* Represents all range predicates in the query. */
196
SEL_ARG *index_tree; /* The SEL_ARG sub-tree corresponding to index_info. */
197
uint32_t param_idx; /* Index of used key in param->key. */
198
/* Number of records selected by the ranges in index_tree. */
200
ha_rows quick_prefix_records;
203
GroupMinMaxReadPlan(bool have_min_arg,
205
KEY_PART_INFO *min_max_arg_part_arg,
206
uint32_t group_prefix_len_arg,
207
uint32_t used_key_parts_arg,
208
uint32_t group_key_parts_arg,
211
uint32_t key_infix_len_arg,
212
unsigned char *key_infix_arg,
214
SEL_ARG *index_tree_arg,
215
uint32_t param_idx_arg,
216
ha_rows quick_prefix_records_arg)
218
have_min(have_min_arg),
219
have_max(have_max_arg),
220
min_max_arg_part(min_max_arg_part_arg),
221
group_prefix_len(group_prefix_len_arg),
222
used_key_parts(used_key_parts_arg),
223
group_key_parts(group_key_parts_arg),
224
index_info(index_info_arg),
226
key_infix_len(key_infix_len_arg),
227
range_tree(tree_arg),
228
index_tree(index_tree_arg),
229
param_idx(param_idx_arg),
230
quick_prefix_records(quick_prefix_records_arg)
233
memcpy(this->key_infix, key_infix_arg, key_infix_len);
235
virtual ~GroupMinMaxReadPlan() {} /* Remove gcc warning */
237
QuickSelectInterface *make_quick(Parameter *param,
238
bool retrieve_full_rows,
239
drizzled::memory::Root *parent_alloc);
243
} /* namespace optimizer */
245
} /* namespace drizzled */
247
#endif /* DRIZZLED_OPTIMIZER_TABLE_READ_PLAN_H */