~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
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
 */
1 by brian
clean slate
19
575.4.7 by Monty Taylor
More header cleanup.
20
#ifndef DRIZZLED_SQL_SELECT_H
21
#define DRIZZLED_SQL_SELECT_H
22
1055.2.21 by Jay Pipes
Documentation and indentation/style cleanups in sql_select, opt_range.h and join_tab.h. This patch doxygenates classes/structs and their member variables.
23
#include "drizzled/cached_item.h"
24
#include "drizzled/session.h"
25
#include "drizzled/field/varstring.h"
26
#include "drizzled/item/null.h"
1089.1.8 by Brian Aker
Shuffled around a few structures.
27
#include <drizzled/enum_nested_loop_state.h>
1108.6.56 by Padraig O'Sullivan
Extracted KeyUse into its own header file and placed it within the
28
#include "drizzled/optimizer/position.h"
29
#include "drizzled/optimizer/sargable_param.h"
30
#include "drizzled/optimizer/key_use.h"
1089.1.8 by Brian Aker
Shuffled around a few structures.
31
#include "drizzled/join_cache.h"
32
#include "drizzled/join_table.h"
33
1108.6.33 by Padraig O'Sullivan
Use std::vector to hold an array of SargableParam objects instead of a
34
#include <vector>
35
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
36
namespace drizzled
37
{
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
38
39
class select_result;
40
1 by brian
clean slate
41
/**
1055.2.21 by Jay Pipes
Documentation and indentation/style cleanups in sql_select, opt_range.h and join_tab.h. This patch doxygenates classes/structs and their member variables.
42
 * @file API and Classes to use when handling where clause
43
 */
1 by brian
clean slate
44
243.1.13 by Jay Pipes
More comments in mysql_priv.h to mark stuff TODO. Move sql_locale.h and object_creation_ctx.h up in the file since no more dependencies above them.
45
/* PREV_BITS only used in sql_select.cc */
46
#define PREV_BITS(type,A)	((type) (((type) 1 << (A)) -1))
47
1 by brian
clean slate
48
/* Values in optimize */
49
#define KEY_OPTIMIZE_EXISTS		1
50
#define KEY_OPTIMIZE_REF_OR_NULL	2
51
1541.1.1 by Brian Aker
JOIN -> Join rename
52
class Join;
1 by brian
clean slate
53
1541.1.1 by Brian Aker
JOIN -> Join rename
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);
1 by brian
clean slate
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
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
68
} /* namespace drizzled */
69
70
/** @TODO why is this in the middle of the file??? */
71
1039.2.1 by Jay Pipes
First phase refactoring the JOIN class:
72
#include "drizzled/join.h"
1 by brian
clean slate
73
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
74
namespace drizzled
75
{
76
1039.2.2 by Jay Pipes
Phase 2 of JOIN refactoring.
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
*****************************************************************************/
1997 by Brian Aker
Reverse patch with memory leak.
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
};
1039.2.2 by Jay Pipes
Phase 2 of JOIN refactoring.
90
1541.1.1 by Brian Aker
JOIN -> Join rename
91
void TEST_join(Join *join);
1 by brian
clean slate
92
93
/* Extern functions in sql_select.cc */
94
bool store_val_in_field(Field *field, Item *val, enum_check_fields check_flag);
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
95
Table *create_tmp_table(Session *session,Tmp_Table_Param *param,List<Item> &fields,
1892.3.3 by tdavies
struct order_st changed and renamed to c++ class named:Order
96
			Order *group, bool distinct, bool save_sum_fields,
151 by Brian Aker
Ulonglong to uint64_t
97
			uint64_t select_options, ha_rows rows_limit,
1039.1.4 by Brian Aker
Modified alias to being const.
98
			const char* alias);
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
99
void count_field_types(Select_Lex *select_lex, Tmp_Table_Param *param,
1 by brian
clean slate
100
                       List<Item> &fields, bool reset_with_sum_func);
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
101
bool setup_copy_fields(Session *session, Tmp_Table_Param *param,
1 by brian
clean slate
102
		       Item **ref_pointer_array,
103
		       List<Item> &new_list1, List<Item> &new_list2,
482 by Brian Aker
Remove uint.
104
		       uint32_t elements, List<Item> &fields);
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
105
void copy_fields(Tmp_Table_Param *param);
1819.9.80 by Georgi Kodinov, Stewart Smith
Merge Revision revid:georgi.kodinov@oracle.com-20100813080739-27p9rgxvo26a6psh from MySQL InnoDB
106
bool copy_funcs(Item **func_ptr, const Session *session);
520.1.22 by Brian Aker
Second pass of thd cleanup
107
Field* create_tmp_field_from_field(Session *session, Field* org_field,
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
108
                                   const char *name, Table *table,
482 by Brian Aker
Remove uint.
109
                                   Item_field *item, uint32_t convert_blob_length);
