~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/optimizer/table_read_plan.h

  • Committer: Brian Aker
  • Date: 2009-10-15 00:22:33 UTC
  • mto: (1183.1.11 merge)
  • mto: This revision was merged to the branch mainline in revision 1198.
  • Revision ID: brian@gaz-20091015002233-fa4ao2mbc67wls91
First pass of information engine. OMG, ponies... is it so much easier to
deal with creating and engine.

The list table iterator though... its ass, needs to go. We should also
abstract out share. Very few engines need a custom one. Just say'in

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
 
namespace optimizer
30
 
{
31
 
 
32
 
class Parameter;
33
 
class SEL_ARG;
34
 
class SEL_TREE;
35
 
class RorScanInfo;
36
 
 
37
 
/*
38
 
  Table rows retrieval plan. Range optimizer creates QuickSelectInterface-derived
39
 
  objects from table read plans.
40
 
*/
41
 
class TableReadPlan
42
 
{
43
 
public:
44
 
  /*
45
 
    Plan read cost, with or without cost of full row retrieval, depending
46
 
    on plan creation parameters.
47
 
  */
48
 
  double read_cost;
49
 
  ha_rows records; /* estimate of #rows to be examined */
50
 
 
51
 
  /*
52
 
    If true, the scan returns rows in rowid order. This is used only for
53
 
    scans that can be both ROR and non-ROR.
54
 
  */
55
 
  bool is_ror;
56
 
 
57
 
  /*
58
 
    Create quick select for this plan.
59
 
    SYNOPSIS
60
 
     make_quick()
61
 
       param               Parameter from test_quick_select
62
 
       retrieve_full_rows  If true, created quick select will do full record
63
 
                           retrieval.
64
 
       parent_alloc        Memory pool to use, if any.
65
 
 
66
 
    NOTES
67
 
      retrieve_full_rows is ignored by some implementations.
68
 
 
69
 
    RETURN
70
 
      created quick select
71
 
      NULL on any error.
72
 
  */
73
 
  virtual QuickSelectInterface *make_quick(Parameter *param,
74
 
                                           bool retrieve_full_rows,
75
 
                                           memory::Root *parent_alloc= NULL) = 0;
76
 
 
77
 
  /* Table read plans are allocated on memory::Root and are never deleted */
78
 
  static void *operator new(size_t size, memory::Root *mem_root)
79
 
  { 
80
 
    return (void*) mem_root->alloc_root((uint32_t) size); 
81
 
  }
82
 
 
83
 
  static void operator delete(void *, size_t)
84
 
  { }
85
 
 
86
 
  static void operator delete(void *, memory::Root *)
87
 
    { /* Never called */ }
88
 
 
89
 
  virtual ~TableReadPlan() {} /* Remove gcc warning */
90
 
 
91
 
};
92
 
 
93
 
 
94
 
/*
95
 
  Plan for a QuickRangeSelect scan.
96
 
  RangeReadPlan::make_quick ignores retrieve_full_rows parameter because
97
 
  QuickRangeSelect doesn't distinguish between 'index only' scans and full
98
 
  record retrieval scans.
99
 
*/
100
 
class RangeReadPlan : public TableReadPlan
101
 
{
102
 
 
103
 
public:
104
 
 
105
 
  SEL_ARG *key; /* set of intervals to be used in "range" method retrieval */
106
 
  uint32_t     key_idx; /* key number in Parameter::key */
107
 
  uint32_t     mrr_flags;
108
 
  uint32_t     mrr_buf_size;
109
 
 
110
 
  RangeReadPlan(SEL_ARG *key_arg, uint32_t idx_arg, uint32_t mrr_flags_arg)
111
 
    :
112
 
      key(key_arg),
113
 
      key_idx(idx_arg),
114
 
      mrr_flags(mrr_flags_arg)
115
 
  {}
116
 
  virtual ~RangeReadPlan() {}                     /* Remove gcc warning */
117
 
 
118
 
  QuickSelectInterface *make_quick(Parameter *param, bool, memory::Root *parent_alloc);
119
 
 
120
 
};
121
 
 
122
 
 
123
 
/* Plan for QuickRorIntersectSelect scan. */
124
 
class RorIntersectReadPlan : public TableReadPlan
125
 
{
126
 
public:
127
 
 
128
 
  RorIntersectReadPlan() {}                      /* Remove gcc warning */
129
 
  virtual ~RorIntersectReadPlan() {}             /* Remove gcc warning */
130
 
 
131
 
  QuickSelectInterface *make_quick(Parameter *param,
132
 
                                   bool retrieve_full_rows,
133
 
                                   memory::Root *parent_alloc);
134
 
 
135
 
  /* Array of pointers to ROR range scans used in this intersection */
136
 
  RorScanInfo **first_scan;
137
 
  RorScanInfo **last_scan; /* End of the above array */
138
 
  RorScanInfo *cpk_scan;  /* Clustered PK scan, if there is one */
139
 
 
140
 
  bool is_covering; /* true if no row retrieval phase is necessary */
141
 
  double index_scan_costs; /* SUM(cost(index_scan)) */
142
 
 
143
 
};
144
 
 
145
 
 
146
 
/*
147
 
  Plan for QuickRorUnionSelect scan.
148
 
  QuickRorUnionSelect always retrieves full rows, so retrieve_full_rows
149
 
  is ignored by make_quick.
150
 
*/
151
 
 
152
 
class RorUnionReadPlan : public TableReadPlan
153
 
{
154
 
public:
155
 
  RorUnionReadPlan() {}                          /* Remove gcc warning */
156
 
  virtual ~RorUnionReadPlan() {}                 /* Remove gcc warning */
157
 
  QuickSelectInterface *make_quick(Parameter *param,
158
 
                                   bool retrieve_full_rows,
159
 
                                   memory::Root *parent_alloc);
160
 
  TableReadPlan **first_ror; /* array of ptrs to plans for merged scans */
161
 
  TableReadPlan **last_ror;  /* end of the above array */
162
 
};
163
 
 
164
 
 
165
 
/*
166
 
  Plan for QuickIndexMergeSelect scan.
167
 
  QuickRorIntersectSelect always retrieves full rows, so retrieve_full_rows
168
 
  is ignored by make_quick.
169
 
*/
170
 
 
171
 
class IndexMergeReadPlan : public TableReadPlan
172
 
{
173
 
public:
174
 
  IndexMergeReadPlan() {}                        /* Remove gcc warning */
175
 
  virtual ~IndexMergeReadPlan() {}               /* Remove gcc warning */
176
 
  QuickSelectInterface *make_quick(Parameter *param,
177
 
                                   bool retrieve_full_rows,
178
 
                                   memory::Root *parent_alloc);
179
 
  RangeReadPlan **range_scans; /* array of ptrs to plans of merged scans */
180
 
  RangeReadPlan **range_scans_end; /* end of the array */
181
 
};
182
 
 
183
 
 
184
 
/*
185
 
  Plan for a QuickGroupMinMaxSelect scan.
186
 
*/
187
 
 
188
 
class GroupMinMaxReadPlan : public TableReadPlan
189
 
{
190
 
private:
191
 
  bool have_min;
192
 
  bool have_max;
193
 
  KeyPartInfo *min_max_arg_part;
194
 
  uint32_t group_prefix_len;
195
 
  uint32_t used_key_parts;
196
 
  uint32_t group_key_parts;
197
 
  KeyInfo *index_info;
198
 
  uint32_t index;
199
 
  uint32_t key_infix_len;
200
 
  unsigned char key_infix[MAX_KEY_LENGTH];
201
 
  SEL_TREE *range_tree; /* Represents all range predicates in the query. */
202
 
  SEL_ARG *index_tree; /* The SEL_ARG sub-tree corresponding to index_info. */
203
 
  uint32_t param_idx; /* Index of used key in param->key. */
204
 
  /* Number of records selected by the ranges in index_tree. */
205
 
public:
206
 
  ha_rows quick_prefix_records;
207
 
 
208
 
public:
209
 
  GroupMinMaxReadPlan(bool have_min_arg, 
210
 
                      bool have_max_arg,
211
 
                      KeyPartInfo *min_max_arg_part_arg,
212
 
                      uint32_t group_prefix_len_arg, 
213
 
                      uint32_t used_key_parts_arg,
214
 
                      uint32_t group_key_parts_arg, 
215
 
                      KeyInfo *index_info_arg,
216
 
                      uint32_t index_arg, 
217
 
                      uint32_t key_infix_len_arg,
218
 
                      unsigned char *key_infix_arg,
219
 
                      SEL_TREE *tree_arg, 
220
 
                      SEL_ARG *index_tree_arg,
221
 
                      uint32_t param_idx_arg, 
222
 
                      ha_rows quick_prefix_records_arg)
223
 
    :
224
 
      have_min(have_min_arg),
225
 
      have_max(have_max_arg),
226
 
      min_max_arg_part(min_max_arg_part_arg),
227
 
      group_prefix_len(group_prefix_len_arg),
228
 
      used_key_parts(used_key_parts_arg),
229
 
      group_key_parts(group_key_parts_arg),
230
 
      index_info(index_info_arg),
231
 
      index(index_arg),
232
 
      key_infix_len(key_infix_len_arg),
233
 
      range_tree(tree_arg),
234
 
      index_tree(index_tree_arg),
235
 
      param_idx(param_idx_arg),
236
 
      quick_prefix_records(quick_prefix_records_arg)
237
 
    {
238
 
      if (key_infix_len)
239
 
        memcpy(this->key_infix, key_infix_arg, key_infix_len);
240
 
    }
241
 
  virtual ~GroupMinMaxReadPlan() {}             /* Remove gcc warning */
242
 
 
243
 
  QuickSelectInterface *make_quick(Parameter *param,
244
 
                                   bool retrieve_full_rows,
245
 
                                   memory::Root *parent_alloc);
246
 
};
247
 
 
248
 
 
249
 
} /* namespace optimizer */
250
 
 
251
 
} /* namespace drizzled */
252
 
 
253
 
#endif /* DRIZZLED_OPTIMIZER_TABLE_READ_PLAN_H */