~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/optimizer/table_read_plan.h

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 01:03:01 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913010301-tcvvezipx1124acy
Added calls to the dtrace delete begin/end probes.

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
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_TABLE_READ_PLAN_H
21
 
#define DRIZZLED_OPTIMIZER_TABLE_READ_PLAN_H
22
 
 
23
 
#include "drizzled/util/functors.h"
24
 
#include <algorithm>
25
 
 
26
 
namespace drizzled
27
 
{
28
 
 
29
 
struct st_ror_scan_info;
30
 
 
31
 
namespace optimizer
32
 
{
33
 
 
34
 
class Parameter;
35
 
class SEL_ARG;
36
 
class SEL_TREE;
37
 
 
38
 
/*
39
 
  Table rows retrieval plan. Range optimizer creates QuickSelectInterface-derived
40
 
  objects from table read plans.
41
 
*/
42
 
class TableReadPlan
43
 
{
44
 
public:
45
 
  /*
46
 
    Plan read cost, with or without cost of full row retrieval, depending
47
 
    on plan creation parameters.
48
 
  */
49
 
  double read_cost;
50
 
  ha_rows records; /* estimate of #rows to be examined */
51
 
 
52
 
  /*
53
 
    If true, the scan returns rows in rowid order. This is used only for
54
 
    scans that can be both ROR and non-ROR.
55
 
  */
56
 
  bool is_ror;
57
 
 
58
 
  /*
59
 
    Create quick select for this plan.
60
 
    SYNOPSIS
61
 
     make_quick()
62
 
       param               Parameter from test_quick_select
63
 
       retrieve_full_rows  If true, created quick select will do full record
64
 
                           retrieval.
65
 
       parent_alloc        Memory pool to use, if any.
66
 
 
67
 
    NOTES
68
 
      retrieve_full_rows is ignored by some implementations.
69
 
 
70
 
    RETURN
71
 
      created quick select
72
 
      NULL on any error.
73
 
  */
74
 
  virtual QuickSelectInterface *make_quick(Parameter *param,
75
 
                                           bool retrieve_full_rows,
76
 
                                           memory::Root *parent_alloc= NULL) = 0;
77
 
 
78
 
  /* Table read plans are allocated on memory::Root and are never deleted */
79
 
  static void *operator new(size_t size, memory::Root *mem_root)
80
 
  { 
81
 
    return (void*) alloc_root(mem_root, (uint32_t) size); 
82
 
  }
83
 
 
84
 
  static void operator delete(void *, size_t)
85
 
  { }
86
 
 
87
 
  static void operator delete(void *, memory::Root *)
88
 
    { /* Never called */ }
89
 
 
90
 
  virtual ~TableReadPlan() {} /* Remove gcc warning */
91
 
 
92
 
};
93
 
 
94
 
 
95
 
/*
96
 
  Plan for a QuickRangeSelect scan.
97
 
  RangeReadPlan::make_quick ignores retrieve_full_rows parameter because
98
 
  QuickRangeSelect doesn't distinguish between 'index only' scans and full
99
 
  record retrieval scans.
100
 
*/
101
 
class RangeReadPlan : public TableReadPlan
102
 
{
103
 
 
104
 
public:
105
 
 
106
 
  RangeReadPlan(SEL_ARG *key_arg, uint32_t idx_arg, uint32_t mrr_flags_arg)
107
 
    :
108
 
      key(key_arg),
109
 
      key_idx(idx_arg),
110
 
      mrr_flags(mrr_flags_arg),
111
 
      mrr_buf_size(0)
112
 
  {}
113
 
 
114
 
  virtual ~RangeReadPlan() {}                     /* Remove gcc warning */
115
 
 
116
 
  QuickSelectInterface *make_quick(Parameter *param, bool, memory::Root *parent_alloc);
117
 
 
118
 
  void setMRRBufferSize(uint32_t in_mrr_buf_size)
119
 
  {
120
 
    mrr_buf_size= in_mrr_buf_size;
121
 
  }
122
 
 
123
 
  uint32_t getKeyIndex() const
124
 
  {
125
 
    return key_idx;
126
 
  }
127
 
 
128
 
  uint32_t getMRRBufferSize() const
129
 
  {
130
 
    return mrr_buf_size;
131
 
  }
132
 
 
133
 
private:
134
 
 
135
 
  /** set of intervals to be used in "range" method retrieval */
136
 
  SEL_ARG *key;
137
 
  /** key number in Parameter::key */
138
 
  uint32_t     key_idx;
139
 
  uint32_t     mrr_flags;
140
 
  uint32_t     mrr_buf_size;
141
 
 
142
 
};
143
 
 
144
 
 
145
 
/* Plan for QuickRorIntersectSelect scan. */
146
 
class RorIntersectReadPlan : public TableReadPlan
147
 
{
148
 
public:
149
 
 
150
 
  RorIntersectReadPlan() 
151
 
    :
152
 
      ror_range_scans(),
153
 
      cpk_scan(NULL),
154
 
      is_covering(false),
155
 
      index_scan_costs(0.0)
156
 
  {}
157
 
 
158
 
  virtual ~RorIntersectReadPlan() 
159
 
  {
160
 
    std::for_each(ror_range_scans.begin(),
161
 
                  ror_range_scans.end(),
162
 
                  DeletePtr());
163
 
    ror_range_scans.clear();
164
 
  }
165
 
 
166
 
  QuickSelectInterface *make_quick(Parameter *param,
167
 
                                   bool retrieve_full_rows,
168
 
                                   memory::Root *parent_alloc);
169
 
 
170
 
  void setRowRetrievalNecessary(bool in_is_covering)
171
 
  {
172
 
    is_covering= in_is_covering;
173
 
  }
174
 
 
175
 
  void setCostOfIndexScans(double in_index_scan_costs)
176
 
  {
177
 
    index_scan_costs= in_index_scan_costs;
178
 
  }
179
 
 
180
 
  /**
181
 
   * @return true if row retrival phase is necessary.
182
 
   */
183
 
  bool isRowRetrievalNecessary() const
184
 
  {
185
 
    return ! is_covering;
186
 
  }
187
 
 
188
 
  /**
189
 
   * @return the sum of the cost of each index scan
190
 
   */
191
 
  double getCostOfIndexScans() const
192
 
  {
193
 
    return index_scan_costs;
194
 
  }
195
 
 
196
 
  /** Vector of pointers to ROR range scans used in this intersection */
197
 
  std::vector<struct st_ror_scan_info *> ror_range_scans;
198
 
  struct st_ror_scan_info *cpk_scan;  /* Clustered PK scan, if there is one */
199
 
 
200
 
private:
201
 
 
202
 
  /** true if no row retrieval phase is necessary */
203
 
  bool is_covering; 
204
 
  /* SUM(cost(index_scan)) */
205
 
  double index_scan_costs; 
206
 
 
207
 
};
208
 
 
209
 
 
210
 
/*
211
 
  Plan for QuickRorUnionSelect scan.
212
 
  QuickRorUnionSelect always retrieves full rows, so retrieve_full_rows
213
 
  is ignored by make_quick.
214
 
*/
215
 
 
216
 
class RorUnionReadPlan : public TableReadPlan
217
 
{
218
 
public:
219
 
  RorUnionReadPlan() {}                          /* Remove gcc warning */
220
 
  virtual ~RorUnionReadPlan() {}                 /* Remove gcc warning */
221
 
  QuickSelectInterface *make_quick(Parameter *param,
222
 
                                   bool retrieve_full_rows,
223
 
                                   memory::Root *parent_alloc);
224
 
  /** vector of plans for merged scans */
225
 
  std::vector<TableReadPlan *> merged_scans;
226
 
};
227
 
 
228
 
 
229
 
/*
230
 
  Plan for QuickIndexMergeSelect scan.
231
 
  QuickRorIntersectSelect always retrieves full rows, so retrieve_full_rows
232
 
  is ignored by make_quick.
233
 
*/
234
 
 
235
 
class IndexMergeReadPlan : public TableReadPlan
236
 
{
237
 
public:
238
 
  IndexMergeReadPlan() {}                        /* Remove gcc warning */
239
 
  virtual ~IndexMergeReadPlan() {}               /* Remove gcc warning */
240
 
  QuickSelectInterface *make_quick(Parameter *param,
241
 
                                   bool retrieve_full_rows,
242
 
                                   memory::Root *parent_alloc);
243
 
  RangeReadPlan **range_scans; /* array of ptrs to plans of merged scans */
244
 
  RangeReadPlan **range_scans_end; /* end of the array */
245
 
};
246
 
 
247
 
 
248
 
/*
249
 
  Plan for a QuickGroupMinMaxSelect scan.
250
 
*/
251
 
 
252
 
class GroupMinMaxReadPlan : public TableReadPlan
253
 
{
254
 
 
255
 
public:
256
 
 
257
 
  GroupMinMaxReadPlan(bool have_min_arg, 
258
 
                      bool have_max_arg,
259
 
                      KEY_PART_INFO *min_max_arg_part_arg,
260
 
                      uint32_t group_prefix_len_arg, 
261
 
                      uint32_t used_key_parts_arg,
262
 
                      uint32_t group_key_parts_arg, 
263
 
                      KEY *index_info_arg,
264
 
                      uint32_t index_arg, 
265
 
                      uint32_t key_infix_len_arg,
266
 
                      unsigned char *key_infix_arg,
267
 
                      SEL_TREE *tree_arg, 
268
 
                      SEL_ARG *index_tree_arg,
269
 
                      uint32_t param_idx_arg, 
270
 
                      ha_rows quick_prefix_records_arg)
271
 
    :
272
 
      quick_prefix_records(quick_prefix_records_arg),
273
 
      have_min(have_min_arg),
274
 
      have_max(have_max_arg),
275
 
      min_max_arg_part(min_max_arg_part_arg),
276
 
      group_prefix_len(group_prefix_len_arg),
277
 
      used_key_parts(used_key_parts_arg),
278
 
      group_key_parts(group_key_parts_arg),
279
 
      index_info(index_info_arg),
280
 
      index(index_arg),
281
 
      key_infix_len(key_infix_len_arg),
282
 
      range_tree(tree_arg),
283
 
      index_tree(index_tree_arg),
284
 
      param_idx(param_idx_arg)
285
 
    {
286
 
      if (key_infix_len)
287
 
        memcpy(this->key_infix, key_infix_arg, key_infix_len);
288
 
    }
289
 
  virtual ~GroupMinMaxReadPlan() {}             /* Remove gcc warning */
290
 
 
291
 
  QuickSelectInterface *make_quick(Parameter *param,
292
 
                                   bool retrieve_full_rows,
293
 
                                   memory::Root *parent_alloc);
294
 
 
295
 
  /* Number of records selected by the ranges in index_tree. */
296
 
  ha_rows quick_prefix_records;
297
 
 
298
 
private:
299
 
 
300
 
  bool have_min;
301
 
  bool have_max;
302
 
  KEY_PART_INFO *min_max_arg_part;
303
 
  uint32_t group_prefix_len;
304
 
  uint32_t used_key_parts;
305
 
  uint32_t group_key_parts;
306
 
  KEY *index_info;
307
 
  uint32_t index;
308
 
  uint32_t key_infix_len;
309
 
  unsigned char key_infix[MAX_KEY_LENGTH];
310
 
  SEL_TREE *range_tree; /* Represents all range predicates in the query. */
311
 
  SEL_ARG *index_tree; /* The SEL_ARG sub-tree corresponding to index_info. */
312
 
  uint32_t param_idx; /* Index of used key in param->key. */
313
 
};
314
 
 
315
 
 
316
 
} /* namespace optimizer */
317
 
 
318
 
} /* namespace drizzled */
319
 
 
320
 
#endif /* DRIZZLED_OPTIMIZER_TABLE_READ_PLAN_H */