1039.2.2 by Jay Pipes
Phase 2 of JOIN refactoring.
110
bool test_if_ref(Item_field *left_item,Item *right_item);
1541.1.1 by Brian Aker
JOIN -> Join rename
111
COND *optimize_cond(Join *join, COND *conds, List<TableList> *join_list, Item::cond_result *cond_value);
1039.2.2 by Jay Pipes
Phase 2 of JOIN refactoring.
112
COND *make_cond_for_table(COND *cond,table_map table, table_map used_table, bool exclude_expensive_cond);
113
COND* substitute_for_best_equal_field(COND *cond, COND_EQUAL *cond_equal, void *table_join_idx);
114
bool list_contains_unique_index(Table *table, bool (*find_func) (Field *, void *), void *data);
115
bool find_field_in_order_list (Field *field, void *data);
116
bool find_field_in_item_list (Field *field, void *data);
1892.3.3 by tdavies
struct order_st changed and renamed to c++ class named:Order
117
bool test_if_skip_sort_order(JoinTable *tab,Order *order,ha_rows select_limit, bool no_changes, const key_map *map);
118
Order *create_distinct_group(Session *session,
1039.2.2 by Jay Pipes
Phase 2 of JOIN refactoring.
119
                                Item **ref_pointer_array,
1892.3.3 by tdavies
struct order_st changed and renamed to c++ class named:Order
120
                                Order *order_list,
1039.2.2 by Jay Pipes
Phase 2 of JOIN refactoring.
121
                                List<Item> &fields,
122
                                List<Item> &,
123
                                bool *all_order_by_fields_used);
124
// Create list for using with tempory table
125
bool change_to_use_tmp_fields(Session *session,
126
                              Item **ref_pointer_array,
127
			                        List<Item> &res_selected_fields,
128
			                        List<Item> &res_all_fields,
129
			                        uint32_t elements,
130
                              List<Item> &all_fields);
1541.1.1 by Brian Aker
JOIN -> Join rename
131
int do_select(Join *join, List<Item> *fields, Table *tmp_table);
1039.2.2 by Jay Pipes
Phase 2 of JOIN refactoring.
132
bool const_expression_in_where(COND *conds,Item *item, Item **comp_item);
1892.3.3 by tdavies
struct order_st changed and renamed to c++ class named:Order
133
int create_sort_index(Session *session, Join *join, Order *order, ha_rows filesort_limit, ha_rows select_limit, bool is_order_by);
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
134
void save_index_subquery_explain_info(JoinTable *join_tab, Item* where);
1039.2.2 by Jay Pipes
Phase 2 of JOIN refactoring.
135
Item *remove_additional_cond(Item* conds);
136
bool setup_sum_funcs(Session *session, Item_sum **func_ptr);
137
bool init_sum_functions(Item_sum **func, Item_sum **end);
138
bool update_sum_func(Item_sum **func);
139
void copy_sum_funcs(Item_sum **func_ptr, Item_sum **end);
140
bool change_refs_to_tmp_fields(Session *session,
141
                               Item **ref_pointer_array,
142
                               List<Item> &res_selected_fields,
143
                               List<Item> &res_all_fields,
144
                               uint32_t elements,
145
			                         List<Item> &all_fields);
