~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_select.h

  • Committer: Monty Taylor
  • Date: 2009-08-17 18:46:08 UTC
  • mto: (1182.1.1 staging)
  • mto: This revision was merged to the branch mainline in revision 1183.
  • Revision ID: mordred@inaugust.com-20090817184608-0b2emowpjr9m6le7
"Fixed" the deadlock test. I'd still like someone to look at what's going on here.

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"
30
 
#include "drizzled/optimizer/key_use.h"
31
28
#include "drizzled/join_cache.h"
32
29
#include "drizzled/join_table.h"
33
30
 
34
 
#include <vector>
35
 
 
36
 
namespace drizzled
37
 
{
38
31
 
39
32
class select_result;
40
33
 
45
38
/* PREV_BITS only used in sql_select.cc */
46
39
#define PREV_BITS(type,A)       ((type) (((type) 1 << (A)) -1))
47
40
 
 
41
#include <plugin/myisam/myisam.h>
 
42
#include <drizzled/sql_array.h>
 
43
 
48
44
/* Values in optimize */
49
45
#define KEY_OPTIMIZE_EXISTS             1
50
46
#define KEY_OPTIMIZE_REF_OR_NULL        2
51
47
 
 
48
class KeyUse 
 
49
{
 
50
public:
 
51
  Table *table; /**< Pointer to the table this key belongs to */
 
52
  Item *val;    /**< or value if no field */
 
53
  table_map used_tables;
 
54
  uint32_t key;
 
55
  uint32_t keypart;
 
56
  uint32_t optimize; /**< 0, or KEY_OPTIMIZE_* */
 
57
  key_part_map keypart_map;
 
58
  ha_rows ref_table_rows;
 
59
  /**
 
60
    If true, the comparison this value was created from will not be
 
61
    satisfied if val has NULL 'value'.
 
62
  */
 
63
  bool null_rejecting;
 
64
  /**
 
65
    !NULL - This KeyUse was created from an equality that was wrapped into
 
66
            an Item_func_trig_cond. This means the equality (and validity of
 
67
            this KeyUse element) can be turned on and off. The on/off state
 
68
            is indicted by the pointed value:
 
69
              *cond_guard == true <=> equality condition is on
 
70
              *cond_guard == false <=> equality condition is off
 
71
 
 
72
    NULL  - Otherwise (the source equality can't be turned off)
 
73
  */
 
74
  bool *cond_guard;
 
75
};
 
76
 
52
77
class JOIN;
53
78
 
54
79
enum_nested_loop_state sub_select_cache(JOIN *join, JoinTable *join_tab, bool end_of_records);
56
81
enum_nested_loop_state end_send_group(JOIN *join, JoinTable *join_tab, bool end_of_records);
57
82
enum_nested_loop_state end_write_group(JOIN *join, JoinTable *join_tab, bool end_of_records);
58
83
 
 
84
/**
 
85
 * Information about a position of table within a join order. Used in join
 
86
 * optimization.
 
87
 */
 
88
typedef struct st_position
 
89
{
 
90
  /**
 
91
    The "fanout": number of output rows that will be produced (after
 
92
    pushed down selection condition is applied) per each row combination of
 
93
    previous tables.
 
94
  */
 
95
  double records_read;
 
96
 
 
97
  /**
 
98
    Cost accessing the table in course of the entire complete join execution,
 
99
    i.e. cost of one access method use (e.g. 'range' or 'ref' scan ) times
 
100
    number the access method will be invoked.
 
101
  */
 
102
  double read_time;
 
103
  JoinTable *table;
 
104
 
 
105
  /**
 
106
    NULL  -  'index' or 'range' or 'index_merge' or 'ALL' access is used.
 
107
    Other - [eq_]ref[_or_null] access is used. Pointer to {t.keypart1 = expr}
 
108
  */
 
109
  KeyUse *key;
 
110
 
 
111
  /** If ref-based access is used: bitmap of tables this table depends on  */
 
112
  table_map ref_depend_map;
 
113
 
 
114
  bool use_insideout_scan;
 
115
} POSITION;
 
116
 
59
117
typedef struct st_rollup
60
118
{
61
119
  enum State { STATE_NONE, STATE_INITED, STATE_READY };
65
123
  List<Item> *fields;
66
124
} ROLLUP;
67
125
 
68
 
} /* namespace drizzled */
69
 
 
70
 
