~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_select.h

  • Committer: Monty Taylor
  • Date: 2009-12-21 06:46:30 UTC
  • mto: (1253.2.3 out-of-tree)
  • mto: This revision was merged to the branch mainline in revision 1250.
  • Revision ID: mordred@inaugust.com-20091221064630-xaxd6pzqr8djvw3f
Removed global sql_list.h include.

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, Inc.
 
4
 *  Copyright (C) 2008-2009 Sun Microsystems
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
21
21
#define DRIZZLED_SQL_SELECT_H
22
22
 
23
23
#include "drizzled/cached_item.h"
 
24
#include "drizzled/session.h"
24
25
#include "drizzled/field/varstring.h"
25
26
#include "drizzled/item/null.h"
26
27
#include <drizzled/enum_nested_loop_state.h>
29
30
#include "drizzled/optimizer/key_use.h"
30
31
#include "drizzled/join_cache.h"
31
32
#include "drizzled/join_table.h"
32
 
#include "drizzled/records.h"
33
 
#include "drizzled/stored_key.h"
34
33
 
35
34
#include <vector>
36
35
 
37
 
namespace drizzled
38
 
{
39
36
 
40
 
class Item_func;
41
 
class Select_Lex_Unit;
42
37
class select_result;
43
 
class st_dynamic_array;
44
38
 
45
39
/**
46
40
 * @file API and Classes to use when handling where clause
49
43
/* PREV_BITS only used in sql_select.cc */
50
44
#define PREV_BITS(type,A)       ((type) (((type) 1 << (A)) -1))
51
45
 
 
46
#include <plugin/myisam/myisam.h>
 
47
#include <drizzled/sql_array.h>
 
48
 
52
49
/* Values in optimize */
53
50
#define KEY_OPTIMIZE_EXISTS             1
54
51
#define KEY_OPTIMIZE_REF_OR_NULL        2
55
52
 
56
 
class Join;
57
 
 
58
 
enum_nested_loop_state sub_select_cache(Join *join, JoinTable *join_tab, bool end_of_records);
59
 
enum_nested_loop_state sub_select(Join *join,JoinTable *join_tab, bool end_of_records);
60
 
enum_nested_loop_state end_send_group(Join *join, JoinTable *join_tab, bool end_of_records);
61
 
enum_nested_loop_state end_write_group(Join *join, JoinTable *join_tab, bool end_of_records);
62
 
 
63
 
class Rollup
 
53
class JOIN;
 
54
 
 
55
enum_nested_loop_state sub_select_cache(JOIN *join, JoinTable *join_tab, bool end_of_records);
 
56
enum_nested_loop_state sub_select(JOIN *join,JoinTable *join_tab, bool end_of_records);
 
57
enum_nested_loop_state end_send_group(JOIN *join, JoinTable *join_tab, bool end_of_records);
 
58
enum_nested_loop_state end_write_group(JOIN *join, JoinTable *join_tab, bool end_of_records);
 
59
 
 
60
typedef struct st_rollup
64
61
{
65
 
public:
66
62
  enum State { STATE_NONE, STATE_INITED, STATE_READY };
67
 
 
68
 
  Rollup()
69
 
  :
70
 
  state(),
71
 
  null_items(NULL),
72
 
  ref_pointer_arrays(NULL),
73
 
  fields()
74
 
  {}
75
 
  
76
 
  Rollup(State in_state,
77
 
         Item_null_result **in_null_items,
78
 
         Item ***in_ref_pointer_arrays,
79
 
         List<Item> *in_fields)
80
 
  :
81
 
  state(in_state),
82
 
  null_items(in_null_items),
83
 
  ref_pointer_arrays(in_ref_pointer_arrays),
84
 
  fields(in_fields)
85
 
  {}
86
 
  
87
 
  State getState() const
88
 
  {
89
 
    return state;
90
 
  }
91
 
 
92
 
  void setState(State in_state)
93
 
  {
94
 
    state= in_state;
95
 
  }
96
 
 
97
 
  Item_null_result **getNullItems() const
98
 
  {
99
 
    return null_items;
100
 
  }
101
 
 
102
 
  void setNullItems(Item_null_result **in_null_items)
103
 
  {
104
 
    null_items= in_null_items;
105
 
  }
106
 
 
107
 
  Item ***getRefPointerArrays() const
108
 
  {
109
 
    return ref_pointer_arrays;
110
 
  }
111
 
 
112
 
  void setRefPointerArrays(Item ***in_ref_pointer_arrays)
113
 
  {
114
 
    ref_pointer_arrays= in_ref_pointer_arrays;
115
 
  }
116
 
 
117
 
  List<Item> *getFields() const
118
 
  {
119
 
    return fields;
120
 
  }
121
 
 
122
 
  void setFields(List<Item> *in_fields)
123
 
  {
124
 
    fields= in_fields;
125
 
  }
126
 
  
127
 
private:
128
63
  State state;
129
64
  Item_null_result **null_items;
130
65
  Item ***ref_pointer_arrays;
131
66
  List<Item> *fields;
132
 
};
133
 
 
134
 
} /* namespace drizzled */
135
 
 
136
 