1892.3.3 by tdavies
struct order_st changed and renamed to c++ class named:Order
146
bool change_group_ref(Session *session, Item_func *expr, Order *group_list, bool *changed);
1637.5.9 by Prafulla Tekawade
Fix for Bug 592444
147
bool check_interleaving_with_nj(JoinTable *next);
1039.2.2 by Jay Pipes
Phase 2 of JOIN refactoring.
148
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
149
int join_read_const_table(JoinTable *tab, optimizer::Position *pos);
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
150
int join_read_system(JoinTable *tab);
151
int join_read_const(JoinTable *tab);
152
int join_read_key(JoinTable *tab);
153
int join_read_always_key(JoinTable *tab);
154
int join_read_last_key(JoinTable *tab);
1538 by Brian Aker
Code shuffle on ReadRecord
155
int join_no_more_records(ReadRecord *info);
156
int join_read_next(ReadRecord *info);
157
int join_read_next_different(ReadRecord *info);
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
158
int join_init_quick_read_record(JoinTable *tab);
1090.1.1 by Brian Aker
Collection of patches/bug fixes from new-cleanup tree (none of the
159
int init_read_record_seq(JoinTable *tab);
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
160
int test_if_quick_select(JoinTable *tab);
161
int join_init_read_record(JoinTable *tab);
162
int join_read_first(JoinTable *tab);
1538 by Brian Aker
Code shuffle on ReadRecord
163
int join_read_next_same(ReadRecord *info);
164
int join_read_next_same_diff(ReadRecord *info);
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
165
int join_read_last(JoinTable *tab);
1538 by Brian Aker
Code shuffle on ReadRecord
166
int join_read_prev_same(ReadRecord *info);
167
int join_read_prev(ReadRecord *info);
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
168
int join_read_always_key_or_null(JoinTable *tab);
1538 by Brian Aker
Code shuffle on ReadRecord
169
int join_read_next_same_or_null(ReadRecord *info);
1039.2.2 by Jay Pipes
Phase 2 of JOIN refactoring.
170
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
171
void calc_used_field_length(Session *, JoinTable *join_tab);
1039.2.3 by Jay Pipes
Phase 3 of refactoring JOIN
172
StoredKey *get_store_key(Session *session, 
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
173
                         optimizer::KeyUse *keyuse,
1039.2.2 by Jay Pipes
Phase 2 of JOIN refactoring.
174
                         table_map used_tables,
1534 by Brian Aker
Remove of KeyPartInfo
175
                         KeyPartInfo *key_part,
1039.2.2 by Jay Pipes
Phase 2 of JOIN refactoring.
176
                         unsigned char *key_buff,
177
                         uint32_t maybe_null);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
178
int join_tab_cmp(const void* ptr1, const void* ptr2);
179
int join_tab_cmp_straight(const void* ptr1, const void* ptr2);
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
180
void push_index_cond(JoinTable *tab, uint32_t keyno, bool other_tbls_ok);
1541.1.1 by Brian Aker
JOIN -> Join rename
181
void add_not_null_conds(Join *join);
1039.2.2 by Jay Pipes
Phase 2 of JOIN refactoring.
182
uint32_t max_part_bit(key_part_map bits);
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
183
COND *add_found_match_trig_cond(JoinTable *tab, COND *cond, JoinTable *root_tab);
1892.3.3 by tdavies
struct order_st changed and renamed to c++ class named:Order
184
Order *create_distinct_group(Session *session,
1039.2.2 by Jay Pipes
Phase 2 of JOIN refactoring.
185
                                Item **ref_pointer_array,
1892.3.3 by tdavies
struct order_st changed and renamed to c++ class named:Order
186
                                Order *order,
1039.2.2 by Jay Pipes
Phase 2 of JOIN refactoring.
187
                                List<Item> &fields,
188
                                List<Item> &all_fields,
189
                                bool *all_order_by_fields_used);
1892.3.3 by tdavies
struct order_st changed and renamed to c++ class named:Order
190
bool eq_ref_table(Join *join, Order *start_order, JoinTable *tab);
1039.2.2 by Jay Pipes
Phase 2 of JOIN refactoring.
191
int remove_dup_with_compare(Session *session, Table *table, Field **first_field, uint32_t offset, Item *having);
192
int remove_dup_with_hash_index(Session *session, 
193
                               Table *table,
194
                               uint32_t field_count,
195
                               Field **first_field,
196
                               uint32_t key_length,
197
                               Item *having);
198
bool update_ref_and_keys(Session *session,
199
                         DYNAMIC_ARRAY *keyuse,
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
200
                         JoinTable *join_tab,
1039.2.2 by Jay Pipes
Phase 2 of JOIN refactoring.
201
                         uint32_t tables,
202
                         COND *cond, 
203
                         COND_EQUAL *,
204
                         table_map normal_tables,
205
                         Select_Lex *select_lex,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
206
                         std::vector<optimizer::SargableParam> &sargables);
207
ha_rows get_quick_record_count(Session *session, optimizer::SqlSelect *select, Table *table, const key_map *keys,ha_rows limit);
1541.1.1 by Brian Aker
JOIN -> Join rename
208
void optimize_keyuse(Join *join, DYNAMIC_ARRAY *keyuse_array);
209
void add_group_and_distinct_keys(Join *join, JoinTable *join_tab);
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
210
void read_cached_record(JoinTable *tab);
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
211
bool select_query(Session *session, Item ***rref_pointer_array,
1241.7.6 by Padraig O'Sullivan
Added some dtrace probes for tracing the optimizer.
212
                  TableList *tables, uint32_t wild_num,  List<Item> &list,
1892.3.3 by tdavies
struct order_st changed and renamed to c++ class named:Order
213
                  COND *conds, uint32_t og_num, Order *order, Order *group,
1241.7.6 by Padraig O'Sullivan
Added some dtrace probes for tracing the optimizer.
214
                  Item *having, uint64_t select_type,
215
                  select_result *result, Select_Lex_Unit *unit,
216
                  Select_Lex *select_lex);
1039.2.2 by Jay Pipes
Phase 2 of JOIN refactoring.
217
// Create list for using with tempory table
218
void init_tmptable_sum_functions(Item_sum **func);
219
void update_tmptable_sum_func(Item_sum **func,Table *tmp_table);
1892.3.3 by tdavies
struct order_st changed and renamed to c++ class named:Order
220
bool only_eq_ref_tables(Join *join, Order *order, table_map tables);
1541.1.1 by Brian Aker
JOIN -> Join rename
221
bool create_ref_for_key(Join *join, JoinTable *j, 
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
222
                        optimizer::KeyUse *org_keyuse, 
1108.6.56 by Padraig O'Sullivan
Extracted KeyUse into its own header file and placed it within the
223
                        table_map used_tables);
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
224
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
225
} /* namespace drizzled */
226
227
/** @TODO why is this in the middle of the file??? */
228
1039.2.3 by Jay Pipes
Phase 3 of refactoring JOIN
229
#include "drizzled/stored_key.h"
1 by brian
clean slate
230
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
231
namespace drizzled
232
{
233
1089.1.14 by Brian Aker
Fix TABLE_REF structure
234
bool cp_buffer_from_ref(Session *session, table_reference_st *ref);
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
235
int safe_index_read(JoinTable *tab);
520.1.22 by Brian Aker
Second pass of thd cleanup
236
COND *remove_eq_conds(Session *session, COND *cond, Item::cond_result *cond_value);
1101.1.16 by Monty Taylor
Reverted 1103
237
int test_if_item_cache_changed(List<Cached_item> &list);
575.4.7 by Monty Taylor
More header cleanup.
238
1054.1.7 by Brian Aker
Refactor TableList methods.
239
void print_join(Session *session, String *str,
240
                List<TableList> *tables, enum_query_type);
241
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
242
} /* namespace drizzled */
243
575.4.7 by Monty Taylor
More header cleanup.
244
#endif /* DRIZZLED_SQL_SELECT_H */