~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/optimizer/range_param.h

Merged vcol stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
#ifndef DRIZZLED_OPTIMIZER_RANGE_PARAM_H
21
 
#define DRIZZLED_OPTIMIZER_RANGE_PARAM_H
22
 
 
23
 
#include <boost/dynamic_bitset.hpp>
24
 
 
25
 
#include "drizzled/field.h"
26
 
 
27
 
namespace drizzled
28
 
{
29
 
 
30
 
typedef class Item COND;
31
 
typedef struct st_key_part KEY_PART;
32
 
 
33
 
namespace optimizer
34
 
{
35
 
 
36
 
class RorScanInfo
37
 
{
38
 
public:
39
 
  RorScanInfo()
40
 
    :
41
 
      idx(0),
42
 
      keynr(0),
43
 
      records(0), 
44
 
      sel_arg(NULL),
45
 
      covered_fields(0),
46
 
      covered_fields_size(0),
47
 
      used_fields_covered(0),
48
 
      key_rec_length(0),
49
 
      index_read_cost(0.0),
50
 
      first_uncovered_field(0),
51
 
      key_components(0)
52
 
  {}
53
 
 
54
 
  boost::dynamic_bitset<> bitsToBitset() const;
55
 
 
56
 
  void subtractBitset(const boost::dynamic_bitset<>& in_bitset);
57
 
 
58
 
  uint32_t findFirstNotSet() const; 
59
 
 
60
 
  size_t getBitCount() const;
61
 
 
62
 
  uint32_t      idx;      /* # of used key in param->keys */
63
 
  uint32_t      keynr;    /* # of used key in table */
64
 
  ha_rows   records;  /* estimate of # records this scan will return */
65
 
 
66
 
  /* Set of intervals over key fields that will be used for row retrieval. */
67
 
  optimizer::SEL_ARG   *sel_arg;
68
 
 
69
 
  /* Fields used in the query and covered by this ROR scan. */
70
 
  uint64_t covered_fields;
71
 
  size_t covered_fields_size;
72
 
  uint32_t      used_fields_covered; /* # of set bits in covered_fields */
73
 
  int       key_rec_length; /* length of key record (including rowid) */
74
 
 
75
 
  /*
76
 
    Cost of reading all index records with values in sel_arg intervals set
77
 
    (assuming there is no need to access full table records)
78
 
  */
79
 
  double    index_read_cost;
80
 
  uint32_t      first_uncovered_field; /* first unused bit in covered_fields */
81
 
  uint32_t      key_components; /* # of parts in the key */
82
 
};
83
 
 
84
 
class RangeParameter
85
 
{
86
 
public:
87
 
 
88
 
  RangeParameter()
89
 
    :
90
 
      session(NULL),
91
 
      table(NULL),
92
 
      cond(NULL),
93
 
      prev_tables(),
94
 
      read_tables(),
95
 
      current_table(),
96
 
      key_parts(NULL),
97
 
      key_parts_end(NULL),
98
 
      mem_root(NULL),
99
 
      old_root(NULL),
100
 
      keys(0),
101
 
      using_real_indexes(false),
102
 
      remove_jump_scans(false),
103
 
      alloced_sel_args(0),
104
 
      force_default_mrr(false)
105
 
  {}
106
 
 
107
 
  Session       *session;   /* Current thread handle */
108
 
  Table *table; /* Table being analyzed */
109
 
  COND *cond;   /* Used inside get_mm_tree(). */
110
 
  table_map prev_tables;
111
 
  table_map read_tables;
112
 
  table_map current_table; /* Bit of the table being analyzed */
113
 
 
114
 
  /* Array of parts of all keys for which range analysis is performed */
115
 
  KEY_PART *key_parts;
116
 
  KEY_PART *key_parts_end;
117
 
  memory::Root *mem_root; /* Memory that will be freed when range analysis completes */
118
 
  memory::Root *old_root; /* Memory that will last until the query end */
119
 
  /*
120
 
    Number of indexes used in range analysis (In SEL_TREE::keys only first
121
 
    #keys elements are not empty)
122
 
  */
123
 
  uint32_t keys;
124
 
 
125
 
  /*
126
 
    If true, the index descriptions describe real indexes (and it is ok to
127
 
    call field->optimize_range(real_keynr[...], ...).
128
 
    Otherwise index description describes fake indexes.
129
 
  */
130
 
  bool using_real_indexes;
131
 
 
132
 
  bool remove_jump_scans;
133
 
 
134
 
  /*
135
 
    used_key_no -> table_key_no translation table. Only makes sense if
136
 
    using_real_indexes==true
137
 
  */
138
 
  uint32_t real_keynr[MAX_KEY];
139
 
  /* Number of SEL_ARG objects allocated by optimizer::SEL_ARG::clone_tree operations */
140
 
  uint32_t alloced_sel_args;
141
 
  bool force_default_mrr;
142
 
};
143
 
 
144
 
class Parameter : public RangeParameter
145
 
{
146
 
public:
147
 
 
148
 
  Parameter()
149
 
    :
150
 
      RangeParameter(),
151
 
      max_key_part(0),
152
 
      range_count(0),
153
 
      quick(false),
154
 
      needed_fields(),
155
 
      tmp_covered_fields(),
156
 
      needed_reg(NULL),
157
 
      imerge_cost_buff(NULL),
158
 
      imerge_cost_buff_size(0),
159
 
      is_ror_scan(false),
160
 
      n_ranges(0)
161
 
  {}
162
 
 
163
 
  KEY_PART *key[MAX_KEY]; /* First key parts of keys used in the query */
164
 
  uint32_t max_key_part;
165
 
  /* Number of ranges in the last checked tree->key */
166
 
  uint32_t range_count;
167
 
  unsigned char min_key[MAX_KEY_LENGTH+MAX_FIELD_WIDTH];
168
 
  unsigned char max_key[MAX_KEY_LENGTH+MAX_FIELD_WIDTH];
169
 
  bool quick; // Don't calulate possible keys
170
 
 
171
 
  boost::dynamic_bitset<> needed_fields;    /* bitmask of fields needed by the query */
172
 
  boost::dynamic_bitset<> tmp_covered_fields;
173
 
 
174
 
  key_map *needed_reg;        /* ptr to SqlSelect::needed_reg */
175
 
 
176
 
  uint32_t *imerge_cost_buff;     /* buffer for index_merge cost estimates */
177
 
  uint32_t imerge_cost_buff_size; /* size of the buffer */
178
 
 
179
 
  /* true if last checked tree->key can be used for ROR-scan */
180
 
  bool is_ror_scan;
181
 
  /* Number of ranges in the last checked tree->key */
182
 
  uint32_t n_ranges;
183
 
};
184
 
 
185
 
} /* namespace optimizer */
186
 
 
187
 
} /* namespace drizzled */
188
 
 
189
 
#endif /* DRIZZLED_OPTIMIZER_RANGE_PARAM_H */