/** @TODO why is this in the middle of the file??? */
 
67
} ROLLUP;
137
68
 
138
69
#include "drizzled/join.h"
139
70
 
140
 
namespace drizzled
141
 
{
142
 
 
143
71
/*****************************************************************************
144
72
  Make som simple condition optimization:
145
73
  If there is a test 'field = const' change all refs to 'field' to 'const'
148
76
  item->marker should be 0 for all items on entry
149
77
  Return in cond_value false if condition is impossible (1 = 2)
150
78
*****************************************************************************/
151
 
typedef std::pair<Item*, Item_func*> COND_CMP;
 
79
struct COND_CMP {
 
80
  Item *and_level;
 
81
  Item_func *cmp_func;
 
82
  COND_CMP(Item *a,Item_func *b) :and_level(a),cmp_func(b) {}
 
83
};
152
84
 
153
 
void TEST_join(Join *join);
 
85
void TEST_join(JOIN *join);
154
86
 
155
87
/* Extern functions in sql_select.cc */
156
88
bool store_val_in_field(Field *field, Item *val, enum_check_fields check_flag);
157
89
Table *create_tmp_table(Session *session,Tmp_Table_Param *param,List<Item> &fields,
158
 
                        Order *group, bool distinct, bool save_sum_fields,
 
90
                        order_st *group, bool distinct, bool save_sum_fields,
159
91
                        uint64_t select_options, ha_rows rows_limit,
160
92
                        const char* alias);
 
93
void free_tmp_table(Session *session, Table *entry);
161
94
void count_field_types(Select_Lex *select_lex, Tmp_Table_Param *param,
162
95
                       List<Item> &fields, bool reset_with_sum_func);
163
96
bool setup_copy_fields(Session *session, Tmp_Table_Param *param,
165
98
                       List<Item> &new_list1, List<Item> &new_list2,
166
99
                       uint32_t elements, List<Item> &fields);
167
100
void copy_fields(Tmp_Table_Param *param);
168
 
bool copy_funcs(Item **func_ptr, const Session *session);
 
101
void copy_funcs(Item **func_ptr);
169
102
Field* create_tmp_field_from_field(Session *session, Field* org_field,
170
103
                                   const char *name, Table *table,
171
104
                                   Item_field *item, uint32_t convert_blob_length);
172
105
bool test_if_ref(Item_field *left_item,Item *right_item);
173
 
COND *optimize_cond(Join *join, COND *conds, List<TableList> *join_list, Item::cond_result *cond_value);
 
106
COND *optimize_cond(JOIN *join, COND *conds, List<TableList> *join_list, Item::cond_result *cond_value);
174
107
COND *make_cond_for_table(COND *cond,table_map table, table_map used_table, bool exclude_expensive_cond);
175
108
COND* substitute_for_best_equal_field(COND *cond, COND_EQUAL *cond_equal, void *table_join_idx);
176
109
bool list_contains_unique_index(Table *table, bool (*find_func) (Field *, void *), void *data);
177
110
bool find_field_in_order_list (Field *field, void *data);
178
111
bool find_field_in_item_list (Field *field, void *data);
179
 
bool test_if_skip_sort_order(JoinTable *tab,Order *order,ha_rows select_limit, bool no_changes, const key_map *map);
180
 
Order *create_distinct_group(Session *session,
 
112
bool test_if_skip_sort_order(JoinTable *tab,order_st *order,ha_rows select_limit, bool no_changes, const key_map *map);
 
113
order_st *create_distinct_group(Session *session,
181
114
                                Item **ref_pointer_array,
182
 
                                Order *order_list,
 
115
                                order_st *order_list,
183
116
                                List<Item> &fields,
184
117
                                List<Item> &,
185
118
                                bool *all_order_by_fields_used);
190
123
                                                List<Item> &res_all_fields,
191
124
                                                uint32_t elements,
192
125
                              List<Item> &all_fields);
193
 
int do_select(Join *join, List<Item> *fields, Table *tmp_table);
 
126
int do_select(JOIN *join, List<Item> *fields, Table *tmp_table);
194
127
bool const_expression_in_where(COND *conds,Item *item, Item **comp_item);
195
 
int create_sort_index(Session *session, Join *join, Order *order, ha_rows filesort_limit, ha_rows select_limit, bool is_order_by);
 
128
int create_sort_index(Session *session, JOIN *join, order_st *order, ha_rows filesort_limit, ha_rows select_limit, bool is_order_by);
196
129
void save_index_subquery_explain_info(JoinTable *join_tab, Item* where);
197
130
Item *remove_additional_cond(Item* conds);
198
131
bool setup_sum_funcs(Session *session, Item_sum **func_ptr);
205
138
                               List<Item> &res_all_fields,
206
139
                               uint32_t elements,
207
140
                                                 List<Item> &all_fields);
