~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to drizzled/sql_select.h

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

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_SQL_SELECT_H
 
21
#define DRIZZLED_SQL_SELECT_H
 
22
 
 
23
#include "drizzled/cached_item.h"
 
24
#include "drizzled/session.h"
 
25
#include "drizzled/field/varstring.h"
 
26
#include "drizzled/item/null.h"
 
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
#include "drizzled/join_cache.h"
 
32
#include "drizzled/join_table.h"
 
33
 
 
34
#include <vector>
 
35
 
 
36
namespace drizzled
 
37
{
 
38
 
 
39
class select_result;
 
40
 
 
41
/**
 
42
 * @file API and Classes to use when handling where clause
 
43
 */
 
44
 
 
45
/* PREV_BITS only used in sql_select.cc */
 
46
#define PREV_BITS(type,A)       ((type) (((type) 1 << (A)) -1))
 
47
 
 
48
/* Values in optimize */
 
49
#define KEY_OPTIMIZE_EXISTS             1
 
50
#define KEY_OPTIMIZE_REF_OR_NULL        2
 
51
 
 
52
class JOIN;
 
53
 
 
54
enum_nested_loop_state sub_select_cache(JOIN *join, JoinTable *join_tab, bool end_of_records);
 
55
enum_nested_loop_state sub_select(JOIN *join,JoinTable *join_tab, bool end_of_records);
 
56
enum_nested_loop_state end_send_group(JOIN *join, JoinTable *join_tab, bool end_of_records);
 
57
enum_nested_loop_state end_write_group(JOIN *join, JoinTable *join_tab, bool end_of_records);
 
58
 
 
59
typedef struct st_rollup
 
60
{
 
61
  enum State { STATE_NONE, STATE_INITED, STATE_READY };
 
62
  State state;
 
63
  Item_null_result **null_items;
 
64
  Item ***ref_pointer_arrays;
 
65
  List<Item> *fields;
 
66
} ROLLUP;
 
67
 
 
68
} /* namespace drizzled */
 
69
 
 
70
/** @TODO why is this in the middle of the file??? */
 
71
 
 
72
#include "drizzled/join.h"
 
73
 
 
74
namespace drizzled
 
