Drizzled Public API Documentation

range_param.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 <boost/dynamic_bitset.hpp>
00023 
00024 #include <drizzled/field.h>
00025 
00026 namespace drizzled
00027 {
00028 
00029 typedef class Item COND;
00030 typedef struct st_key_part KEY_PART;
00031 
00032 namespace optimizer
00033 {
00034 
00035 class RorScanInfo
00036 {
00037 public:
00038   RorScanInfo()
00039     :
00040       idx(0),
00041       keynr(0),
00042       records(0), 
00043       sel_arg(NULL),
00044       covered_fields(0),
00045       covered_fields_size(0),
00046       used_fields_covered(0),
00047       key_rec_length(0),
00048       index_read_cost(0.0),
00049       first_uncovered_field(0),
00050       key_components(0)
00051   {}
00052 
00053   boost::dynamic_bitset<> bitsToBitset() const;
00054 
00055   void subtractBitset(const boost::dynamic_bitset<>& in_bitset);
00056 
00057   uint32_t findFirstNotSet() const; 
00058 
00059   size_t getBitCount() const;
00060 
00061   uint32_t      idx;      /* # of used key in param->keys */
00062   uint32_t      keynr;    /* # of used key in table */
00063   ha_rows   records;  /* estimate of # records this scan will return */
00064 
00065   /* Set of intervals over key fields that will be used for row retrieval. */
00066   optimizer::SEL_ARG   *sel_arg;
00067 
00068   /* Fields used in the query and covered by this ROR scan. */
00069   uint64_t covered_fields;
00070   size_t covered_fields_size;
00071   uint32_t      used_fields_covered; /* # of set bits in covered_fields */
00072   int       key_rec_length; /* length of key record (including rowid) */
00073 
00074   /*
00075     Cost of reading all index records with values in sel_arg intervals set
00076     (assuming there is no need to access full table records)
00077   */
00078   double    index_read_cost;
00079   uint32_t      first_uncovered_field; /* first unused bit in covered_fields */
00080   uint32_t      key_components; /* # of parts in the key */
00081 };
00082 
00083 class RangeParameter
00084 {
00085 public:
00086 
00087   RangeParameter()
00088     :
00089       session(NULL),
00090       table(NULL),
00091       cond(NULL),
00092       prev_tables(),
00093       read_tables(),
00094       current_table(),
00095       key_parts(NULL),
00096       key_parts_end(NULL),
00097       mem_root(NULL),
00098       old_root(NULL),
00099       keys(0),
00100       using_real_indexes(false),
00101       remove_jump_scans(false),
00102       alloced_sel_args(0),
00103       force_default_mrr(false)
00104   {}
00105 
00106   Session *session;   /* Current thread handle */
00107   Table *table; /* Table being analyzed */
00108   COND *cond;   /* Used inside get_mm_tree(). */
00109   table_map prev_tables;
00110   table_map read_tables;
00111   table_map current_table; /* Bit of the table being analyzed */
00112 
00113   /* Array of parts of all keys for which range analysis is performed */
00114   KEY_PART *key_parts;
00115   KEY_PART *key_parts_end;
00116   memory::Root *mem_root; /* Memory that will be freed when range analysis completes */
00117   memory::Root *old_root; /* Memory that will last until the query end */
00118   /*
00119     Number of indexes used in range analysis (In SEL_TREE::keys only first
00120     #keys elements are not empty)
00121   */
00122   uint32_t keys;
00123 
00124   /*
00125     If true, the index descriptions describe real indexes (and it is ok to
00126     call field->optimize_range(real_keynr[...], ...).
00127     Otherwise index description describes fake indexes.
00128   */
00129   bool using_real_indexes;
00130 
00131   bool remove_jump_scans;
00132 
00133   /*
00134     used_key_no -> table_key_no translation table. Only makes sense if
00135     using_real_indexes==true
00136   */
00137   uint32_t real_keynr[MAX_KEY];
00138   /* Number of SEL_ARG objects allocated by optimizer::SEL_ARG::clone_tree operations */
00139   uint32_t alloced_sel_args;
00140   bool force_default_mrr;
00141 };
00142 
00143 class Parameter : public RangeParameter
00144 {
00145 public:
00146 
00147   Parameter()
00148     :
00149       RangeParameter(),
00150       max_key_part(0),
00151       range_count(0),
00152       quick(false),
00153       needed_fields(),
00154       tmp_covered_fields(),
00155       needed_reg(NULL),
00156       imerge_cost_buff(NULL),
00157       imerge_cost_buff_size(0),
00158       is_ror_scan(false),
00159       n_ranges(0)
00160   {}
00161 
00162   KEY_PART *key[MAX_KEY]; /* First key parts of keys used in the query */
00163   uint32_t max_key_part;
00164   /* Number of ranges in the last checked tree->key */
00165   uint32_t range_count;
00166   unsigned char min_key[MAX_KEY_LENGTH+MAX_FIELD_WIDTH];
00167   unsigned char max_key[MAX_KEY_LENGTH+MAX_FIELD_WIDTH];
00168   bool quick; // Don't calulate possible keys
00169 
00170   boost::dynamic_bitset<> needed_fields;    /* bitmask of fields needed by the query */
00171   boost::dynamic_bitset<> tmp_covered_fields;
00172 
00173   key_map *needed_reg;        /* ptr to SqlSelect::needed_reg */
00174 
00175   uint32_t *imerge_cost_buff;     /* buffer for index_merge cost estimates */
00176   uint32_t imerge_cost_buff_size; /* size of the buffer */
00177 
00178   /* true if last checked tree->key can be used for ROR-scan */
00179   bool is_ror_scan;
00180   /* Number of ranges in the last checked tree->key */
00181   uint32_t n_ranges;
00182 };
00183 
00184 } /* namespace optimizer */
00185 
00186 } /* namespace drizzled */
00187