208
 
bool change_group_ref(Session *session, Item_func *expr, Order *group_list, bool *changed);
209
 
bool check_interleaving_with_nj(JoinTable *next);
210
 
void update_const_equal_items(COND *cond, JoinTable *tab);
 
141
bool change_group_ref(Session *session, Item_func *expr, order_st *group_list, bool *changed);
 
142
bool check_interleaving_with_nj(JoinTable *last, JoinTable *next);
 
143
 
 
144
int join_read_const_table(JoinTable *tab, drizzled::optimizer::Position *pos);
 
145
int join_read_system(JoinTable *tab);
211
146
int join_read_const(JoinTable *tab);
212
147
int join_read_key(JoinTable *tab);
213
148
int join_read_always_key(JoinTable *tab);
214
149
int join_read_last_key(JoinTable *tab);
215
 
int join_no_more_records(ReadRecord *info);
216
 
int join_read_next(ReadRecord *info);
217
 
int join_read_next_different(ReadRecord *info);
 
150
int join_no_more_records(READ_RECORD *info);
 
151
int join_read_next(READ_RECORD *info);
 
152
int join_read_next_different(READ_RECORD *info);
218
153
int join_init_quick_read_record(JoinTable *tab);
219
154
int init_read_record_seq(JoinTable *tab);
220
155
int test_if_quick_select(JoinTable *tab);
221
156
int join_init_read_record(JoinTable *tab);
222
157
int join_read_first(JoinTable *tab);
223
 
int join_read_next_same(ReadRecord *info);
224
 
int join_read_next_same_diff(ReadRecord *info);
 
158
int join_read_next_same(READ_RECORD *info);
 
159
int join_read_next_same_diff(READ_RECORD *info);
225
160
int join_read_last(JoinTable *tab);
226
 
int join_read_prev_same(ReadRecord *info);
227
 
int join_read_prev(ReadRecord *info);
 
161
int join_read_prev_same(READ_RECORD *info);
 
162
int join_read_prev(READ_RECORD *info);
228
163
int join_read_always_key_or_null(JoinTable *tab);
229
 
int join_read_next_same_or_null(ReadRecord *info);
 
164
int join_read_next_same_or_null(READ_RECORD *info);
230
165
 
231
166
void calc_used_field_length(Session *, JoinTable *join_tab);
232
167
StoredKey *get_store_key(Session *session, 
233
 
                         optimizer::KeyUse *keyuse,
 
168
                         drizzled::optimizer::KeyUse *keyuse,
234
169
                         table_map used_tables,
235
 
                         KeyPartInfo *key_part,
 
170
                         KEY_PART_INFO *key_part,
236
171
                         unsigned char *key_buff,
237
172
                         uint32_t maybe_null);
238
 
int join_tab_cmp(const void* ptr1, const void* ptr2);
239
 
