~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_select.h

  • Committer: Eric Day
  • Date: 2009-08-27 18:06:03 UTC
  • mfrom: (1125 staging)
  • mto: This revision was merged to the branch mainline in revision 1131.
  • Revision ID: eday@oddments.org-20090827180603-hy264dq4s78dptdo
Merged trunk.

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>
 
29
#include <drizzled/optimizer/sargable_param.h>
28
30
#include "drizzled/join_cache.h"
29
31
#include "drizzled/join_table.h"
30
32
 
 
33
#include <vector>
 
34
 
31
35
 
32
36
class select_result;
33
37
 
81
85
enum_nested_loop_state end_send_group(JOIN *join, JoinTable *join_tab, bool end_of_records);
82
86
enum_nested_loop_state end_write_group(JOIN *join, JoinTable *join_tab, bool end_of_records);
83
87
 
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
 
      use_insideout_scan(false)
100
 
  {}
101
 
 
102
 
  /**
103
 
   * Determine whether the table this particular position is representing in
104
 
   * the query plan is a const table or not. A constant table is defined as
105
 
   * (taken from the MySQL optimizer internals document on MySQL forge):
106
 
   *
107
 
   * 1) A table with zero rows, or with only one row
108
 
   * 2) A table expression that is restricted with a WHERE condition
109
 
   *
110
 
   * Based on the definition above, when records_read is set to 1.0 in the
111
 
   * Position class, it infers that this position in the partial plan
112
 
   * represents a const table.
113
 
   *
114
 
   * @return true if this position represents a const table; false otherwise
115
 
   */
116
 
  bool isConstTable() const
117
 
  {
118
 
    return (records_read < 2.0);
119
 
  }
120
 
 
121
 
  /**
122
 
    The "fanout": number of output rows that will be produced (after
123
 
    pushed down selection condition is applied) per each row combination of
124
 
    previous tables. The value is an in-precise estimate.
125
 
  */
126
 
  double records_read;
127
 
 
128
 
  /**
129
 
    Cost accessing the table in course of the entire complete join execution,
130
 
    i.e. cost of one access method use (e.g. 'range' or 'ref' scan ) times
131
 
    number the access method will be invoked.
132
 
  */
133
 
  double read_time;
134
 
  JoinTable *table;
135
 
 
136
 
  /**
137
 
    NULL  -  'index' or 'range' or 'index_merge' or 'ALL' access is used.
138
 
    Other - [eq_]ref[_or_null] access is used. Pointer to {t.keypart1 = expr}
139
 
  */
140
 
  KeyUse *key;
141
 
 
142
 
  /** If ref-based access is used: bitmap of tables this table depends on  */
143
 
  table_map ref_depend_map;
144
 
 
145
 
  bool use_insideout_scan;
146
 
};
147
 
 
148
88
typedef struct st_rollup
149
89
{
150
90
  enum State { STATE_NONE, STATE_INITED, STATE_READY };
156
96
 
157
97
#include "drizzled/join.h"
158
98
 
159
 
typedef struct st_select_check {
160
 
  uint32_t const_ref,reg_ref;
161
 
} SELECT_CHECK;
162
 
 
163
 
/*
164
 
   This structure is used to collect info on potentially sargable
165
 
   predicates in order to check whether they become sargable after
166
 
   reading const tables.
167
 
   We form a bitmap of indexes that can be used for sargable predicates.
168
 
   Only such indexes are involved in range analysis.
169
 
*/
170
 
typedef struct st_sargable_param
171
 
{
172
 
  Field *field;              /* field against which to check sargability */
173
 
  Item **arg_value;          /* values of potential keys for lookups     */
174
 
  uint32_t num_values;           /* number of values in the above array      */
175
 
} SARGABLE_PARAM;
176
 
 
177
 
/**
178
 
 * Structure used when finding key fields
179
 
 */
180
 
typedef struct key_field_t 
181
 
{
182
 
  Field *field;
183
 
  Item *val; /**< May be empty if diff constant */
184
 
  uint32_t level;
185
 
  uint32_t optimize; /**< KEY_OPTIMIZE_* */
186
 
  bool eq_func;
187
 
  /**
188
 
    If true, the condition this struct represents will not be satisfied
189
 
    when val IS NULL.
190
 
  */
191
 
  bool null_rejecting;
192
 
  bool *cond_guard; /**< @see KeyUse::cond_guard */
193
 
} KEY_FIELD;
194
 
 
195
99
/*****************************************************************************
196
100
  Make som simple condition optimization:
197
101
  If there is a test 'field = const' change all refs to 'field' to 'const'
266
170
bool change_group_ref(Session *session, Item_func *expr, order_st *group_list, bool *changed);
267
171
bool check_interleaving_with_nj(JoinTable *last, JoinTable *next);
268
172
 
269
 
int join_read_const_table(JoinTable *tab, Position *pos);
 
173
int join_read_const_table(JoinTable *tab, drizzled::optimizer::Position *pos);
270
174
int join_read_system(JoinTable *tab);
271
175
int join_read_const(JoinTable *tab);
272
176
int join_read_key(JoinTable *tab);
324
228
                         COND_EQUAL *,
325
229
                         table_map normal_tables,
326
230
                         Select_Lex *select_lex,
327
 
                         SARGABLE_PARAM **sargables);
 
231
                         std::vector<drizzled::optimizer::SargableParam> &sargables);
328
232
ha_rows get_quick_record_count(Session *session, SQL_SELECT *select, Table *table, const key_map *keys,ha_rows limit);
329
233
void optimize_keyuse(JOIN *join, DYNAMIC_ARRAY *keyuse_array);
330
234
void add_group_and_distinct_keys(JOIN *join, JoinTable *join_tab);