1 #ifndef SQL_OPTIMIZER_INCLUDED
2 #define SQL_OPTIMIZER_INCLUDED
30 #include "opt_explain_format.h"
41 enum State { STATE_NONE, STATE_INITED, STATE_READY };
89 uint send_group_parts;
97 bool first_record,full_join, no_field_update;
111 ha_rows send_records;
112 ha_rows found_records,examined_rows,row_limit;
114 ha_rows m_select_limit;
144 Next_select_func first_select;
158 Item_sum **sum_funcs, ***sum_funcs_end;
161 ulonglong select_options;
162 select_result *result;
163 TMP_TABLE_PARAM tmp_table_param;
197 bool simple_order, simple_group;
207 ordered_index_group_by,
208 ordered_index_order_by
209 } ordered_index_usage;
220 int hidden_group_field_count;
257 Explain_sort_clause src;
266 : order(order_arg), src(src_arg), flags(order_arg ? ESP_EXISTS : ESP_none)
295 operator ORDER *() {
return order; }
296 operator const ORDER *()
const {
return order; }
298 ORDER* operator->()
const {
return order; }
300 void clean() { order= NULL; src= ESC_none; flags= ESP_none; }
302 void set_flag(Explain_sort_property flag)
307 void reset_flag(Explain_sort_property flag) { flags&= ~flag; }
308 bool get_flag(Explain_sort_property flag)
const {
312 int get_flags()
const { DBUG_ASSERT(order);
return flags; }
401 JOIN(THD *thd_arg,
List<Item> &fields_arg, ulonglong select_options_arg,
402 select_result *result_arg)
403 : keyuse(thd_arg->mem_root),
405 sj_subselects(thd_arg->mem_root)
407 init(thd_arg, fields_arg, select_options_arg, result_arg);
410 void init(THD *thd_arg,
List<Item> &fields_arg, ulonglong select_options_arg,
411 select_result *result_arg)
420 implicit_grouping= FALSE;
432 select_options= select_options_arg;
440 ordered_index_usage= ordered_index_void;
443 hidden_group_field_count= 0;
460 tmp_table_param.init();
461 tmp_table_param.end_write_records= HA_POS_ERROR;
462 rollup.state= ROLLUP::STATE_NONE;
484 SELECT_LEX *select, SELECT_LEX_UNIT *
unit);
493 bool flatten_subqueries();
496 bool before_group_by,
bool recompute= FALSE);
501 size_t slice_sz=
select_lex->ref_pointer_array.size() / 5
U;
502 DBUG_ASSERT(
select_lex->ref_pointer_array.size() % 5 == 0);
503 DBUG_ASSERT(slice_num < 5
U);
515 DBUG_ASSERT(dst_arr.size() >= src_arr.size());
516 void *dest= dst_arr.array();
517 const void *src= src_arr.array();
518 memcpy(dest, src, src_arr.size() * src_arr.element_size());
525 current_ref_ptrs= src_arr;
533 current_ref_ptrs= items0;
542 void remove_subq_pushed_predicates(
Item **where);
553 bool save_join_tab();
554 void restore_join_tab();
555 bool init_save_join_tab();
568 return (do_send_rows && tmp_table_param.sum_func_count != 0 &&
570 select_lex->having_value != Item::COND_FALSE);
573 bool is_top_level_join()
const
575 return (
unit == &thd->lex->unit && (
unit->fake_select_lex == 0 ||
612 ORDER_with_src &tmp_table_group,
613 bool save_sum_fields);
618 bool create_first_intermediate_table();
625 void optimize_distinct();
638 void optimize_fts_query();
644 void optimize_fts_limit_query();
657 void replace_item_field(
const char* field_name,
Item* new_item);
659 #ifdef WITH_PARTITION_STORAGE_ENGINE
660 bool prune_table_partitions(THD *thd);
666 bool implicit_grouping;
668 void set_prefix_tables();
673 void set_semijoin_info();
674 bool set_access_methods();
675 bool setup_materialized_table(
JOIN_TAB *tab, uint tableno,
678 bool make_tmp_tables_info();
679 bool compare_costs_of_subquery_strategies(
683 class Prepare_error_tracker
686 Prepare_error_tracker(THD *thd_arg) : thd(thd_arg) {}
687 ~Prepare_error_tracker()
689 if (unlikely(thd->is_error()))
690 thd->lex->mark_broken();
699 bool uses_index_fields_only(
Item *item,
TABLE *tbl, uint keyno,
706 bool build_equalities, Item::cond_result *cond_value);
709 void *table_join_idx);
723 bool exclude_expensive_cond);
731 inline bool field_time_cmp_date(
const Field *f,
const Item *v)
733 return f->is_temporal() && !f->is_temporal_with_date() &&
734 v->is_temporal_with_date();