~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/optimizer/table_read_plan.h

  • Committer: Patrick Crews
  • Date: 2011-01-29 14:17:35 UTC
  • mto: (2126.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2127.
  • Revision ID: gleebix@gmail.com-20110129141735-3y2658vt5ur0a33o
Fixes to make test-dbqp

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008-2009 Sun Microsystems
 
4
 *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
26
26
namespace drizzled
27
27
{
28
28
 
29
 
struct st_ror_scan_info;
30
 
 
31
29
namespace optimizer
32
30
{
33
31
 
34
32
class Parameter;
35
33
class SEL_ARG;
36
34
class SEL_TREE;
 
35
class RorScanInfo;
37
36
 
38
37
/*
39
38
  Table rows retrieval plan. Range optimizer creates QuickSelectInterface-derived
78
77
  /* Table read plans are allocated on memory::Root and are never deleted */
79
78
  static void *operator new(size_t size, memory::Root *mem_root)
80
79
  { 
81
 
    return (void*) alloc_root(mem_root, (uint32_t) size); 
 
80
    return (void*) mem_root->alloc_root((uint32_t) size); 
82
81
  }
83
82
 
84
83
  static void operator delete(void *, size_t)
103
102
 
104
103
public:
105
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
 
106
110
  RangeReadPlan(SEL_ARG *key_arg, uint32_t idx_arg, uint32_t mrr_flags_arg)
107
111
    :
108
112
      key(key_arg),
109
113
      key_idx(idx_arg),
110
 
      mrr_flags(mrr_flags_arg),
111
 
      mrr_buf_size(0)
 
114
      mrr_flags(mrr_flags_arg)
112
115
  {}
113
 
 
114
116
  virtual ~RangeReadPlan() {}                     /* Remove gcc warning */
115
117
 
116
118
  QuickSelectInterface *make_quick(Parameter *param, bool, memory::Root *parent_alloc);
117
119
 
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
120
};
143
121
 
144
122
 
147
125
{
148
126
public:
149
127
 
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
 
  }
 
128
  RorIntersectReadPlan() {}                      /* Remove gcc warning */
 
129
  virtual ~RorIntersectReadPlan() {}             /* Remove gcc warning */
165
130
 
166
131
  QuickSelectInterface *make_quick(Parameter *param,
167
132
                                   bool retrieve_full_rows,
168
133
                                   memory::Root *parent_alloc);
169
134
 
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; 
 
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)) */
206
142
 
207
143
};
208
144
 
221
157
  QuickSelectInterface *make_quick(Parameter *param,
222
158
                                   bool retrieve_full_rows,
223
159
                                   memory::Root *parent_alloc);
224
 
  /** vector of plans for merged scans */
225
 
  std::vector<TableReadPlan *> merged_scans;
 
160
  TableReadPlan **first_ror; /* array of ptrs to plans for merged scans */
 
161
  TableReadPlan **last_ror;  /* end of the above array */
226
162
};
227
163
 
228
164
 
251
187
 
252
188
class GroupMinMaxReadPlan : public TableReadPlan
253
189
{
254
 
 
255
 
public:
256
 
 
 
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:
257
209
  GroupMinMaxReadPlan(bool have_min_arg, 
258
210
                      bool have_max_arg,
259
 
                      KEY_PART_INFO *min_max_arg_part_arg,
 
211
                      KeyPartInfo *min_max_arg_part_arg,
260
212
                      uint32_t group_prefix_len_arg, 
261
213
                      uint32_t used_key_parts_arg,
262
214
                      uint32_t group_key_parts_arg, 
263
 
                      KEY *index_info_arg,
 
215
                      KeyInfo *index_info_arg,
264
216
                      uint32_t index_arg, 
265
217
                      uint32_t key_infix_len_arg,
266
218
                      unsigned char *key_infix_arg,
269
221
                      uint32_t param_idx_arg, 
270
222
                      ha_rows quick_prefix_records_arg)
271
223
    :
272
 
      quick_prefix_records(quick_prefix_records_arg),
273
224
      have_min(have_min_arg),
274
225
      have_max(have_max_arg),
275
226
      min_max_arg_part(min_max_arg_part_arg),
281
232
      key_infix_len(key_infix_len_arg),
282
233
      range_tree(tree_arg),
283
234
      index_tree(index_tree_arg),
284
 
      param_idx(param_idx_arg)
 
235
      param_idx(param_idx_arg),
 
236
      quick_prefix_records(quick_prefix_records_arg)
285
237
    {
286
238
      if (key_infix_len)
287
239
        memcpy(this->key_infix, key_infix_arg, key_infix_len);
291
243
  QuickSelectInterface *make_quick(Parameter *param,
292
244
                                   bool retrieve_full_rows,
293
245
                                   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
246
};
314
247
 
315
248