~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_select.h

  • Committer: Padraig O'Sullivan
  • Date: 2009-08-10 23:35:59 UTC
  • mto: (1115.3.10 captain)
  • mto: This revision was merged to the branch mainline in revision 1120.
  • Revision ID: osullivan.padraig@gmail.com-20090810233559-2ax654ye148d7fst
Added an optimizer namespace and sub-directory within drizzled. Moved the
Position class into its own header file within this sub-dir and declared the
Position class within the drizzled::optimizer namespace.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "drizzled/field/varstring.h"
26
26
#include "drizzled/item/null.h"
27
27
#include <drizzled/enum_nested_loop_state.h>
 
28
#include <drizzled/optimizer/position.h>
28
29
#include "drizzled/join_cache.h"
29
30
#include "drizzled/join_table.h"
30
31
 
81
82
enum_nested_loop_state end_send_group(JOIN *join, JoinTable *join_tab, bool end_of_records);
82
83
enum_nested_loop_state end_write_group(JOIN *join, JoinTable *join_tab, bool end_of_records);
83
84
 
84
 
/**
85
 
 * Information about a position of table within a join order. Used in join
86
 
 * optimization.
87
 
 */
88
 
class Position
89
 
{
90
 
public:
91
 
 
92
 
  Position()
93
 
    :
94
 
      records_read(0),
95
 
      read_time(0),
96
 
      table(NULL),
97
 
      key(NULL),
98
 
      ref_depend_map(0)
99
 
  {}
100
 
 
101
 
  Position(double in_records_read,
102
 
           double in_read_time,
103
 
           JoinTable *in_table,
104
 
           KeyUse *in_key,
105
 
           table_map in_ref_depend_map)
106
 
    :
107
 
      records_read(in_records_read),
108
 
      read_time(in_read_time),
109
 
      table(in_table),
110
 
      key(in_key),
111
 
      ref_depend_map(in_ref_depend_map)
112
 
  {}
113
 
 
114
 
  /**
115
 
   * Determine whether the table this particular position is representing in
116
 
   * the query plan is a const table or not. A constant table is defined as
117
 
   * (taken from the MySQL optimizer internals document on MySQL forge):
118
 
   *
119
 
   * 1) A table with zero rows, or with only one row
120
 
   * 2) A table expression that is restricted with a WHERE condition
121
 
   *
122
 
   * Based on the definition above, when records_read is set to 1.0 in the
123
 
   * Position class, it infers that this position in the partial plan
124
 
   * represents a const table.
125
 
   *
126
 
   * @return true if this position represents a const table; false otherwise
127
 
   */
128
 
  bool isConstTable() const
129
 
  {
130
 
    return (records_read < 2.0);
131
 
  }
132
 
 
133
 
  double getFanout() const
134
 
  {
135
 
    return records_read;
136
 
  }
137
 
 
138
 
  void setFanout(double in_records_read)
139
 
  {
140
 
    records_read= in_records_read;
141
 
  }
142
 
 
143
 
  double getCost() const
144
 
  {
145
 
    return read_time;
146
 
  }
147
 
 
148
 
  JoinTable *getJoinTable()
149
 
  {
150
 
    return table;
151
 
  }
152
 
 
153
 
  /**
154
 
   * Check to see if the table attached to the JoinTable for this position
155
 
   * has an index that can produce an ordering. 
156
 
   *
157
 
   * @return true if the table attached to the JoinTable for this position
158
 
   * does not have an index that can produce an ordering; false otherwise
159
 
   */
160
 
  bool hasTableForSorting(Table *cmp_table) const
161
 
  {
162
 
    return (cmp_table != table->table);
163
 
  }
164
 
 
165
 
  bool examinePosition(table_map found_ref)
166
 
  {
167
 
    if (table->table->map & found_ref)
168
 
    {
169
 
      return true;
170
 
    }
171
 
    return false;
172
 
  }
173
 
 
174
 
  KeyUse *getKeyUse()
175
 
  {
176
 
    return key;
177
 
  }
178
 
 
179
 
  table_map getRefDependMap()
180
 
  {
181
 
    return ref_depend_map;
182
 
  }
183
 
 
184
 
  void clearRefDependMap()
185
 
  {
186
 
    ref_depend_map= 0;
187
 
  }
188
 
 
189
 
private:
190
 
 
191
 
  /**
192
 
    The "fanout": number of output rows that will be produced (after
193
 
    pushed down selection condition is applied) per each row combination of
194
 
    previous tables. The value is an in-precise estimate.
195
 
  */
196
 
  double records_read;
197
 
 
198
 
  /**
199
 
    Cost accessing the table in course of the entire complete join execution,
200
 
    i.e. cost of one access method use (e.g. 'range' or 'ref' scan ) times
201
 
    number the access method will be invoked.
202
 
  */
203
 
  double read_time;
204
 
 
205
 
  JoinTable *table;
206
 
 
207
 
  /**
208
 
    NULL  -  'index' or 'range' or 'index_merge' or 'ALL' access is used.
209
 
    Other - [eq_]ref[_or_null] access is used. Pointer to {t.keypart1 = expr}
210
 
  */
211
 
  KeyUse *key;
212
 
 
213
 
  /** If ref-based access is used: bitmap of tables this table depends on  */
214
 
  table_map ref_depend_map;
215
 
 
216
 
};
217
 
 
218
85
typedef struct st_rollup
219
86
{
220
87
  enum State { STATE_NONE, STATE_INITED, STATE_READY };
332
199
bool change_group_ref(Session *session, Item_func *expr, order_st *group_list, bool *changed);
333
200
bool check_interleaving_with_nj(JoinTable *last, JoinTable *next);
334
201
 
335
 
int join_read_const_table(JoinTable *tab, Position *pos);
 
202
int join_read_const_table(JoinTable *tab, drizzled::optimizer::Position *pos);
336
203
int join_read_system(JoinTable *tab);
337
204
int join_read_const(JoinTable *tab);
338
205
int join_read_key(JoinTable *tab);