Drizzled Public API Documentation

quick_group_min_max_select.h

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #pragma once
00021 
00022 #include <drizzled/optimizer/range.h>
00023 
00024 #include <vector>
00025 
00026 namespace drizzled
00027 {
00028 
00029 namespace optimizer
00030 {
00031 
00064 class QuickGroupMinMaxSelect : public QuickSelectInterface
00065 {
00066 
00067 private:
00068 
00069   Cursor *cursor; 
00070   Join *join; 
00071   KeyInfo *index_info; 
00072   unsigned char *record; 
00073   unsigned char *tmp_record; 
00074   unsigned char *group_prefix; 
00075   uint32_t group_prefix_len; 
00076   uint32_t group_key_parts; 
00077   unsigned char *last_prefix; 
00078   bool have_min; 
00079   bool have_max; 
00080   bool seen_first_key; 
00081   KeyPartInfo *min_max_arg_part; 
00082   uint32_t min_max_arg_len; 
00083   unsigned char *key_infix; 
00084   uint32_t key_infix_len;
00085   std::vector<QuickRange *> min_max_ranges; 
00086   uint32_t real_prefix_len; 
00087   uint32_t real_key_parts;  
00088   List<Item_sum> *min_functions;
00089   List<Item_sum> *max_functions;
00090   List<Item_sum>::iterator *min_functions_it;
00091   List<Item_sum>::iterator *max_functions_it;
00092 
00093 public:
00094 
00095   /*
00096     The following two members are public to allow easy access from
00097     GroupMinMaxReadPlan::make_quick()
00098   */
00099   memory::Root alloc; 
00100   QuickRangeSelect *quick_prefix_select; 
00102 private:
00103 
00125   int next_prefix();
00126 
00146   int next_min_in_range();
00147 
00167   int next_max_in_range();
00168 
00191   int next_min();
00192 
00208   int next_max();
00209 
00232   void update_min_result();
00233 
00255   void update_max_result();
00256 
00257 public:
00258 
00259   /*
00260      Construct new quick select for group queries with min/max.
00261 
00262      SYNOPSIS
00263      QuickGroupMinMaxSelect::QuickGroupMinMaxSelect()
00264      table             The table being accessed
00265      join              Descriptor of the current query
00266      have_min          true if the query selects a MIN function
00267      have_max          true if the query selects a MAX function
00268      min_max_arg_part  The only argument field of all MIN/MAX functions
00269      group_prefix_len  Length of all key parts in the group prefix
00270      prefix_key_parts  All key parts in the group prefix
00271      index_info        The index chosen for data access
00272      use_index         The id of index_info
00273      read_cost         Cost of this access method
00274      records           Number of records returned
00275      key_infix_len     Length of the key infix appended to the group prefix
00276      key_infix         Infix of constants from equality predicates
00277      parent_alloc      Memory pool for this and quick_prefix_select data
00278 
00279      RETURN
00280      None
00281    */
00282   QuickGroupMinMaxSelect(Table *table, 
00283                          Join *join, 
00284                          bool have_min,
00285                          bool have_max, 
00286                          KeyPartInfo *min_max_arg_part,
00287                          uint32_t group_prefix_len, 
00288                          uint32_t group_key_parts,
00289                          uint32_t used_key_parts, 
00290                          KeyInfo *index_info,
00291                          uint use_index, 
00292                          double read_cost, 
00293                          ha_rows records,
00294                          uint key_infix_len, 
00295                          unsigned char *key_infix,
00296                          memory::Root *parent_alloc);
00297 
00298   ~QuickGroupMinMaxSelect();
00299 
00317   bool add_range(SEL_ARG *sel_range);
00318 
00339   void update_key_stat();
00340 
00358   void adjust_prefix_ranges();
00359 
00360   bool alloc_buffers();
00361 
00378   int init();
00379 
00394   int reset();
00395 
00422   int get_next();
00423 
00424   bool reverse_sorted() const
00425   {
00426     return false;
00427   }
00428 
00429   bool unique_key_range() const
00430   {
00431     return false;
00432   }
00433 
00434   int get_type() const
00435   {
00436     return QS_TYPE_GROUP_MIN_MAX;
00437   }
00438 
00452   void add_keys_and_lengths(std::string *key_names, std::string *used_lengths);
00453 
00454 };
00455 
00456 
00457 } /* namespace optimizer */
00458 
00459 } /* namespace drizzled */
00460