75
{
 
76
 
 
77
/*****************************************************************************
 
78
  Make som simple condition optimization:
 
79
  If there is a test 'field = const' change all refs to 'field' to 'const'
 
80
  Remove all dummy tests 'item = item', 'const op const'.
 
81
  Remove all 'item is NULL', when item can never be null!
 
82
  item->marker should be 0 for all items on entry
 
83
  Return in cond_value false if condition is impossible (1 = 2)
 
84
*****************************************************************************/
 
85
struct COND_CMP {
 
86
  Item *and_level;
 
87
  Item_func *cmp_func;
 
88
  COND_CMP(Item *a,Item_func *b) :and_level(a),cmp_func(b) {}
 
89
};
 
90
 
 
91
void TEST_join(JOIN *join);
 
92
 
 
93
/* Extern functions in sql_select.cc */
 
94
bool store_val_in_field(Field *field, Item *val, enum_check_fields check_flag);
 
95
Table *create_tmp_table(Session *session,Tmp_Table_Param *param,List<Item> &fields,
 
96
                        order_st *group, bool distinct, bool save_sum_fields,
 
97
                        uint64_t select_options, ha_rows rows_limit,
 
98
                        const char* alias);
 
99
void free_tmp_table(Session *session, Table *entry);
 
100
void count_field_types(Select_Lex *select_lex, Tmp_Table_Param *param,
 
101
                       List<Item> &fields, bool reset_with_sum_func);
 
102
bool setup_copy_fields(Session *session, Tmp_Table_Param *param,
 
103
                       Item **ref_pointer_array,
 
104
                       List<Item> &new_list1, List<Item> &new_list2,
 
105
                       uint32_t elements, List<Item> &fields);
 
106
void copy_fields(Tmp_Table_Param *param);
 
107
void copy_funcs(Item **func_ptr);
 
108
Field* create_tmp_field_from_field(Session *session, Field* org_field,
 
109
                                   const char *name, Table *table,
 
110
                                   Item_field *item, uint32_t convert_blob_length);
 
111
bool test_if_ref(Item_field *left_item,Item *right_item);
 
112
COND *optimize_cond(JOIN *join, COND *conds, List<TableList> *join_list, Item::cond_result *cond_value);
 
113
COND *make_cond_for_table(COND *cond,table_map table, table_map used_table, bool exclude_expensive_cond);
 
114
COND* substitute_for_best_equal_field(COND *cond, COND_EQUAL *cond_equal, void *table_join_idx);
 
115
bool list_contains_unique_index(Table *table, bool (*find_func) (Field *, void *), void *data);
 
116
bool find_field_in_order_list (Field *field, void *data);
 
117
bool find_field_in_item_list (Field *field, void *data);
 
118
bool test_if_skip_sort_order(JoinTable *tab,order_st *order,ha_rows select_limit, bool no_changes, const key_map *map);
 
119
order_st *create_distinct_group(Session *session,
 
120
                                Item **ref_pointer_array,
 
121
                                order_st *order_list,
 
122
                                List<Item> &fields,
 
123
                                List<Item> &,
 
124
                                bool *all_order_by_fields_used);
 
125
// Create list for using with tempory table
 
126
bool change_to_use_tmp_fields(Session *session,
 
127
                              Item **ref_pointer_array,
 
128
                                                List<Item> &res_selected_fields,
 
129
                                                List<Item> &res_all_fields,
 
130
                                                uint32_t elements,
 
131
                              List<Item> &all_fields);
 
132
int do_select(JOIN *join, List<Item> *fields, Table *tmp_table);
 
133
bool const_expression_in_where(COND *conds,Item *item, Item **comp_item);
 
134
int create_sort_index(Session *session, JOIN *join, order_st *order, ha_rows filesort_limit, ha_rows select_limit, bool is_order_by);
 
135
void save_index_subquery_explain_info(JoinTable *join_tab, Item* where);
 
136
Item *remove_additional_cond(Item* conds);
 
137
bool setup_sum_funcs(Session *session, Item_sum **func_ptr);
 
138
bool init_sum_functions(Item_sum **func, Item_sum **end);
 
139
bool update_sum_func(Item_sum **func);
 
140
void copy_sum_funcs(Item_sum **func_ptr, Item_sum **end);
 
141
bool change_refs_to_tmp_fields(Session *session,
 
142
                               Item **ref_pointer_array,
 
143
                               List<Item> &res_selected_fields,
 
144
                               List<Item> &res_all_fields,
 
145
                               uint32_t elements,
 
146
                                                 List<Item> &all_fields);
 
147
bool change_group_ref(Session *session, Item_func *expr, order_st *group_list, bool *changed);
 
148
bool check_interleaving_with_nj(JoinTable *last, JoinTable *next);
 
149
 
 
150
int join_read_const_table(JoinTable *tab, optimizer::Position *pos);
 
151
int join_read_system(JoinTable *tab);
 
152
int join_read_const(JoinTable *tab);
 
153
int join_read_key(JoinTable *tab);
 
154
int join_read_always_key(JoinTable *tab);
 
155
int join_read_last_key(JoinTable *tab);
 
156
int join_no_more_records(READ_RECORD *info);
 
157
int join_read_next(READ_RECORD *info);
 
158
int join_read_next_different(READ_RECORD *info);
 
159
int join_init_quick_read_record(JoinTable *tab);
 
160
int init_read_record_seq(JoinTable *tab);
 
161
int test_if_quick_select(JoinTable *tab);
 
162
int join_init_read_record(JoinTable *tab);
 
163
int join_read_first(JoinTable *tab);
 
164
int join_read_next_same(READ_RECORD *info);
 
165
int join_read_next_same_diff(READ_RECORD *info);
 
166
int join_read_last(JoinTable *tab);
 
167
int join_read_prev_same(READ_RECORD *info);
 
168
int join_read_prev(READ_RECORD *info);
 
169
int join_read_always_key_or_null(JoinTable *tab);
 
170
int join_read_next_same_or_null(READ_RECORD *info);
 
171
 
 
172
void calc_used_field_length(Session *, JoinTable *join_tab);
 
173
StoredKey *get_store_key(Session *session, 
 
174
                         optimizer::KeyUse *keyuse,
 
175
                         table_map used_tables,
 
176
                         KEY_PART_INFO *key_part,
 
177
                         unsigned char *key_buff,
 
178
                         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);
 
181
void push_index_cond(JoinTable *tab, uint32_t keyno, bool other_tbls_ok);
 
182
void add_not_null_conds(JOIN *join);
 
183
uint32_t max_part_bit(key_part_map bits);
 
184
COND *add_found_match_trig_cond(JoinTable *tab, COND *cond, JoinTable *root_tab);
 
185
order_st *create_distinct_group(Session *session,
 
186
                                Item **ref_pointer_array,
 
187
                                order_st *order,
 
188
                                List<Item> &fields,
 
189
                                List<Item> &all_fields,
 
190
                                bool *all_order_by_fields_used);
 
191
bool eq_ref_table(JOIN *join, order_st *start_order, JoinTable *tab);
 
192
int remove_dup_with_compare(Session *session, Table *table, Field **first_field, uint32_t offset, Item *having);
 
193
int remove_dup_with_hash_index(Session *session, 
 
194
                               Table *table,
 
195
                               uint32_t field_count,
 
196
                               Field **first_field,
 
197
                               uint32_t key_length,
 
198
                               Item *having);
 
199
bool update_ref_and_keys(Session *session,
 
200
                         DYNAMIC_ARRAY *keyuse,
 
201
                         JoinTable *join_tab,
 
202
                         uint32_t tables,
 
203
                         COND *cond, 
 
204
                         COND_EQUAL *,
 
205
                         table_map normal_tables,
 
206
                         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);
 
209
void optimize_keyuse(JOIN *join, DYNAMIC_ARRAY *keyuse_array);
 
210
void add_group_and_distinct_keys(JOIN *join, JoinTable *join_tab);
 
211
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
// Create list for using with tempory table
 
219
void init_tmptable_sum_functions(Item_sum **func);
 
220
void update_tmptable_sum_func(Item_sum **func,Table *tmp_table);
 
221
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??? */
 
229
 
 
230
#include "drizzled/stored_key.h"
 
231
 
 
232
namespace drizzled
 
233
{
 
234
 
 
235
bool cp_buffer_from_ref(Session *session, table_reference_st *ref);
 
236
int safe_index_read(JoinTable *tab);
 
237
COND *remove_eq_conds(Session *session, COND *cond, Item::cond_result *cond_value);
 
238
int test_if_item_cache_changed(List<Cached_item> &list);
 
239
 
 
240
void print_join(Session *session, String *str,
 
241
                List<TableList> *tables, enum_query_type);
 
242
 
 
243
} /* namespace drizzled */
 
244
 
 
245
#endif /* DRIZZLED_SQL_SELECT_H */