/** @TODO why is this in the middle of the file??? */
71
 
 
72
126
#include "drizzled/join.h"
73
127
 
74
 
namespace drizzled
75
 
{
 
128
typedef struct st_select_check {
 
129
  uint32_t const_ref,reg_ref;
 
130
} SELECT_CHECK;
 
131
 
 
132
/*
 
133
   This structure is used to collect info on potentially sargable
 
134
   predicates in order to check whether they become sargable after
 
135
   reading const tables.
 
136
   We form a bitmap of indexes that can be used for sargable predicates.
 
137
   Only such indexes are involved in range analysis.
 
138
*/
 
139
typedef struct st_sargable_param
 
140
{
 
141
  Field *field;              /* field against which to check sargability */
 
142
  Item **arg_value;          /* values of potential keys for lookups     */
 
143
  uint32_t num_values;           /* number of values in the above array      */
 
144
} SARGABLE_PARAM;
 
145
 
 
146
/**
 
147
 * Structure used when finding key fields
 
148
 */
 
149
typedef struct key_field_t 
 
150
{
 
151
  Field *field;
 
152
  Item *val; /**< May be empty if diff constant */
 
153
  uint32_t level;
 
154
  uint32_t optimize; /**< KEY_OPTIMIZE_* */
 
155
  bool eq_func;
 
156
  /**
 
157
    If true, the condition this struct represents will not be satisfied
 
158
    when val IS NULL.
 
159
  */
 
160
  bool null_rejecting;
 
161
  bool *cond_guard; /**< @see KeyUse::cond_guard */
 
162
} KEY_FIELD;
76
163
 
77
164
/*****************************************************************************
78
165
  Make som simple condition optimization:
88
175
  COND_CMP(Item *a,Item_func *b) :and_level(a),cmp_func(b) {}
89
176
};
90
177
 
 
178
extern const char *join_type_str[];
91
179
void TEST_join(JOIN *join);
92
180
 
93
181
/* Extern functions in sql_select.cc */
144
232
                               List<Item> &res_all_fields,
145
233
                               uint32_t elements,
146
234
                                                 List<Item> &all_fields);
 
235
void select_describe(JOIN *join, bool need_tmp_table,bool need_order, bool distinct, const char *message= NULL);
147
236
bool change_group_ref(Session *session, Item_func *expr, order_st *group_list, bool *changed);
148
237
bool check_interleaving_with_nj(JoinTable *last, JoinTable *next);
149
238
 
150
 
int join_read_const_table(JoinTable *tab, optimizer::Position *pos);
 
239
int join_read_const_table(JoinTable *tab, POSITION *pos);
151
240
int join_read_system(JoinTable *tab);
152
241
int join_read_const(JoinTable *tab);
153
242
int join_read_key(JoinTable *tab);
171
260
 
172
261
void calc_used_field_length(Session *, JoinTable *join_tab);
173
262
StoredKey *get_store_key(Session *session, 
174
 
                         optimizer::KeyUse *keyuse,
 
263
                         KeyUse *keyuse,
175
264
                         table_map used_tables,
176
265
                         KEY_PART_INFO *key_part,
177
266
                         unsigned char *key_buff,
178
267
                         uint32_t maybe_null);
179
 
int join_tab_cmp(const void* ptr1, const void* ptr2);
180
 
int join_tab_cmp_straight(const void* ptr1, const void* ptr2);
 
