Drizzled Public API Documentation

table_read_plan.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/memory/sql_alloc.h>
00023 #include <drizzled/util/functors.h>
00024 #include <algorithm>
00025 
00026 namespace drizzled {
00027 namespace optimizer {
00028 
00029 /*
00030   Table rows retrieval plan. Range optimizer creates QuickSelectInterface-derived
00031   objects from table read plans.
00032 */
00033 class TableReadPlan : public memory::SqlAlloc
00034 {
00035 public:
00036   /*
00037     Plan read cost, with or without cost of full row retrieval, depending
00038     on plan creation parameters.
00039   */
00040   double read_cost;
00041   ha_rows records; /* estimate of #rows to be examined */
00042 
00043   /*
00044     If true, the scan returns rows in rowid order. This is used only for
00045     scans that can be both ROR and non-ROR.
00046   */
00047   bool is_ror;
00048 
00049   /*
00050     Create quick select for this plan.
00051     SYNOPSIS
00052      make_quick()
00053        param               Parameter from test_quick_select
00054        retrieve_full_rows  If true, created quick select will do full record
00055                            retrieval.
00056        parent_alloc        Memory pool to use, if any.
00057 
00058     NOTES
00059       retrieve_full_rows is ignored by some implementations.
00060 
00061     RETURN
00062       created quick select
00063       NULL on any error.
00064   */
00065   virtual QuickSelectInterface *make_quick(Parameter *param,
00066                                            bool retrieve_full_rows,
00067                                            memory::Root *parent_alloc= NULL) = 0;
00068 
00069   virtual ~TableReadPlan() {} /* Remove gcc warning */
00070 };
00071 
00072 
00073 /*
00074   Plan for a QuickRangeSelect scan.
00075   RangeReadPlan::make_quick ignores retrieve_full_rows parameter because
00076   QuickRangeSelect doesn't distinguish between 'index only' scans and full
00077   record retrieval scans.
00078 */
00079 class RangeReadPlan : public TableReadPlan
00080 {
00081 public:
00082   SEL_ARG *key; /* set of intervals to be used in "range" method retrieval */
00083   uint32_t     key_idx; /* key number in Parameter::key */
00084   uint32_t     mrr_flags;
00085   uint32_t     mrr_buf_size;
00086 
00087   RangeReadPlan(SEL_ARG *key_arg, uint32_t idx_arg, uint32_t mrr_flags_arg)
00088     :
00089       key(key_arg),
00090       key_idx(idx_arg),
00091       mrr_flags(mrr_flags_arg)
00092   {}
00093 
00094   QuickSelectInterface *make_quick(Parameter *param, bool, memory::Root *parent_alloc);
00095 };
00096 
00097 
00098 /* Plan for QuickRorIntersectSelect scan. */
00099 class RorIntersectReadPlan : public TableReadPlan
00100 {
00101 public:
00102   QuickSelectInterface *make_quick(Parameter *param,
00103                                    bool retrieve_full_rows,
00104                                    memory::Root *parent_alloc);
00105 
00106   /* Array of pointers to ROR range scans used in this intersection */
00107   RorScanInfo **first_scan;
00108   RorScanInfo **last_scan; /* End of the above array */
00109   RorScanInfo *cpk_scan;  /* Clustered PK scan, if there is one */
00110 
00111   bool is_covering; /* true if no row retrieval phase is necessary */
00112   double index_scan_costs; /* SUM(cost(index_scan)) */
00113 
00114 };
00115 
00116 
00117 /*
00118   Plan for QuickRorUnionSelect scan.
00119   QuickRorUnionSelect always retrieves full rows, so retrieve_full_rows
00120   is ignored by make_quick.
00121 */
00122 
00123 class RorUnionReadPlan : public TableReadPlan
00124 {
00125 public:
00126   QuickSelectInterface *make_quick(Parameter *param,
00127                                    bool retrieve_full_rows,
00128                                    memory::Root *parent_alloc);
00129   TableReadPlan **first_ror; /* array of ptrs to plans for merged scans */
00130   TableReadPlan **last_ror;  /* end of the above array */
00131 };
00132 
00133 
00134 /*
00135   Plan for QuickIndexMergeSelect scan.
00136   QuickRorIntersectSelect always retrieves full rows, so retrieve_full_rows
00137   is ignored by make_quick.
00138 */
00139 
00140 class IndexMergeReadPlan : public TableReadPlan
00141 {
00142 public:
00143   QuickSelectInterface *make_quick(Parameter *param,
00144                                    bool retrieve_full_rows,
00145                                    memory::Root *parent_alloc);
00146   RangeReadPlan **range_scans; /* array of ptrs to plans of merged scans */
00147   RangeReadPlan **range_scans_end; /* end of the array */
00148 };
00149 
00150 
00151 /*
00152   Plan for a QuickGroupMinMaxSelect scan.
00153 */
00154 
00155 class GroupMinMaxReadPlan : public TableReadPlan
00156 {
00157 private:
00158   bool have_min;
00159   bool have_max;
00160   KeyPartInfo *min_max_arg_part;
00161   uint32_t group_prefix_len;
00162   uint32_t used_key_parts;
00163   uint32_t group_key_parts;
00164   KeyInfo *index_info;
00165   uint32_t index;
00166   uint32_t key_infix_len;
00167   unsigned char key_infix[MAX_KEY_LENGTH];
00168   SEL_TREE *range_tree; /* Represents all range predicates in the query. */
00169   SEL_ARG *index_tree; /* The SEL_ARG sub-tree corresponding to index_info. */
00170   uint32_t param_idx; /* Index of used key in param->key. */
00171   /* Number of records selected by the ranges in index_tree. */
00172 public:
00173   ha_rows quick_prefix_records;
00174 
00175 public:
00176   GroupMinMaxReadPlan(bool have_min_arg,
00177                       bool have_max_arg,
00178                       KeyPartInfo *min_max_arg_part_arg,
00179                       uint32_t group_prefix_len_arg,
00180                       uint32_t used_key_parts_arg,
00181                       uint32_t group_key_parts_arg,
00182                       KeyInfo *index_info_arg,
00183                       uint32_t index_arg,
00184                       uint32_t key_infix_len_arg,
00185                       unsigned char *key_infix_arg,
00186                       SEL_TREE *tree_arg,
00187                       SEL_ARG *index_tree_arg,
00188                       uint32_t param_idx_arg,
00189                       ha_rows quick_prefix_records_arg)
00190     :
00191       have_min(have_min_arg),
00192       have_max(have_max_arg),
00193       min_max_arg_part(min_max_arg_part_arg),
00194       group_prefix_len(group_prefix_len_arg),
00195       used_key_parts(used_key_parts_arg),
00196       group_key_parts(group_key_parts_arg),
00197       index_info(index_info_arg),
00198       index(index_arg),
00199       key_infix_len(key_infix_len_arg),
00200       range_tree(tree_arg),
00201       index_tree(index_tree_arg),
00202       param_idx(param_idx_arg),
00203       quick_prefix_records(quick_prefix_records_arg)
00204     {
00205       if (key_infix_len)
00206         memcpy(this->key_infix, key_infix_arg, key_infix_len);
00207     }
00208 
00209   QuickSelectInterface *make_quick(Parameter *param,
00210                                    bool retrieve_full_rows,
00211                                    memory::Root *parent_alloc);
00212 };
00213 
00214 
00215 } /* namespace optimizer */
00216 
00217 } /* namespace drizzled */
00218