int join_tab_cmp_straight(const void* ptr1, const void* ptr2);
 
173
extern "C" int join_tab_cmp(const void* ptr1, const void* ptr2);
 
174
extern "C" int join_tab_cmp_straight(const void* ptr1, const void* ptr2);
240
175
void push_index_cond(JoinTable *tab, uint32_t keyno, bool other_tbls_ok);
241
 
void add_not_null_conds(Join *join);
 
176
void add_not_null_conds(JOIN *join);
242
177
uint32_t max_part_bit(key_part_map bits);
243
178
COND *add_found_match_trig_cond(JoinTable *tab, COND *cond, JoinTable *root_tab);
244
 
bool eq_ref_table(Join *join, Order *start_order, JoinTable *tab);
 
179
order_st *create_distinct_group(Session *session,
 
180
                                Item **ref_pointer_array,
 
181
                                order_st *order,
 
182
                                List<Item> &fields,
 
183
                                List<Item> &all_fields,
 
184
                                bool *all_order_by_fields_used);
 
185
bool eq_ref_table(JOIN *join, order_st *start_order, JoinTable *tab);
 
186
int join_tab_cmp(const void* ptr1, const void* ptr2);
245
187
int remove_dup_with_compare(Session *session, Table *table, Field **first_field, uint32_t offset, Item *having);
246
188
int remove_dup_with_hash_index(Session *session, 
247
189
                               Table *table,
257
199
                         COND_EQUAL *,
258
200
                         table_map normal_tables,
259
201
                         Select_Lex *select_lex,
260
 
                         std::vector<optimizer::SargableParam> &sargables);
261
 
ha_rows get_quick_record_count(Session *session, optimizer::SqlSelect *select, Table *table, const key_map *keys,ha_rows limit);
262
 
void optimize_keyuse(Join *join, DYNAMIC_ARRAY *keyuse_array);
263
 
void add_group_and_distinct_keys(Join *join, JoinTable *join_tab);
 
202
                         std::vector<drizzled::optimizer::SargableParam> &sargables);
 
203
ha_rows get_quick_record_count(Session *session, drizzled::optimizer::SqlSelect *select, Table *table, const key_map *keys,ha_rows limit);
 
204
void optimize_keyuse(JOIN *join, DYNAMIC_ARRAY *keyuse_array);
 
205
void add_group_and_distinct_keys(JOIN *join, JoinTable *join_tab);
264
206
void read_cached_record(JoinTable *tab);
265
 
bool select_query(Session *session, Item ***rref_pointer_array,
 
207
bool mysql_select(Session *session, Item ***rref_pointer_array,
266
208
                  TableList *tables, uint32_t wild_num,  List<Item> &list,
267
 
                  COND *conds, uint32_t og_num, Order *order, Order *group,
 
209
                  COND *conds, uint32_t og_num, order_st *order, order_st *group,
268
210
                  Item *having, uint64_t select_type,
269
211
                  select_result *result, Select_Lex_Unit *unit,
270
212
                  Select_Lex *select_lex);
271
213
// Create list for using with tempory table
272
214
void init_tmptable_sum_functions(Item_sum **func);
273
215
void update_tmptable_sum_func(Item_sum **func,Table *tmp_table);
274
 
bool only_eq_ref_tables(Join *join, Order *order, table_map tables);
275
 
bool create_ref_for_key(Join *join, JoinTable *j, 
276
 
                        optimizer::KeyUse *org_keyuse, 
 
216
bool only_eq_ref_tables(JOIN *join, order_st *order, table_map tables);
 
217
bool create_ref_for_key(JOIN *join, JoinTable *j, 
 
218
                        drizzled::optimizer::KeyUse *org_keyuse, 
277
219
                        table_map used_tables);
278
220
 
 
221
#include "drizzled/stored_key.h"
 
222
 
279
223
bool cp_buffer_from_ref(Session *session, table_reference_st *ref);
280
224
int safe_index_read(JoinTable *tab);
281
225
COND *remove_eq_conds(Session *session, COND *cond, Item::cond_result *cond_value);
284
228
void print_join(Session *session, String *str,
285
229
                List<TableList> *tables, enum_query_type);
286
230
 
287
 
} /* namespace drizzled */
288
 
 
289
231
#endif /* DRIZZLED_SQL_SELECT_H */