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