~jaypipes/drizzle/transaction_log

« back to all changes in this revision

Viewing changes to drizzled/optimizer/table_read_plan.h

  • Committer: Jay Pipes
  • Date: 2009-12-22 03:07:38 UTC
  • mfrom: (1143.14.85 build)
  • Revision ID: jpipes@serialcoder-20091222030738-gnb0vyg77fmkt4cj
Merge trunk

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