Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00027 #pragma once
00028
00029 #include <drizzled/dynamic_array.h>
00030 #include <drizzled/optimizer/position.h>
00031 #include <drizzled/sql_select.h>
00032 #include <drizzled/tmp_table_param.h>
00033 #include <bitset>
00034
00035 namespace drizzled
00036 {
00037
00038 class DrizzleLock;
00039 class Session;
00040 class SortField;
00041
00042 class Join :public memory::SqlAlloc
00043 {
00044 Join(const Join &rhs);
00045 Join& operator=(const Join &rhs);
00051 optimizer::Position positions[MAX_TABLES+1];
00052
00057 optimizer::Position best_positions[MAX_TABLES+1];
00058
00059 public:
00060 JoinTable *join_tab;
00061 JoinTable **best_ref;
00062 JoinTable **map2table;
00063 JoinTable *join_tab_save;
00065 Table **table;
00066 Table **all_tables;
00072 Table *sort_by_table;
00073
00074 uint32_t tables;
00075 uint32_t outer_tables;
00076 uint32_t const_tables;
00077 uint32_t send_group_parts;
00078
00079 bool sort_and_group;
00080 bool first_record;
00081 bool full_join;
00082 bool group;
00083 bool no_field_update;
00084 bool do_send_rows;
00089 bool resume_nested_loop;
00097 bool no_const_tables;
00098 bool select_distinct;
00106 bool group_optimized_away;
00107
00108
00109
00110
00111
00112
00113 bool simple_order;
00114 bool simple_group;
00119 bool no_order;
00121 bool skip_sort_order;
00122 bool union_part;
00123 bool optimized;
00124 bool need_tmp;
00125 bool hidden_group_fields;
00126
00127 table_map const_table_map;
00128 table_map found_const_table_map;
00129 table_map outer_join;
00130
00131 ha_rows send_records;
00132 ha_rows found_records;
00133 ha_rows examined_rows;
00134 ha_rows row_limit;
00135 ha_rows select_limit;
00145 ha_rows fetch_limit;
00146
00147 Session *session;
00148 List<Item> *fields;
00149 List<Item> &fields_list;
00150 List<TableList> *join_list;
00152 Select_Lex_Unit *unit;
00154 Select_Lex *select_lex;
00155 optimizer::SqlSelect *select;
00161 std::bitset<64> cur_embedding_map;
00162
00167 double best_read;
00168 List<Cached_item> group_fields;
00169 List<Cached_item> group_fields_cache;
00170 Table *tmp_table;
00172 Table *exec_tmp_table1;
00173 Table *exec_tmp_table2;
00174 Item_sum **sum_funcs;
00175 Item_sum ***sum_funcs_end;
00177 Item_sum **sum_funcs2;
00178 Item_sum ***sum_funcs_end2;
00179 Item *having;
00180 Item *tmp_having;
00181 Item *having_history;
00182 uint64_t select_options;
00183 select_result *result;
00184 Tmp_Table_Param tmp_table_param;
00185 DrizzleLock *lock;
00186
00187 Join *tmp_join;
00188 Rollup rollup;
00189 DYNAMIC_ARRAY keyuse;
00190 Item::cond_result cond_value;
00191 Item::cond_result having_value;
00192 List<Item> all_fields;
00194 List<Item> tmp_all_fields1;
00195 List<Item> tmp_all_fields2;
00196 List<Item> tmp_all_fields3;
00198 List<Item> tmp_fields_list1;
00199 List<Item> tmp_fields_list2;
00200 List<Item> tmp_fields_list3;
00201 int error;
00202
00203 Order *order;
00204 Order *group_list;
00205 COND *conds;
00206 Item *conds_history;
00207 TableList *tables_list;
00208 COND_EQUAL *cond_equal;
00209 JoinTable *return_tab;
00210 Item **ref_pointer_array;
00212 Item **items0;
00213 Item **items1;
00214 Item **items2;
00215 Item **items3;
00216 Item **current_ref_pointer_array;
00217 uint32_t ref_pointer_array_size;
00218 const char *zero_result_cause;
00219
00220
00221
00222
00223
00224
00225
00226
00227 SortField *sortorder;
00228 Table **table_reexec;
00229 JoinTable *join_tab_reexec;
00230
00231
00233 Join(Session *session_arg,
00234 List<Item> &fields_arg,
00235 uint64_t select_options_arg,
00236 select_result *result_arg);
00237
00244 void reset(Session *session_arg,
00245 List<Item> &fields_arg,
00246 uint64_t select_options_arg,
00247 select_result *result_arg);
00248
00249 int prepare(Item ***rref_pointer_array,
00250 TableList *tables,
00251 uint32_t wind_num,
00252 COND *conds,
00253 uint32_t og_num,
00254 Order *order,
00255 Order *group,
00256 Item *having,
00257 Select_Lex *select,
00258 Select_Lex_Unit *unit);
00259
00260 int optimize();
00261 int reinit();
00262 void exec();
00263 int destroy();
00264 void restore_tmp();
00265 bool alloc_func_list();
00266 bool setup_subquery_materialization();
00267 bool make_sum_func_list(List<Item> &all_fields,
00268 List<Item> &send_fields,
00269 bool before_group_by,
00270 bool recompute= false);
00271
00272 inline void set_items_ref_array(Item **ptr)
00273 {
00274 memcpy(ref_pointer_array, ptr, ref_pointer_array_size);
00275 current_ref_pointer_array= ptr;
00276 }
00277 inline void init_items_ref_array()
00278 {
00279 items0= ref_pointer_array + all_fields.size();
00280 memcpy(items0, ref_pointer_array, ref_pointer_array_size);
00281 current_ref_pointer_array= items0;
00282 }
00283
00284 bool rollup_init();
00285 bool rollup_make_fields(List<Item> &all_fields,
00286 List<Item> &fields,
00287 Item_sum ***func);
00288 int rollup_send_data(uint32_t idx);
00289 int rollup_write_data(uint32_t idx, Table *table);
00290 void remove_subq_pushed_predicates(Item **where);
00297 void join_free();
00299 void cleanup(bool full);
00300 void clear();
00301 bool save_join_tab();
00302 bool init_save_join_tab();
00303 bool send_row_on_empty_set()
00304 {
00305 return (do_send_rows && tmp_table_param.sum_func_count != 0 &&
00306 !group_list);
00307 }
00308 bool change_result(select_result *result);
00309 bool is_top_level_join() const;
00310
00316 void copyPartialPlanIntoOptimalPlan(uint32_t size)
00317 {
00318 memcpy(best_positions, positions,
00319 sizeof(optimizer::Position) * size);
00320 }
00321
00322 void cache_const_exprs();
00323
00329 optimizer::Position &getPosFromOptimalPlan(uint32_t index)
00330 {
00331 return best_positions[index];
00332 }
00333
00339 optimizer::Position &getPosFromPartialPlan(uint32_t index)
00340 {
00341 return positions[index];
00342 }
00343
00348 void setPosInPartialPlan(uint32_t index, optimizer::Position &in_pos)
00349 {
00350 positions[index]= in_pos;
00351 }
00352
00356 optimizer::Position *getFirstPosInPartialPlan()
00357 {
00358 return positions;
00359 }
00360
00366 optimizer::Position *getSpecificPosInPartialPlan(int32_t index)
00367 {
00368 return positions + index;
00369 }
00370
00371 };
00372
00373 enum_nested_loop_state evaluate_join_record(Join *join, JoinTable *join_tab, int error);
00374 enum_nested_loop_state evaluate_null_complemented_join_record(Join *join, JoinTable *join_tab);
00375 enum_nested_loop_state flush_cached_records(Join *join, JoinTable *join_tab, bool skip_last);
00376 enum_nested_loop_state end_send(Join *join, JoinTable *join_tab, bool end_of_records);
00377 enum_nested_loop_state end_write(Join *join, JoinTable *join_tab, bool end_of_records);
00378 enum_nested_loop_state end_update(Join *join, JoinTable *join_tab, bool end_of_records);
00379 enum_nested_loop_state end_unique_update(Join *join, JoinTable *join_tab, bool end_of_records);
00380
00381 }
00382