268
extern "C" int join_tab_cmp(const void* ptr1, const void* ptr2);
 
269
extern "C" int join_tab_cmp_straight(const void* ptr1, const void* ptr2);
181
270
void push_index_cond(JoinTable *tab, uint32_t keyno, bool other_tbls_ok);
182
271
void add_not_null_conds(JOIN *join);
183
272
uint32_t max_part_bit(key_part_map bits);
189
278
                                List<Item> &all_fields,
190
279
                                bool *all_order_by_fields_used);
191
280
bool eq_ref_table(JOIN *join, order_st *start_order, JoinTable *tab);
 
281
int join_tab_cmp(const void* ptr1, const void* ptr2);
192
282
int remove_dup_with_compare(Session *session, Table *table, Field **first_field, uint32_t offset, Item *having);
193
283
int remove_dup_with_hash_index(Session *session, 
194
284
                               Table *table,
204
294
                         COND_EQUAL *,
205
295
                         table_map normal_tables,
206
296
                         Select_Lex *select_lex,
207
 
                         std::vector<optimizer::SargableParam> &sargables);
208
 
ha_rows get_quick_record_count(Session *session, optimizer::SqlSelect *select, Table *table, const key_map *keys,ha_rows limit);
 
297
                         SARGABLE_PARAM **sargables);
 
298
ha_rows get_quick_record_count(Session *session, SQL_SELECT *select, Table *table, const key_map *keys,ha_rows limit);
209
299
void optimize_keyuse(JOIN *join, DYNAMIC_ARRAY *keyuse_array);
210
300
void add_group_and_distinct_keys(JOIN *join, JoinTable *join_tab);
211
301
void read_cached_record(JoinTable *tab);
212
 
bool mysql_select(Session *session, Item ***rref_pointer_array,
213
 
                  TableList *tables, uint32_t wild_num,  List<Item> &list,
214
 
                  COND *conds, uint32_t og_num, order_st *order, order_st *group,
215
 
                  Item *having, uint64_t select_type,
216
 
                  select_result *result, Select_Lex_Unit *unit,
217
 
                  Select_Lex *select_lex);
218
302
// Create list for using with tempory table
219
303
void init_tmptable_sum_functions(Item_sum **func);
220
304
void update_tmptable_sum_func(Item_sum **func,Table *tmp_table);
221
305
bool only_eq_ref_tables(JOIN *join, order_st *order, table_map tables);
222
 
bool create_ref_for_key(JOIN *join, JoinTable *j, 
223
 
                        optimizer::KeyUse *org_keyuse, 
224
 
                        table_map used_tables);
225
 
 
226
 
} /* namespace drizzled */
227
 
 
228
 
/** @TODO why is this in the middle of the file??? */
 
306
bool create_ref_for_key(JOIN *join, JoinTable *j, KeyUse *org_keyuse, table_map used_tables);
 
307
 
 
308
/* functions from opt_sum.cc */
 
309
bool simple_pred(Item_func *func_item, Item **args, bool *inv_order);
 
310
int opt_sum_query(TableList *tables, List<Item> &all_fields,COND *conds);
 
311
 
 
312
/* from sql_delete.cc, used by opt_range.cc */
 
313
extern "C" int refpos_order_cmp(void* arg, const void *a,const void *b);
229
314
 
230
315
#include "drizzled/stored_key.h"
231
316
 
232
 
namespace drizzled
233
 
{
234
 
 
235
317
bool cp_buffer_from_ref(Session *session, table_reference_st *ref);
236
318
int safe_index_read(JoinTable *tab);
237
319
COND *remove_eq_conds(Session *session, COND *cond, Item::cond_result *cond_value);
240
322
void print_join(Session *session, String *str,
241
323
                List<TableList> *tables, enum_query_type);
242
324
 
243
 
} /* namespace drizzled */
244
 
 
245
325
#endif /* DRIZZLED_SQL_SELECT_H */