drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
quick_group_min_max_select.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/optimizer/range.h>
23
24#include <vector>
25
26namespace drizzled
27{
28
29class KeyPartInfo;
30
31namespace optimizer
32{
33
66class QuickGroupMinMaxSelect : public QuickSelectInterface
67{
68
69private:
70
74 unsigned char *record;
75 unsigned char *tmp_record;
76 unsigned char *group_prefix;
78 uint32_t group_key_parts;
79 unsigned char *last_prefix;
80 bool have_min;
81 bool have_max;
83 KeyPartInfo *min_max_arg_part;
84 uint32_t min_max_arg_len;
85 unsigned char *key_infix;
86 uint32_t key_infix_len;
87 std::vector<QuickRange *> min_max_ranges;
88 uint32_t real_prefix_len;
89 uint32_t real_key_parts;
90 List<Item_sum> *min_functions;
91 List<Item_sum> *max_functions;
92 List<Item_sum>::iterator *min_functions_it;
93 List<Item_sum>::iterator *max_functions_it;
94
95public:
96
97 /*
98 The following two members are public to allow easy access from
99 GroupMinMaxReadPlan::make_quick()
100 */
103
104private:
105
127 int next_prefix();
128
148 int next_min_in_range();
149
169 int next_max_in_range();
170
193 int next_min();
194
210 int next_max();
211
234 void update_min_result();
235
257 void update_max_result();
258
259public:
260
261 /*
262 Construct new quick select for group queries with min/max.
263
264 SYNOPSIS
265 QuickGroupMinMaxSelect::QuickGroupMinMaxSelect()
266 table The table being accessed
267 join Descriptor of the current query
268 have_min true if the query selects a MIN function
269 have_max true if the query selects a MAX function
270 min_max_arg_part The only argument field of all MIN/MAX functions
271 group_prefix_len Length of all key parts in the group prefix
272 prefix_key_parts All key parts in the group prefix
273 index_info The index chosen for data access
274 use_index The id of index_info
275 read_cost Cost of this access method
276 records Number of records returned
277 key_infix_len Length of the key infix appended to the group prefix
278 key_infix Infix of constants from equality predicates
279 parent_alloc Memory pool for this and quick_prefix_select data
280
281 RETURN
282 None
283 */
284 QuickGroupMinMaxSelect(Table *table,
285 Join *join,
286 bool have_min,
287 bool have_max,
288 KeyPartInfo *min_max_arg_part,
289 uint32_t group_prefix_len,
290 uint32_t group_key_parts,
291 uint32_t used_key_parts,
293 uint use_index,
294 double read_cost,
295 ha_rows records,
296 uint key_infix_len,
297 unsigned char *key_infix,
298 memory::Root *parent_alloc);
299
300 ~QuickGroupMinMaxSelect();
301
319 bool add_range(SEL_ARG *sel_range);
320
341 void update_key_stat();
342
361
362 bool alloc_buffers();
363
380 int init();
381
396 int reset();
397
424 int get_next();
425
426 bool reverse_sorted() const
427 {
428 return false;
429 }
430
431 bool unique_key_range() const
432 {
433 return false;
434 }
435
436 int get_type() const
437 {
438 return QS_TYPE_GROUP_MIN_MAX;
439 }
440
454 void add_keys_and_lengths(std::string *key_names, std::string *used_lengths);
455
456};
457
458
459} /* namespace optimizer */
460
461} /* namespace drizzled */
462
void add_keys_and_lengths(std::string *key_names, std::string *used_lengths)
TODO: Rename this file - func.h is stupid.