Namespaces | |
namespace | drizzled |
TODO: Rename this file - func.h is stupid. |
Functions | |
static bool | drizzled::make_group_fields (Join *main_join, Join *curr_join) |
static void | drizzled::calc_group_buffer (Join *join, Order *group) |
static bool | drizzled::alloc_group_fields (Join *join, Order *group) |
static uint32_t | drizzled::cache_record_length (Join *join, uint32_t index) |
static double | drizzled::prev_record_reads (Join *join, uint32_t idx, table_map found_ref) |
static bool | drizzled::get_best_combination (Join *join) |
static void | drizzled::set_position (Join *join, uint32_t index, JoinTable *table, optimizer::KeyUse *key) |
static bool | drizzled::choose_plan (Join *join, table_map join_tables) |
static void | drizzled::best_access_path (Join *join, JoinTable *s, Session *session, table_map remaining_tables, uint32_t idx, double record_count, double read_time) |
static void | drizzled::optimize_straight_join (Join *join, table_map join_tables) |
static bool | drizzled::greedy_search (Join *join, table_map remaining_tables, uint32_t depth, uint32_t prune_level) |
static bool | drizzled::best_extension_by_limited_search (Join *join, table_map remaining_tables, uint32_t idx, double record_count, double read_time, uint32_t depth, uint32_t prune_level) |
static uint32_t | drizzled::determine_search_depth (Join *join) |
static void | drizzled::make_simple_join (Join *, Table *) |
static void | drizzled::make_outerjoin_info (Join *join) |
static bool | drizzled::make_join_select (Join *join, optimizer::SqlSelect *select, COND *item) |
static void | drizzled::make_join_readinfo (Join &) |
static void | drizzled::update_depend_map (Join *join) |
static void | drizzled::update_depend_map (Join *join, Order *order) |
static Order * | drizzled::remove_constants (Join *join, Order *first_order, COND *cond, bool change_list, bool *simple_order) |
static void | drizzled::return_zero_rows (Join *join, select_result *res, TableList *tables, List< Item > &fields, bool send_row, uint64_t select_options, const char *info, Item *having) |
static COND * | drizzled::simplify_joins (Join *join, List< TableList > *join_list, COND *conds, bool top) |
static int | drizzled::remove_duplicates (Join *join, Table *entry, List< Item > &fields, Item *having) |
static int | drizzled::setup_without_group (Session *session, Item **ref_pointer_array, TableList *tables, TableList *, List< Item > &fields, List< Item > &all_fields, COND **conds, Order *order, Order *group, bool *hidden_group_fields) |
static bool | drizzled::make_join_statistics (Join *join, TableList *leaves, COND *conds, DYNAMIC_ARRAY *keyuse) |
static uint32_t | drizzled::build_bitmap_for_nested_joins (List< TableList > *join_list, uint32_t first_unused) |
static Table * | drizzled::get_sort_by_table (Order *a, Order *b, TableList *tables) |
static void | drizzled::reset_nj_counters (List< TableList > *join_list) |
static bool | drizzled::test_if_subpart (Order *a, Order *b) |
static void | drizzled::restore_prev_nj_state (JoinTable *last) |
static bool | drizzled::add_ref_to_table_cond (Session *session, JoinTable *join_tab) |
static void | drizzled::free_blobs (Field **ptr) |
static void | drizzled::clear_tables (Join *join) |
enum_nested_loop_state | drizzled::evaluate_join_record (Join *join, JoinTable *join_tab, int error) |
Process one record of the nested loop join. | |
enum_nested_loop_state | drizzled::evaluate_null_complemented_join_record (Join *join, JoinTable *join_tab) |
enum_nested_loop_state | drizzled::flush_cached_records (Join *join, JoinTable *join_tab, bool skip_last) |
enum_nested_loop_state | drizzled::end_send (Join *join, JoinTable *, bool end_of_records) |
enum_nested_loop_state | drizzled::end_write (Join *join, JoinTable *, bool end_of_records) |
enum_nested_loop_state | drizzled::end_update (Join *join, JoinTable *, bool end_of_records) |
enum_nested_loop_state | drizzled::end_unique_update (Join *join, JoinTable *, bool end_of_records) |
static uint32_t | drizzled::used_blob_length (CacheField **ptr) |
int | drizzled::join_init_cache (Session *session, JoinTable *tables, uint32_t table_count) |
static int | drizzled::sort_keyuse (optimizer::KeyUse *a, optimizer::KeyUse *b) |
static COND * | drizzled::build_equal_items (Session *session, COND *cond, COND_EQUAL *inherited, List< TableList > *join_list, COND_EQUAL **cond_equal_ref) |
static Item * | drizzled::part_of_refkey (Table *form, Field *field) |
static bool | drizzled::cmp_buffer_with_ref (JoinTable *tab) |
static void | drizzled::change_cond_ref_to_const (Session *session, list< COND_CMP > &save_list, Item *and_father, Item *cond, Item *field, Item *value) |
static void | drizzled::copy_blobs (Field **ptr) |
static bool | drizzled::eval_const_cond (COND *cond) |
bool | drizzled::handle_select (Session *session, LEX *lex, select_result *result, uint64_t setup_tables_done_option) |
bool | drizzled::fix_inner_refs (Session *session, List< Item > &all_fields, Select_Lex *select, Item **ref_pointer_array) |
void | drizzled::save_index_subquery_explain_info (JoinTable *join_tab, Item *where) |
bool | drizzled::select_query (Session *session, Item ***rref_pointer_array, TableList *tables, uint32_t wild_num, List< Item > &fields, COND *conds, uint32_t og_num, Order *order, Order *group, Item *having, uint64_t select_options, select_result *result, Select_Lex_Unit *unit, Select_Lex *select_lex) |
Item * | drizzled::and_items (Item *cond, Item *item) |
ha_rows | drizzled::get_quick_record_count (Session *session, optimizer::SqlSelect *select, Table *table, const key_map *keys, ha_rows limit) |
uint32_t | drizzled::max_part_bit (key_part_map bits) |
void | drizzled::update_ref_and_keys (Session *session, DYNAMIC_ARRAY *keyuse, JoinTable *join_tab, uint32_t tables, COND *cond, COND_EQUAL *, table_map normal_tables, Select_Lex *select_lex, vector< optimizer::SargableParam > &sargables) |
void | drizzled::optimize_keyuse (Join *join, DYNAMIC_ARRAY *keyuse_array) |
void | drizzled::add_group_and_distinct_keys (Join *join, JoinTable *join_tab) |
int | drizzled::join_tab_cmp (const void *ptr1, const void *ptr2) |
int | drizzled::join_tab_cmp_straight (const void *ptr1, const void *ptr2) |
void | drizzled::calc_used_field_length (Session *, JoinTable *join_tab) |
StoredKey * | drizzled::get_store_key (Session *session, optimizer::KeyUse *keyuse, table_map used_tables, KeyPartInfo *key_part, unsigned char *key_buff, uint32_t maybe_null) |
bool | drizzled::store_val_in_field (Field *field, Item *item, enum_check_fields check_flag) |
void | drizzled::add_cond_and_fix (Item **e1, Item *e2) |
bool | drizzled::create_ref_for_key (Join *join, JoinTable *j, optimizer::KeyUse *org_keyuse, table_map used_tables) |
bool | drizzled::eq_ref_table (Join *join, Order *start_order, JoinTable *tab) |
static Item_equal * | drizzled::find_item_equal (COND_EQUAL *cond_equal, Field *field, bool *inherited_fl) |
static bool | drizzled::check_simple_equality (Item *left_item, Item *right_item, Item *item, COND_EQUAL *cond_equal) |
static bool | drizzled::check_row_equality (Session *session, Item *left_row, Item_row *right_row, COND_EQUAL *cond_equal, List< Item > *eq_list) |
static bool | drizzled::check_equality (Session *session, Item *item, COND_EQUAL *cond_equal, List< Item > *eq_list) |
static COND * | drizzled::build_equal_items_for_cond (Session *session, COND *cond, COND_EQUAL *inherited) |
static int | drizzled::compare_fields_by_table_order (Item_field *field1, Item_field *field2, void *table_join_idx) |
static Item * | drizzled::eliminate_item_equal (COND *cond, COND_EQUAL *upper_levels, Item_equal *item_equal) |
COND * | drizzled::substitute_for_best_equal_field (COND *cond, COND_EQUAL *cond_equal, void *table_join_idx) |
void | drizzled::update_const_equal_items (COND *cond, JoinTable *tab) |
Item * | drizzled::remove_additional_cond (Item *conds) |
static void | drizzled::propagate_cond_constants (Session *session, list< COND_CMP > &save_list, COND *and_father, COND *cond) |
bool | drizzled::check_interleaving_with_nj (JoinTable *next_tab) |
COND * | drizzled::optimize_cond (Join *join, COND *conds, List< TableList > *join_list, Item::cond_result *cond_value) |
COND * | drizzled::remove_eq_conds (Session *session, COND *cond, Item::cond_result *cond_value) |
static bool | drizzled::test_if_equality_guarantees_uniqueness (Item *l, Item *r) |
bool | drizzled::const_expression_in_where (COND *cond, Item *comp_item, Item **const_item) |
Next_select_func | drizzled::setup_end_select_func (Join *join) |
int | drizzled::do_select (Join *join, List< Item > *fields, Table *table) |
enum_nested_loop_state | drizzled::sub_select_cache (Join *join, JoinTable *join_tab, bool end_of_records) |
enum_nested_loop_state | drizzled::sub_select (Join *join, JoinTable *join_tab, bool end_of_records) |
int | drizzled::safe_index_read (JoinTable *tab) |
int | drizzled::join_read_const (JoinTable *tab) |
int | drizzled::join_read_key (JoinTable *tab) |
int | drizzled::join_read_always_key (JoinTable *tab) |
int | drizzled::join_read_last_key (JoinTable *tab) |
int | drizzled::join_no_more_records (ReadRecord *) |
int | drizzled::join_read_next_same_diff (ReadRecord *info) |
int | drizzled::join_read_next_same (ReadRecord *info) |
int | drizzled::join_read_prev_same (ReadRecord *info) |
int | drizzled::join_init_quick_read_record (JoinTable *tab) |
int | drizzled::init_read_record_seq (JoinTable *tab) |
int | drizzled::test_if_quick_select (JoinTable *tab) |
int | drizzled::join_init_read_record (JoinTable *tab) |
int | drizzled::join_read_first (JoinTable *tab) |
int | drizzled::join_read_next_different (ReadRecord *info) |
int | drizzled::join_read_next (ReadRecord *info) |
int | drizzled::join_read_last (JoinTable *tab) |
int | drizzled::join_read_prev (ReadRecord *info) |
int | drizzled::join_read_always_key_or_null (JoinTable *tab) |
int | drizzled::join_read_next_same_or_null (ReadRecord *info) |
enum_nested_loop_state | drizzled::end_send_group (Join *join, JoinTable *, bool end_of_records) |
enum_nested_loop_state | drizzled::end_write_group (Join *join, JoinTable *, bool end_of_records) |
bool | drizzled::test_if_ref (Item_field *left_item, Item *right_item) |
COND * | drizzled::make_cond_for_table (COND *cond, table_map tables, table_map used_table, bool exclude_expensive_cond) |
static int | drizzled::test_if_order_by_key (Order *order, Table *table, uint32_t idx, uint32_t *used_key_parts) |
bool | drizzled::is_subkey (KeyPartInfo *key_part, KeyPartInfo *ref_key_part, KeyPartInfo *ref_key_part_end) |
static uint32_t | drizzled::test_if_subkey (Order *order, Table *table, uint32_t ref, uint32_t ref_key_parts, const key_map *usable_keys) |
bool | drizzled::list_contains_unique_index (Table *table, bool(*find_func)(Field *, void *), void *data) |
bool | drizzled::find_field_in_order_list (Field *field, void *data) |
bool | drizzled::find_field_in_item_list (Field *field, void *data) |
bool | drizzled::test_if_skip_sort_order (JoinTable *tab, Order *order, ha_rows select_limit, bool no_changes, const key_map *map) |
int | drizzled::create_sort_index (Session *session, Join *join, Order *order, ha_rows filesort_limit, ha_rows select_limit, bool is_order_by) |
int | drizzled::remove_dup_with_compare (Session *session, Table *table, Field **first_field, uint32_t offset, Item *having) |
int | drizzled::remove_dup_with_hash_index (Session *session, Table *table, uint32_t field_count, Field **first_field, uint32_t key_length, Item *having) |
SortField * | drizzled::make_unireg_sortorder (Order *order, uint32_t *length, SortField *sortorder) |
bool | drizzled::cp_buffer_from_ref (Session *session, table_reference_st *ref) |
static bool | drizzled::find_order_in_list (Session *session, Item **ref_pointer_array, TableList *tables, Order *order, List< Item > &fields, List< Item > &all_fields, bool is_group_field) |
int | drizzled::setup_order (Session *session, Item **ref_pointer_array, TableList *tables, List< Item > &fields, List< Item > &all_fields, Order *order) |
int | drizzled::setup_group (Session *session, Item **ref_pointer_array, TableList *tables, List< Item > &fields, List< Item > &all_fields, Order *order, bool *hidden_group_fields) |
Order * | drizzled::create_distinct_group (Session *session, Item **ref_pointer_array, Order *order_list, List< Item > &fields, List< Item > &, bool *all_order_by_fields_used) |
void | drizzled::count_field_types (Select_Lex *select_lex, Tmp_Table_Param *param, List< Item > &fields, bool reset_with_sum_func) |
int | drizzled::test_if_item_cache_changed (List< Cached_item > &list) |
bool | drizzled::setup_copy_fields (Session *session, Tmp_Table_Param *param, Item **ref_pointer_array, List< Item > &res_selected_fields, List< Item > &res_all_fields, uint32_t elements, List< Item > &all_fields) |
void | drizzled::copy_fields (Tmp_Table_Param *param) |
bool | drizzled::change_to_use_tmp_fields (Session *session, Item **ref_pointer_array, List< Item > &res_selected_fields, List< Item > &res_all_fields, uint32_t elements, List< Item > &all_fields) |
bool | drizzled::change_refs_to_tmp_fields (Session *session, Item **ref_pointer_array, List< Item > &res_selected_fields, List< Item > &res_all_fields, uint32_t elements, List< Item > &all_fields) |
bool | drizzled::setup_sum_funcs (Session *session, Item_sum **func_ptr) |
void | drizzled::init_tmptable_sum_functions (Item_sum **func_ptr) |
void | drizzled::update_tmptable_sum_func (Item_sum **func_ptr, Table *) |
void | drizzled::copy_sum_funcs (Item_sum **func_ptr, Item_sum **end_ptr) |
bool | drizzled::init_sum_functions (Item_sum **func_ptr, Item_sum **end_ptr) |
bool | drizzled::update_sum_func (Item_sum **func_ptr) |
bool | drizzled::copy_funcs (Item **func_ptr, const Session *session) |
void | drizzled::free_underlaid_joins (Session *session, Select_Lex *select) |
bool | drizzled::change_group_ref (Session *session, Item_func *expr, Order *group_list, bool *changed) |
static void | drizzled::print_table_array (Session *session, String *str, TableList **table, TableList **end) |
void | drizzled::print_join (Session *session, String *str, List< TableList > *tables) |
drizzled::Join::Join (Session *session_arg, List< Item > &fields_arg, uint64_t select_options_arg, select_result *result_arg) | |
void | drizzled::Join::reset (Session *session_arg, List< Item > &fields_arg, uint64_t select_options_arg, select_result *result_arg) |
bool | drizzled::Join::is_top_level_join () const |
int | drizzled::Join::prepare (Item ***rref_pointer_array, TableList *tables, uint32_t wind_num, COND *conds, uint32_t og_num, Order *order, Order *group, Item *having, Select_Lex *select, Select_Lex_Unit *unit) |
void | drizzled::Join::remove_subq_pushed_predicates (Item **where) |
int | drizzled::Join::optimize () |
void | drizzled::Join::restore_tmp () |
int | drizzled::Join::reinit () |
void | drizzled::Join::init_save_join_tab () |
Save the original join layout. | |
void | drizzled::Join::save_join_tab () |
void | drizzled::Join::exec () |
int | drizzled::Join::destroy () |
bool | drizzled::Join::setup_subquery_materialization () |
void | drizzled::Join::join_free () |
void | drizzled::Join::cleanup (bool full) |
bool | drizzled::Join::alloc_func_list () |
bool | drizzled::Join::make_sum_func_list (List< Item > &all_fields, List< Item > &send_fields, bool before_group_by, bool recompute=false) |
bool | drizzled::Join::rollup_init () |
bool | drizzled::Join::rollup_make_fields (List< Item > &all_fields, List< Item > &fields, Item_sum ***func) |
int | drizzled::Join::rollup_send_data (uint32_t idx) |
int | drizzled::Join::rollup_write_data (uint32_t idx, Table *table) |
void | drizzled::Join::clear () |
bool | drizzled::Join::change_result (select_result *result) |
void | drizzled::Join::cache_const_exprs () |
bool | drizzled::JoinCache::store_record_in_cache () |
void | drizzled::JoinCache::reset_cache_read () |
void | drizzled::JoinCache::reset_cache_write () |
Variables | |
plugin::StorageEngine * | drizzled::heap_engine |
const char * | drizzled::subq_sj_cond_name = "0123456789ABCDEF0123456789abcdef0123456789ABCDEF0123456789abcdef-sj-cond" |
void drizzled::add_group_and_distinct_keys | ( | Join * | join, |
JoinTable * | join_tab | ||
) |
Discover the indexes that can be used for GROUP BY or DISTINCT queries.
If the query has a GROUP BY clause, find all indexes that contain all GROUP BY fields, and add those indexes to join->const_keys.
If the query has a DISTINCT clause, find all indexes that contain all SELECT fields, and add those indexes to join->const_keys. This allows later on such queries to be processed by a QUICK_GROUP_MIN_MAX_SELECT.
join | |
join_tab |
Definition at line 772 of file sql_select.cc.
References drizzled::JoinTable::const_keys, drizzled::Join::fields_list, drizzled::Join::group_list, and drizzled::Join::select_distinct.
Referenced by drizzled::make_join_statistics().
|
static |
Create a condition for a const reference and add this to the currenct select for the table.
Definition at line 6189 of file join.cc.
References drizzled::optimizer::SqlSelect::cond, drizzled::Item::fixed, drizzled::Session::is_fatal_error, drizzled::table_reference_st::items, drizzled::table_reference_st::key, drizzled::Table::key_info, and drizzled::table_reference_st::key_parts.
Referenced by drizzled::Join::optimize().
bool drizzled::Join::alloc_func_list | ( | ) |
Make an array of pointers to sum_functions to speed up sum_func calculation.
0 | ok |
1 | Error |
Definition at line 2128 of file join.cc.
References drizzled::Join::fields_list, drizzled::Join::rollup, and drizzled::Join::select_distinct.
Referenced by drizzled::Join::exec(), and drizzled::Join::prepare().
|
static |
Get a list of buffers for saveing last group.
Groups are saved in reverse order for easyer check loop.
Definition at line 3223 of file join.cc.
References drizzled::new_Cached_item().
Referenced by drizzled::make_group_fields(), and drizzled::Join::optimize().
|
static |
Find the best access path for an extension of a partial execution plan and add this path to the plan.
The function finds the best access path to table 's' from the passed partial plan where an access path is the general term for any means to access the data in 's'. An access path may use either an index or a scan, whichever is cheaper. The input partial plan is passed via the array 'join->positions' of length 'idx'. The chosen access method for 's' and its cost are stored in 'join->positions[idx]'.
join | pointer to the structure providing all context info for the query |
s | the table to be joined by the function |
session | thread for the connection that submitted the query |
remaining_tables | set of tables not included into the partial plan yet |
idx | the length of the partial plan |
record_count | estimate for the number of records returned by the partial plan |
read_time | the cost of the partial plan |
Definition at line 3503 of file join.cc.
References drizzled::Table::cursor, drizzled::JoinTable::found_records, drizzled::optimizer::QuickSelectInterface::index, drizzled::Cursor::index_only_read_time(), drizzled::Table::key_info, drizzled::JoinTable::keyuse, drizzled::Table::map, MATCHING_ROWS_IN_OTHER_TABLE, drizzled::max_part_bit(), drizzled::Table::quick_condition_rows, drizzled::optimizer::QuickSelectInterface::read_time, drizzled::JoinTable::read_time, drizzled::JoinTable::records, drizzled::Join::setPosInPartialPlan(), drizzled::Join::sort_by_table, TIME_FOR_COMPARE, drizzled::Join::unit, and drizzled::Session::variables.
Referenced by drizzled::best_extension_by_limited_search(), and drizzled::optimize_straight_join().
|
static |
Find a good, possibly optimal, query execution plan (QEP) by a possibly exhaustive search.
The procedure searches for the optimal ordering of the query tables in set 'remaining_tables' of size N, and the corresponding optimal access paths to each table. The choice of a table order and an access path for each table constitutes a query execution plan (QEP) that fully specifies how to execute the query.
The maximal size of the found plan is controlled by the parameter 'search_depth'. When search_depth == N, the resulting plan is complete and can be used directly as a QEP. If search_depth < N, the found plan consists of only some of the query tables. Such "partial" optimal plans are useful only as input to query optimization procedures, and cannot be used directly to execute a query.
The algorithm begins with an empty partial plan stored in 'join->positions' and a set of N tables - 'remaining_tables'. Each step of the algorithm evaluates the cost of the partial plan extended by all access plans for each of the relations in 'remaining_tables', expands the current partial plan with the access plan that results in lowest cost of the expanded partial plan, and removes the corresponding relation from 'remaining_tables'. The algorithm continues until it either constructs a complete optimal plan, or constructs an optimal plartial plan with size = search_depth.
The final optimal plan is stored in 'join->best_positions'. The corresponding cost of the optimal plan is in 'join->best_read'.
join | pointer to the structure providing all context info for the query |
remaining_tables | set of tables not included into the partial plan yet |
idx | length of the partial QEP in 'join->positions'; since a depth-first search is used, also corresponds to the current depth of the search tree; also an index in the array 'join->best_ref'; |
record_count | estimate for the number of records returned by the best partial plan |
read_time | the cost of the best partial plan |
search_depth | maximum depth of the recursion and thus size of the found optimal plan (0 < search_depth <= join->tables+1). |
prune_level | pruning heuristics that should be applied during optimization (values: 0 = EXHAUSTIVE, 1 = PRUNE_BY_TIME_OR_ROWS) |
false | ok |
true | Fatal error |
Definition at line 4331 of file join.cc.
References drizzled::best_access_path(), drizzled::Join::best_read, drizzled::check_interleaving_with_nj(), drizzled::Join::copyPartialPlanIntoOptimalPlan(), drizzled::Join::getPosFromPartialPlan(), drizzled::optimizer::Position::hasTableForSorting(), drizzled::optimizer::Position::isConstTable(), drizzled::Table::map, drizzled::restore_prev_nj_state(), drizzled::Join::sort_by_table, and TIME_FOR_COMPARE.
Referenced by drizzled::greedy_search().
|
static |
Assign each nested join structure a bit in the nested join bitset.
Assign each nested join structure (except "confluent" ones - those that embed only one element) a bit in the nested join bitset.
join | Join being processed |
join_list | List of tables |
first_unused | Number of first unused bit in the nest joing bitset before the call |
Definition at line 6012 of file join.cc.
Referenced by drizzled::Join::optimize().
|
static |
Build multiple equalities for a condition and all on expressions that inherit these multiple equalities.
The function first applies the build_equal_items_for_cond function to build all multiple equalities for condition cond utilizing equalities referred through the parameter inherited. The extended set of equalities is returned in the structure referred by the cond_equal_ref parameter. After this the function calls itself recursively for all on expressions whose direct references can be found in join_list and who inherit directly the multiple equalities just having built.
Interesting that multiple equality =(t1.a,t2.a,t3.a,t4.a) allows us to use t1.a=t3.a AND t3.a=t4.a under the on condition:
This query equivalent to:
Similarly the original query can be rewritten to the query:
that is equivalent to:
Thus, applying equalities from the where condition we basically can get more freedom in performing join operations. Althogh we don't use this property now, it probably makes sense to use it in the future.
session | Thread Cursor | |
cond | condition to build the multiple equalities for | |
inherited | path to all inherited multiple equality items | |
join_list | list of join tables to which the condition refers to | |
[out] | cond_equal_ref | pointer to the structure to place built equalities in |
Definition at line 2096 of file sql_select.cc.
References drizzled::build_equal_items_for_cond(), drizzled::TableList::cond_equal, and drizzled::TableList::on_expr.
|
static |
Replace all equality predicates in a condition by multiple equality items.
At each 'and' level the function detects items for equality predicates and replaced them by a set of multiple equality items of class Item_equal, taking into account inherited equalities from upper levels. If an equality predicate is used not in a conjunction it's just replaced by a multiple equality predicate. For each 'and' level the function set a pointer to the inherited multiple equalities in the cond_equal field of the associated object of the type Item_cond_and. The function also traverses the cond tree and and for each field reference sets a pointer to the multiple equality item containing the field, if there is any. If this multiple equality equates fields to a constant the function replaces the field reference by the constant in the cases when the field is not of a string type or when the field reference is just an argument of a comparison predicate. The function also determines the maximum number of members in equality lists of each Item_cond_and object assigning it to session->lex().current_select->max_equal_elems.
The function performs the substitution in a recursive descent by the condtion tree, passing to the next AND level a chain of multiple equality predicates which have been built at the upper levels. The Item_equal items built at the level are attached to other non-equality conjucts as a sublist. The pointer to the inherited multiple equalities is saved in the and condition object (Item_cond_and). This chain allows us for any field reference occurence easyly to find a multiple equality that must be held for this occurence. For each AND level we do the following:
We need to do things in this order as lower AND levels need to know about all possible Item_equal objects in upper levels.
session | thread handle |
cond | condition(expression) where to make replacement |
inherited | path to all inherited multiple equality items |
Definition at line 1882 of file sql_select.cc.
References drizzled::check_equality(), drizzled::Item::compile(), and drizzled::Item::quick_fix_field().
Referenced by drizzled::build_equal_items().
void drizzled::Join::cache_const_exprs | ( | ) |
Cache constant expressions in WHERE, HAVING, ON conditions.
Definition at line 2565 of file join.cc.
References drizzled::Item::cache_const_expr_analyzer(), drizzled::Item::cache_const_expr_transformer(), drizzled::Item::compile(), and drizzled::Join::tables.
Referenced by drizzled::Join::optimize().
|
static |
calc how big buffer we need for comparing group entries.
Definition at line 3138 of file join.cc.
References drizzled::Field::field_length, drizzled::Item::maybe_null, and drizzled::Field::pack_length().
Referenced by drizzled::Join::exec(), and drizzled::Join::optimize().
void drizzled::calc_used_field_length | ( | Session * | , |
JoinTable * | join_tab | ||
) |
Find how much space the prevous read not const tables takes in cache.
Definition at line 883 of file sql_select.cc.
References drizzled::Table::cursor, drizzled::Field::pack_length(), drizzled::JoinTable::used_blobs, drizzled::JoinTable::used_fieldlength, and drizzled::JoinTable::used_fields.
bool drizzled::change_group_ref | ( | Session * | session, |
Item_func * | expr, | ||
Order * | group_list, | ||
bool * | changed | ||
) |
Replace occurences of group by fields in an expression by ref items.
The function replaces occurrences of group by fields in expr by ref objects for these fields unless they are under aggregate functions. The function also corrects value of the the maybe_null attribute for the items of all subexpressions containing group by fields.
EXAMPLES
IMPLEMENTATION
The function recursively traverses the tree of the expr expression, looks for occurrences of the group by fields that are not under aggregate functions and replaces them for the corresponding ref items.
session | reference to the context |
expr | expression to make replacement |
group_list | list of references to group by items |
changed | out: returns 1 if item contains a replaced field item |
Some functions are not null-preserving. For those functions updating of the maybe_null attribute is an overkill.
0 | if ok |
1 | on error |
Definition at line 6706 of file sql_select.cc.
References drizzled::Item::eq(), drizzled::Item::maybe_null, and drizzled::Item::name.
Referenced by drizzled::Join::rollup_init().
bool drizzled::change_refs_to_tmp_fields | ( | Session * | session, |
Item ** | ref_pointer_array, | ||
List< Item > & | res_selected_fields, | ||
List< Item > & | res_all_fields, | ||
uint32_t | elements, | ||
List< Item > & | all_fields | ||
) |
Change all sum_func refs to fields to point at fields in tmp table. Change all funcs to be fields in tmp table.
session | Session pointer |
ref_pointer_array | array of pointers to top elements of filed list |
res_selected_fields | new list of items of select item list |
res_all_fields | new list of all items |
elements | number of elements in select item list |
all_fields | all fields list |
0 | ok |
1 | error |
Definition at line 6510 of file sql_select.cc.
References drizzled::Session::is_fatal_error.
Referenced by drizzled::Join::exec().
bool drizzled::Join::change_result | ( | select_result * | res | ) |
change select_result object of Join.
res | new select_result object |
false | OK |
true | error |
Definition at line 2551 of file join.cc.
References drizzled::Join::fields_list, and drizzled::Join::select_lex.
Referenced by drizzled::subselect_hash_sj_engine::init_runtime(), and drizzled::select_query().
bool drizzled::change_to_use_tmp_fields | ( | Session * | session, |
Item ** | ref_pointer_array, | ||
List< Item > & | res_selected_fields, | ||
List< Item > & | res_all_fields, | ||
uint32_t | elements, | ||
List< Item > & | all_fields | ||
) |
Change all funcs and sum_funcs to fields in tmp table, and create new list of all items.
session | Session pointer |
ref_pointer_array | array of pointers to top elements of filed list |
res_selected_fields | new list of items of select item list |
res_all_fields | new list of all items |
elements | number of elements in select item list |
all_fields | all fields list |
0 | ok |
!=0 | error |
Definition at line 6418 of file sql_select.cc.
References drizzled::Field::orig_table.
Referenced by drizzled::Join::exec().
|
static |
Eliminate row equalities and form multiple equalities predicates.
This function checks whether the item is a simple equality i.e. the one that equates a field with another field or a constant (field=field_item or field=constant_item), or, a row equality. For a simple equality the function looks for a multiple equality in the lists referenced directly or indirectly by cond_equal inferring the given simple equality. If it doesn't find any, it builds/expands multiple equality that covers the predicate. Row equalities are eliminated substituted for conjunctive regular equalities which are treated in the same way as original equality predicates.
session | thread handle |
item | predicate to process |
cond_equal | multiple equalities that must hold together with the predicate |
eq_list | results of conversions of row equalities that are not simple enough to form multiple equalities |
true | if re-writing rules have been applied |
false | otherwise, i.e. if the predicate is not an equality, or, if the equality is neither a simple one nor a row equality, or, if the procedure fails by a fatal error. |
Definition at line 1794 of file sql_select.cc.
References drizzled::check_row_equality(), and drizzled::check_simple_equality().
Referenced by drizzled::build_equal_items_for_cond().
bool drizzled::check_interleaving_with_nj | ( | JoinTable * | next_tab | ) |
Check interleaving with an inner tables of an outer join for extension table.
Check if table next_tab can be added to current partial join order, and if yes, record that it has been added.
The function assumes that both current partial join order and its extension with next_tab are valid wrt table dependencies.
IMPLEMENTATION LIMITATIONS ON JOIN order_st The nested [outer] joins executioner algorithm imposes these limitations on join order: 1. "Outer tables first" - any "outer" table must be before any corresponding "inner" table. 2. "No interleaving" - tables inside a nested join must form a continuous sequence in join order (i.e. the sequence must not be interrupted by tables that are outside of this nested join). #1 is checked elsewhere, this function checks #2 provided that #1 has been already checked. WHY NEED NON-INTERLEAVING Consider an example: select * from t0 join t1 left join (t2 join t3) on cond1 The join order "t1 t2 t0 t3" is invalid: table t0 is outside of the nested join, so WHERE condition for t0 is attached directly to t0 (without triggers, and it may be used to access t0). Applying WHERE(t0) to (t2,t0,t3) record is invalid as we may miss combinations of (t1, t2, t3) that satisfy condition cond1, and produce a null-complemented (t1, t2.NULLs, t3.NULLs) row, which should not have been produced. If table t0 is not between t2 and t3, the problem doesn't exist: If t0 is located after (t2,t3), WHERE(t0) is applied after nested join processing has finished. If t0 is located before (t2,t3), predicates like WHERE_cond(t0, t2) are wrapped into condition triggers, which takes care of correct nested join processing. HOW IT IS IMPLEMENTED The limitations on join order can be rephrased as follows: for valid join order one must be able to: 1. write down the used tables in the join order on one line. 2. for each nested join, put one '(' and one ')' on the said line 3. write "LEFT JOIN" and "ON (...)" where appropriate 4. get a query equivalent to the query we're trying to execute. Calls to check_interleaving_with_nj() are equivalent to writing the above described line from left to right. A single check_interleaving_with_nj(A,B) call is equivalent to writing table B and appropriate brackets on condition that table A and appropriate brackets is the last what was written. Graphically the transition is as follows: +---- current position | ... last_tab ))) | ( next_tab ) )..) | ... X Y Z | +- need to move to this position. Notes about the position: The caller guarantees that there is no more then one X-bracket by checking "!(remaining_tables & s->dependent)" before calling this function. X-bracket may have a pair in Y-bracket. When "writing" we store/update this auxilary info about the current position: 1. join->cur_embedding_map - bitmap of pairs of brackets (aka nested joins) we've opened but didn't close. 2. {each NestedJoin class not simplified away}->counter - number of this nested join's children that have already been added to to the partial join order.
join | Join being processed |
next_tab | Table we're going to extend the current partial join with |
false | Join order extended, nested joins info about current join order (see NOTE section) updated. |
true | Requested join order extension not allowed. |
Definition at line 2763 of file sql_select.cc.
References drizzled::Join::cur_embedding_map, and drizzled::JoinTable::embedding_map.
Referenced by drizzled::best_extension_by_limited_search(), and drizzled::greedy_search().
|
static |
Convert row equalities into a conjunction of regular equalities.
The function converts a row equality of the form (E1,...,En)=(E'1,...,E'n) into a list of equalities E1=E'1,...,En=E'n. For each of these equalities Ei=E'i the function checks whether it is a simple equality or a row equality. If it is a simple equality it is used to expand multiple equalities of cond_equal. If it is a row equality it converted to a sequence of equalities between row elements. If Ei=E'i is neither a simple equality nor a row equality the item for this predicate is added to eq_list.
session | thread handle |
left_row | left term of the row equality to be processed |
right_row | right term of the row equality to be processed |
cond_equal | multiple equalities that must hold together with the predicate |
eq_list | results of conversions of row equalities that are not simple enough to form multiple equalities |
true | if conversion has succeeded (no fatal error) |
false | otherwise |
Definition at line 1723 of file sql_select.cc.
References drizzled::check_simple_equality(), and drizzled::Item::quick_fix_field().
Referenced by drizzled::check_equality().
|
static |
Check whether an equality can be used to build multiple equalities.
This function first checks whether the equality (left_item=right_item) is a simple equality i.e. the one that equates a field with another field or a constant (field=field_item or field=const_item). If this is the case the function looks for a multiple equality in the lists referenced directly or indirectly by cond_equal inferring the given simple equality. If it doesn't find any, it builds a multiple equality that covers the predicate, i.e. the predicate can be inferred from this multiple equality. The built multiple equality could be obtained in such a way: create a binary multiple equality equivalent to the predicate, then merge it, if possible, with one of old multiple equalities. This guarantees that the set of multiple equalities covering equality predicates will be minimal.
EXAMPLE: For the where condition
the check_equality will be called for the following equality predicates a=b, b=c, b=2 and f=e.
The implementation does not follow exactly the above rules to build a new multiple equality for the equality predicate. If it processes the equality of the form field1=field2, it looks for multiple equalities me1 containig field1 and me2 containing field2. If only one of them is found the fuction expands it with the lacking field. If multiple equalities for both fields are found they are merged. If both searches fail a new multiple equality containing just field1 and field2 is added to the existing multiple equalities. If the function processes the predicate of the form field1=const, it looks for a multiple equality containing field1. If found, the function checks the constant of the multiple equality. If the value is unknown, it is setup to const. Otherwise the value is compared with const and the evaluation of the equality predicate is performed. When expanding/merging equality predicates from the upper levels the function first copies them for the current level. It looks acceptable, as this happens rarely. The implementation without copying would be much more complicated.
left_item | left term of the quality to be checked |
right_item | right term of the equality to be checked |
item | equality item if the equality originates from a condition predicate, 0 if the equality is the result of row elimination |
cond_equal | multiple equalities that must hold together with the equality |
true | if the predicate is a simple equality predicate to be used for building multiple equalities |
false | otherwise |
Definition at line 1524 of file sql_select.cc.
References drizzled::Item::const_item(), drizzled::Field::eq_def(), drizzled::find_item_equal(), drizzled::Item_equal::merge(), drizzled::Item::name, and drizzled::Item::quick_fix_field().
Referenced by drizzled::check_equality(), and drizzled::check_row_equality().
|
static |
Selects and invokes a search strategy for an optimal query plan.
The function checks user-configurable parameters that control the search strategy for an optimal plan, selects the search method and then invokes it. Each specific optimization procedure stores the final optimal plan in the array 'join->best_positions', and the cost of the plan in 'join->best_read'.
join | pointer to the structure providing all context info for the query |
join_tables | set of the tables in the query |
false | ok |
true | Fatal error |
Definition at line 3436 of file join.cc.
References drizzled::Join::best_read, drizzled::Join::cur_embedding_map, drizzled::determine_search_depth(), drizzled::greedy_search(), drizzled::Join::join_list, drizzled::join_tab_cmp(), drizzled::join_tab_cmp_straight(), drizzled::optimize_straight_join(), drizzled::reset_nj_counters(), drizzled::Join::tables, and drizzled::Session::variables.
Referenced by drizzled::make_join_statistics().
void drizzled::Join::cleanup | ( | bool | full | ) |
Cleanup this Join, possibly for reuse
Free resources of given join.
fill | true if we should free all resources, call with full==1 should be last, before it this function can be called with full==0 |
Definition at line 2036 of file join.cc.
References drizzled::Table::cursor, drizzled::Join::tables, and drizzled::Join::tmp_join.
Referenced by drizzled::Join::destroy(), and drizzled::Join::join_free().
void drizzled::Join::clear | ( | ) |
clear results if there are not rows found for group (end_send_group/end_write_group)
Definition at line 2528 of file join.cc.
References drizzled::copy_fields().
|
static |
Compare field items by table order in the execution plan.
field1 considered as better than field2 if the table containing field1 is accessed earlier than the table containing field2. The function finds out what of two fields is better according this criteria.
field1 | first field item to compare |
field2 | second field item to compare |
table_join_idx | index to tables determining table order |
1 | if field1 is better than field2 |
-1 | if field2 is better than field1 |
0 | otherwise |
Definition at line 2170 of file sql_select.cc.
References drizzled::Item_field::used_tables().
Referenced by drizzled::substitute_for_best_equal_field().
bool drizzled::const_expression_in_where | ( | COND * | cond, |
Item * | comp_item, | ||
Item ** | const_item | ||
) |
Return true if the item is a const value in all the WHERE clause.
Definition at line 3060 of file sql_select.cc.
References drizzled::Item::eq().
Referenced by drizzled::remove_constants().
void drizzled::copy_fields | ( | Tmp_Table_Param * | param | ) |
Make a copy of all simple SELECT'ed items.
This is done at the start of a new group so that we can retrieve these later when the group changes.
Definition at line 6387 of file sql_select.cc.
Referenced by drizzled::Join::clear(), drizzled::end_unique_update(), drizzled::end_update(), and drizzled::optimizer::QuickGroupMinMaxSelect::get_next().
bool drizzled::copy_funcs | ( | Item ** | func_ptr, |
const Session * | session | ||
) |
Copy result of functions to record in tmp_table.
Definition at line 6629 of file sql_select.cc.
References drizzled::Session::is_error().
Referenced by drizzled::end_unique_update(), and drizzled::end_update().
void drizzled::copy_sum_funcs | ( | Item_sum ** | func_ptr, |
Item_sum ** | end_ptr | ||
) |
Copy result of sum functions to record in tmp_table.
Definition at line 6588 of file sql_select.cc.
Referenced by drizzled::Join::rollup_write_data().
void drizzled::count_field_types | ( | Select_Lex * | select_lex, |
Tmp_Table_Param * | param, | ||
List< Item > & | fields, | ||
bool | reset_with_sum_func | ||
) |
Update join with count of the different type of fields.
Definition at line 6140 of file sql_select.cc.
Referenced by drizzled::Join::exec(), drizzled::Join::optimize(), and drizzled::Join::prepare().
Order * drizzled::create_distinct_group | ( | Session * | session, |
Item ** | ref_pointer_array, | ||
Order * | order_list, | ||
List< Item > & | fields, | ||
List< Item > & | , | ||
bool * | all_order_by_fields_used | ||
) |
Create a group by that consist of all non const fields.
Try to use the fields in the order given by 'order' to allow one to optimize away 'order by'.
Definition at line 6068 of file sql_select.cc.
References drizzled::memory::Root::memdup().
Referenced by drizzled::Join::optimize().
int drizzled::Join::destroy | ( | ) |
Clean up join.
Definition at line 1856 of file join.cc.
References drizzled::Join::cleanup(), drizzled::Join::destroy(), drizzled::Join::exec_tmp_table1, drizzled::Join::select, drizzled::Join::select_lex, drizzled::Join::tables, and drizzled::Join::tmp_join.
Referenced by drizzled::Join::destroy().
|
static |
Heuristic procedure to automatically guess a reasonable degree of exhaustiveness for the greedy search procedure.
The procedure estimates the optimization time and selects a search depth big enough to result in a near-optimal QEP, that doesn't take too long to find. If the number of tables in the query exceeds some constant, then search_depth is set to this constant.
join | pointer to the structure providing all context info for the query |
Definition at line 4478 of file join.cc.
References drizzled::Join::tables.
Referenced by drizzled::choose_plan().
int drizzled::do_select | ( | Join * | join, |
List< Item > * | fields, | ||
Table * | table | ||
) |
Make a join of all tables and write it on socket or to table.
0 | if ok |
1 | if error is sent |
-1 | if error should be sent |
Definition at line 3206 of file sql_select.cc.
References drizzled::Table::cursor, drizzled::Session::is_error(), drizzled::Join::join_free(), drizzled::setup_end_select_func(), drizzled::sub_select(), drizzled::Join::tables, and drizzled::Item::val_int().
Referenced by drizzled::Join::exec().
|
static |
Generate minimal set of simple equalities equivalent to a multiple equality.
The function retrieves the fields of the multiple equality item item_equal and for each field f:
cond | condition to add the generated equality to |
upper_levels | structure to access multiple equality of upper levels |
item_equal | multiple equality to generate simple equality from |
Definition at line 2238 of file sql_select.cc.
References drizzled::Item_field::find_item_equal(), drizzled::Item::quick_fix_field(), and drizzled::Item_equal::val_int().
Referenced by drizzled::substitute_for_best_equal_field().
enum_nested_loop_state drizzled::end_unique_update | ( | Join * | join, |
JoinTable * | , | ||
bool | end_of_records | ||
) |
Like end_update, but this is done with unique constraints instead of keys.
Definition at line 3063 of file join.cc.
References drizzled::copy_fields(), drizzled::copy_funcs(), drizzled::Table::cursor, drizzled::Table::get_dup_key(), and drizzled::update_tmptable_sum_func().
Referenced by drizzled::setup_end_select_func().
enum_nested_loop_state drizzled::end_update | ( | Join * | join, |
JoinTable * | , | ||
bool | end_of_records | ||
) |
Group by searching after group record and updating it if possible.
Definition at line 2996 of file join.cc.
References drizzled::copy_fields(), drizzled::copy_funcs(), drizzled::Table::cursor, drizzled::Cursor::index_read_map(), drizzled::Table::key_info, drizzled::Item::maybe_null, and drizzled::update_tmptable_sum_func().
Referenced by drizzled::setup_end_select_func().
bool drizzled::eq_ref_table | ( | Join * | join, |
Order * | start_order, | ||
JoinTable * | tab | ||
) |
Add to join_tab->select_cond[i] "table.field IS NOT NULL" conditions we've inferred from ref/eq_ref access performed.
This function is a part of "Early NULL-values filtering for ref access" optimization.
Example of this optimization: For query SELECT * FROM t1,t2 WHERE t2.key=t1.field
and plan " any-access(t1), ref(t2.key=t1.field) "
add "t1.field IS NOT NULL" to t1's table condition.
Description of the optimization:
We look through equalities choosen to perform ref/eq_ref access, pick equalities that have form "tbl.part_of_key = othertbl.field" (where othertbl is a non-const table and othertbl.field may be NULL) and add them to conditions on correspoding tables (othertbl in this example).
Exception from that is the case when referred_tab->join != join. I.e. don't add NOT NULL constraints from any embedded subquery. Consider this query:
These can't be optimized:
Definition at line 1337 of file sql_select.cc.
References drizzled::JoinTable::first_inner, drizzled::table_reference_st::items, drizzled::table_reference_st::key_parts, drizzled::Table::map, and drizzled::JoinTable::type.
enum_nested_loop_state drizzled::evaluate_join_record | ( | Join * | join, |
JoinTable * | join_tab, | ||
int | error | ||
) |
Process one record of the nested loop join.
This function will evaluate parts of WHERE/ON clauses that are applicable to the partial record on hand and in case of success submit this record to the next level of the nested loop.
Definition at line 2606 of file join.cc.
References drizzled::JoinTable::first_unmatched, drizzled::JoinTable::first_upper, drizzled::JoinTable::found, drizzled::JoinTable::found_match, drizzled::Session::is_error(), drizzled::JoinTable::last_inner, drizzled::Join::return_tab, drizzled::Session::row_count, and drizzled::Item::val_int().
Referenced by drizzled::sub_select().
enum_nested_loop_state drizzled::evaluate_null_complemented_join_record | ( | Join * | join, |
JoinTable * | join_tab | ||
) |
Construct a NULL complimented partial join record and feed it to the next level of the nested loop. This function is used in case we have an OUTER join and no matching record was found.
Definition at line 2730 of file join.cc.
References drizzled::JoinTable::first_unmatched, drizzled::JoinTable::first_upper, drizzled::JoinTable::found, drizzled::JoinTable::last_inner, drizzled::JoinTable::not_null_compl, drizzled::Join::return_tab, and drizzled::Item::val_int().
Referenced by drizzled::sub_select().
void drizzled::Join::exec | ( | ) |
Exec select.
Definition at line 1372 of file join.cc.
References drizzled::Join::all_fields, drizzled::Join::alloc_func_list(), drizzled::calc_group_buffer(), drizzled::change_refs_to_tmp_fields(), drizzled::change_to_use_tmp_fields(), drizzled::optimizer::SqlSelect::cond, drizzled::count_field_types(), drizzled::create_tmp_table(), drizzled::Table::cursor, drizzled::do_select(), drizzled::Session::examined_row_count, drizzled::Join::exec_tmp_table1, drizzled::Join::fields_list, drizzled::JoinTable::first_inner, drizzled::Join::group_list, drizzled::Session::is_error(), drizzled::Session::is_fatal_error, drizzled::Join::items0, drizzled::Join::join_free(), drizzled::JoinTable::keyuse, drizzled::Session::limit_found_rows, drizzled::make_group_fields(), drizzled::Join::make_sum_func_list(), drizzled::Table::map, drizzled::Join::no_order, drizzled::Item::quick_fix_field(), drizzled::Join::ref_pointer_array, drizzled::Join::select_distinct, drizzled::Join::select_lex, drizzled::Session::sent_row_count, drizzled::Session::set_proc_info(), drizzled::setup_copy_fields(), drizzled::setup_sum_funcs(), drizzled::Join::skip_sort_order, drizzled::JoinTable::sorted, drizzled::Join::sum_funcs2, drizzled::Join::tables, drizzled::Join::tables_list, drizzled::test_if_skip_sort_order(), drizzled::test_if_subpart(), drizzled::Join::tmp_all_fields1, drizzled::Join::tmp_fields_list1, drizzled::Join::tmp_having, drizzled::Join::tmp_join, drizzled::Item::top_level_item(), drizzled::Join::unit, drizzled::Item::val_int(), and drizzled::Join::zero_result_cause.
Referenced by drizzled::subselect_hash_sj_engine::exec(), and drizzled::select_query().
bool drizzled::find_field_in_item_list | ( | Field * | field, |
void * | data | ||
) |
Helper function for list_contains_unique_index. Find a field reference in a dynamic list of Items. Finds a direct reference of the Field in the list.
[in] | field | The field to search for. |
[in] | data | List<Item> *.The list to search in |
1 | found |
0 | not found. |
Definition at line 4794 of file sql_select.cc.
Referenced by drizzled::Join::optimize().
bool drizzled::find_field_in_order_list | ( | Field * | field, |
void * | data | ||
) |
Helper function for list_contains_unique_index. Find a field reference in a list of order_st structures. Finds a direct reference of the Field in the list.
field | The field to search for. |
data | order_st *.The list to search in |
1 | found |
0 | not found. |
Definition at line 4764 of file sql_select.cc.
Referenced by drizzled::Join::optimize().
|
static |
Find the multiple equality predicate containing a field.
The function retrieves the multiple equalities accessed through the con_equal structure from current level and up looking for an equality containing field. It stops retrieval as soon as the equality is found and set up inherited_fl to true if it's found on upper levels.
cond_equal | multiple equalities to search in | |
field | field to look for | |
[out] | inherited_fl | set up to true if multiple equality is found on upper levels (not on current level of cond_equal) |
Definition at line 1419 of file sql_select.cc.
References drizzled::Item_equal::contains().
Referenced by drizzled::check_simple_equality().
|
static |
Resolve an ORDER BY or GROUP BY column reference.
Given a column reference (represented by 'order') from a GROUP BY or order_st BY clause, find the actual column it represents. If the column being resolved is from the GROUP BY clause, the procedure searches the SELECT list 'fields' and the columns in the FROM list 'tables'. If 'order' is from the ORDER BY clause, only the SELECT list is being searched.
If 'order' is resolved to an Item, then order->item is set to the found Item. If there is no item for the found column (that is, it was resolved into a table field), order->item is 'fixed' and is added to all_fields and ref_pointer_array.
ref_pointer_array and all_fields are updated.
[in] | session | Pointer to current thread structure |
[in,out] | ref_pointer_array | All select, group and order by fields |
[in] | tables | List of tables to search in (usually FROM clause) |
[in] | order | Column reference to be resolved |
[in] | fields | List of fields to search in (usually SELECT list) |
[in,out] | all_fields | All select, group and order by fields |
[in] | is_group_field | True if order is a GROUP field, false if order_st by field |
false | if OK |
true | if error occurred |
Definition at line 5766 of file sql_select.cc.
References drizzled::Item::basic_const_item(), drizzled::Item::fixed, drizzled::Session::is_fatal_error, and drizzled::Item::val_int().
Referenced by drizzled::setup_group(), and drizzled::setup_order().
void drizzled::free_underlaid_joins | ( | Session * | , |
Select_Lex * | select | ||
) |
Free joins of subselect of this select.
session | Session pointer |
select | pointer to Select_Lex which subselects joins we will free |
Definition at line 6655 of file sql_select.cc.
Referenced by drizzled::delete_query(), drizzled::insert_query(), drizzled::sql_set_variables(), and drizzled::update_query().
|
static |
Set up join struct according to best position.
Definition at line 3344 of file join.cc.
References drizzled::Join::getPosFromOptimalPlan(), drizzled::table_reference_st::key, drizzled::table_reference_st::key_parts, drizzled::JoinTable::keys, drizzled::Table::map, drizzled::Join::map2table, drizzled::JoinTable::on_expr_ref, drizzled::Join::tables, drizzled::JoinTable::type, and drizzled::update_depend_map().
Referenced by drizzled::make_join_statistics().
|
static |
Return table number if there is only one table in sort order and group and order is compatible, else return 0.
Definition at line 6048 of file join.cc.
References drizzled::Table::map, drizzled::TableList::next_leaf, drizzled::TableList::table, and drizzled::Item::used_tables().
Referenced by drizzled::Join::optimize().
|
static |
Find a good, possibly optimal, query execution plan (QEP) by a greedy search.
The search procedure uses a hybrid greedy/exhaustive search with controlled exhaustiveness. The search is performed in N = card(remaining_tables) steps. Each step evaluates how promising is each of the unoptimized tables, selects the most promising table, and extends the current partial QEP with that table. Currenly the most 'promising' table is the one with least expensive extension.\
There are two extreme cases:
All other cases are in-between these two extremes. Thus the parameter 'search_depth' controlls the exhaustiveness of the search. The higher the value, the longer the optimizaton time and possibly the better the resulting plan. The lower the value, the fewer alternative plans are estimated, but the more likely to get a bad QEP.
All intermediate and final results of the procedure are stored in 'join':
The final optimal plan is stored in 'join->best_positions', and its corresponding cost in 'join->best_read'.
where 'best_extension' is a placeholder for a procedure that selects the most "promising" of all tables in 'remaining_tables'. Currently this estimate is performed by calling 'best_extension_by_limited_search' to evaluate all extensions of the current QEP of size 'search_depth', thus the complexity of 'greedy_search' mainly depends on that of 'best_extension_by_limited_search'.
join | pointer to the structure providing all context info for the query |
remaining_tables | set of tables not included into the partial plan yet |
search_depth | controlls the exhaustiveness of the search |
prune_level | the pruning heuristics that should be applied during search |
false | ok |
true | Fatal error |
Definition at line 4143 of file join.cc.
References drizzled::best_extension_by_limited_search(), drizzled::Join::best_read, drizzled::check_interleaving_with_nj(), drizzled::Join::getPosFromOptimalPlan(), drizzled::Join::getPosFromPartialPlan(), drizzled::Table::map, and drizzled::Join::setPosInPartialPlan().
Referenced by drizzled::choose_plan().
bool drizzled::handle_select | ( | Session * | session, |
LEX * | lex, | ||
select_result * | result, | ||
uint64_t | setup_tables_done_option | ||
) |
This handles SELECT with and without UNION.
Definition at line 118 of file sql_select.cc.
References drizzled::Session::is_error(), drizzled::Session::limit_found_rows, drizzled::Session::options, drizzled::select_query(), and drizzled::Session::session_marker.
Referenced by drizzled::statement::InsertSelect::execute(), and drizzled::statement::ReplaceSelect::execute().
void drizzled::Join::init_save_join_tab | ( | ) |
Save the original join layout.
Saves the original join layout so it can be reused in re-execution and for EXPLAIN.
0 | success. |
1 | error occurred. |
Definition at line 1345 of file join.cc.
References drizzled::memory::Root::alloc(), drizzled::Join::restore_tmp(), and drizzled::Join::tmp_join.
Referenced by drizzled::Join::optimize().
|
inline |
Test if a second key is the subkey of the first one.
key_part | First key parts |
ref_key_part | Second key parts |
ref_key_part_end | Last+1 part of the second key |
1 | is a subkey |
0 | no sub key |
Definition at line 4634 of file sql_select.cc.
Referenced by drizzled::test_if_subkey().
drizzled::Join::Join | ( | Session * | session_arg, |
List< Item > & | fields_arg, | ||
uint64_t | select_options_arg, | ||
select_result * | result_arg | ||
) |
Constructors
Definition at line 143 of file join.cc.
References drizzled::Join::fields_list, drizzled::Join::rollup, and drizzled::Join::select_distinct.
void drizzled::Join::join_free | ( | ) |
Release memory and, if possible, the open tables held by this execution plan (and nested plans). It's used to release some tables before the end of execution in order to increase concurrency and reduce memory consumption.
Partially cleanup Join after it has executed: close index or rnd read (table cursors), free quick selects.
This function is called in the end of execution of a Join, before the used tables are unlocked and closed.
For a join that is resolved using a temporary table, the first sweep is performed against actual tables and an intermediate result is inserted into the temprorary table. The last sweep is performed against the temporary table. Therefore, the base tables and associated buffers used to fill the temporary table are no longer needed, and this function is called to free them.
For a join that is performed without a temporary table, this function is called after all rows are sent, but before EOF packet is sent.
For a simple SELECT with no subqueries this function performs a full cleanup of the Join and calls unlockReadTables to free used base tables.
If a Join is executed for a subquery or if it has a subquery, we can't do the full cleanup and need to do a partial cleanup only.
Definition at line 1967 of file join.cc.
References drizzled::Join::cleanup(), drizzled::Join::select_lex, and drizzled::Session::unlockReadTables().
Referenced by drizzled::do_select(), and drizzled::Join::exec().
int drizzled::join_read_always_key_or_null | ( | JoinTable * | tab | ) |
Reading of key with key reference and one part that may be NULL.
Definition at line 4021 of file sql_select.cc.
References drizzled::table_reference_st::null_ref_key.
Referenced by drizzled::optimizer::Index::getStats().
int drizzled::join_read_const | ( | JoinTable * | tab | ) |
Read a (constant) table when there is at most one matching row.
tab | Table to read |
0 | Row was found |
-1 | Row was not found |
1 | Got an error (other than row not found) during read |
Definition at line 3579 of file sql_select.cc.
References drizzled::Table::cursor, drizzled::Cursor::index_read_idx_map(), drizzled::table_reference_st::key, drizzled::table_reference_st::key_buff, drizzled::table_reference_st::key_parts, and drizzled::Table::report_error().
Referenced by drizzled::optimizer::Const::getStats().
int drizzled::join_read_last_key | ( | JoinTable * | tab | ) |
This function is used when optimizing away ORDER BY in SELECT * FROM t1 WHERE a=1 ORDER BY a DESC,b DESC.
Definition at line 3737 of file sql_select.cc.
References drizzled::Table::cursor, drizzled::Cursor::index_read_last_map(), drizzled::table_reference_st::key, drizzled::table_reference_st::key_buff, drizzled::table_reference_st::key_parts, drizzled::Table::report_error(), and drizzled::JoinTable::sorted.
Referenced by drizzled::test_if_skip_sort_order().
int drizzled::join_tab_cmp | ( | const void * | ptr1, |
const void * | ptr2 | ||
) |
Compare two JoinTable objects based on the number of accessed records.
NOTES The order relation implemented by join_tab_cmp() is not transitive, i.e. it is possible to choose such a, b and c that (a < b) && (b < c) but (c < a). This implies that result of a sort using the relation implemented by join_tab_cmp() depends on the order in which elements are compared, i.e. the result is implementation-specific. Example: a: dependent = 0x0 table->map = 0x1 found_records = 3 ptr = 0x907e6b0 b: dependent = 0x0 table->map = 0x2 found_records = 3 ptr = 0x907e838 c: dependent = 0x6 table->map = 0x10 found_records = 2 ptr = 0x907ecd0
1 | if first is bigger |
-1 | if second is bigger |
0 | if equal |
Definition at line 843 of file sql_select.cc.
References drizzled::JoinTable::found_records, and drizzled::Table::map.
Referenced by drizzled::choose_plan().
int drizzled::join_tab_cmp_straight | ( | const void * | ptr1, |
const void * | ptr2 | ||
) |
Same as join_tab_cmp, but for use with SELECT_STRAIGHT_JOIN.
Definition at line 866 of file sql_select.cc.
References drizzled::Table::map.
Referenced by drizzled::choose_plan().
bool drizzled::list_contains_unique_index | ( | Table * | table, |
bool(*)(Field *, void *) | find_func, | ||
void * | data | ||
) |
Check if GROUP BY/DISTINCT can be optimized away because the set is already known to be distinct.
Used in removing the GROUP BY/DISTINCT of the following types of statements:
If (a,b,c is distinct) then <any combination of a,b,c>,{whatever} is also distinct
This function checks if all the key parts of any of the unique keys of the table are referenced by a list : either the select list through find_field_in_item_list or GROUP BY list through find_field_in_order_list. If the above holds and the key parts cannot contain NULLs then we can safely remove the GROUP BY/DISTINCT, as no result set can be more distinct than an unique key.
table | The table to operate on. |
find_func | function to iterate over the list and search for a field |
1 | found |
0 | not found. |
Definition at line 4720 of file sql_select.cc.
References drizzled::Table::key_info.
Referenced by drizzled::Join::optimize().
|
static |
Declarations of static functions used in this source file.
allocate group fields or take prepared (cached).
main_join | join of current select |
curr_join | current join (join of current select or temporary copy of it) |
0 | ok |
1 | failed |
Definition at line 3119 of file join.cc.
References drizzled::alloc_group_fields(), and drizzled::Join::group_list.
Referenced by drizzled::Join::exec().
|
static |
Calculate the best possible join and initialize the join structure.
0 | ok |
1 | Fatal error |
Definition at line 5558 of file join.cc.
References drizzled::add_group_and_distinct_keys(), drizzled::Join::best_read, drizzled::JoinTable::checked_keys, drizzled::choose_plan(), drizzled::JoinTable::const_keys, drizzled::Join::copyPartialPlanIntoOptimalPlan(), drizzled::Table::cursor, drizzled::JoinTable::embedding_map, drizzled::JoinTable::found_records, drizzled::get_best_combination(), drizzled::Join::getFirstPosInPartialPlan(), drizzled::Join::getSpecificPosInPartialPlan(), drizzled::Item::is_null(), drizzled::Table::key_info, drizzled::Field::key_start, drizzled::JoinTable::keys, drizzled::JoinTable::keyuse, drizzled::Table::map, drizzled::Join::map2table, drizzled::optimizer::SqlSelect::needed_reg, drizzled::TableList::next_leaf, drizzled::Join::no_const_tables, drizzled::JoinTable::on_expr_ref, drizzled::optimize_keyuse(), drizzled::optimizer::SqlSelect::quick, drizzled::Table::quick_condition_rows, drizzled::optimizer::QuickSelectInterface::read_time, drizzled::JoinTable::read_time, drizzled::JoinTable::records, drizzled::Join::select_lex, drizzled::set_position(), drizzled::Join::tables, drizzled::JoinTable::type, drizzled::update_ref_and_keys(), and drizzled::Item::used_tables().
Referenced by drizzled::Join::optimize().
|
static |
Fill in outer join related info for the execution plan structure.
For each outer join operation left after simplification of the original query the function set up the following pointers in the linear structure join->join_tab representing the selected execution plan. The first inner table t0 for the operation is set to refer to the last inner table tk through the field t0->last_inner. Any inner table ti for the operation are set to refer to the first inner table ti->first_inner. The first inner table t0 for the operation is set to refer to the first inner table of the embedding outer join operation, if there is any, through the field t0->first_upper. The on expression for the outer join operation is attached to the corresponding first inner table through the field t0->on_expr_ref. Here ti are structures of the JoinTable type.
EXAMPLE. For the query:
given the execution plan with the table order t1,t2,t3,t4 is selected, the following references will be set; t4->last_inner=[t4], t4->first_inner=[t4], t4->first_upper=[t2] t2->last_inner=[t4], t2->first_inner=t3->first_inner=[t2], on expression (t1.a=t2.a AND t1.b=t3.b) will be attached to *t2->on_expr_ref, while t3.a=t4.a will be attached to *t4->on_expr_ref.
join | reference to the info fully describing the query |
Definition at line 4593 of file join.cc.
References drizzled::JoinTable::cond_equal, drizzled::TableList::cond_equal, drizzled::JoinTable::first_inner, drizzled::JoinTable::first_upper, drizzled::JoinTable::last_inner, drizzled::TableList::on_expr, drizzled::JoinTable::on_expr_ref, and drizzled::TableList::outer_join.
Referenced by drizzled::Join::optimize().
bool drizzled::Join::make_sum_func_list | ( | List< Item > & | field_list, |
List< Item > & | send_fields, | ||
bool | before_group_by, | ||
bool | recompute = false |
||
) |
Initialize 'sum_funcs' array with all Item_sum objects.
field_list | All items |
send_fields | Items in select list |
before_group_by | Set to 1 if this is called before GROUP BY handling |
recompute | Set to true if sum_funcs must be recomputed |
0 | ok |
1 | error |
Definition at line 2180 of file join.cc.
References drizzled::Item::const_item(), drizzled::Join::rollup, drizzled::Join::rollup_make_fields(), and drizzled::Join::select_lex.
Referenced by drizzled::Join::exec(), and drizzled::Join::optimize().
uint32_t drizzled::max_part_bit | ( | key_part_map | bits | ) |
Add all keys with uses 'field' for some keypart.
If field->and_level != and_level then only mark key_part as const_part.
Definition at line 515 of file sql_select.cc.
Referenced by drizzled::best_access_path().
int drizzled::Join::optimize | ( | ) |
global select optimisation.
0 | success |
1 | error |
Definition at line 609 of file join.cc.
References drizzled::add_ref_to_table_cond(), drizzled::Join::all_fields, drizzled::alloc_group_fields(), drizzled::Join::best_read, drizzled::build_bitmap_for_nested_joins(), drizzled::Join::cache_const_exprs(), drizzled::calc_group_buffer(), drizzled::count_field_types(), drizzled::create_distinct_group(), drizzled::create_tmp_table(), drizzled::Join::exec_tmp_table1, drizzled::Join::fields_list, drizzled::find_field_in_item_list(), drizzled::find_field_in_order_list(), drizzled::get_sort_by_table(), drizzled::optimizer::QuickSelectInterface::get_type(), drizzled::Join::group_list, drizzled::Join::group_optimized_away, drizzled::in_left_expr_name, drizzled::Join::init_save_join_tab(), drizzled::Session::is_error(), drizzled::Item::is_expensive(), drizzled::Session::is_fatal_error, drizzled::Join::join_list, drizzled::list_contains_unique_index(), drizzled::make_join_statistics(), drizzled::make_outerjoin_info(), drizzled::Join::make_sum_func_list(), drizzled::Table::map, drizzled::Join::map2table, drizzled::Item::name, drizzled::Join::no_order, drizzled::Join::optimized, drizzled::Session::options, drizzled::optimizer::SqlSelect::quick, drizzled::remove_additional_cond(), drizzled::remove_constants(), drizzled::reset_nj_counters(), drizzled::Join::rollup, drizzled::Join::select, drizzled::Join::select_distinct, drizzled::Join::select_lex, drizzled::Session::set_proc_info(), drizzled::Join::setup_subquery_materialization(), drizzled::setup_sum_funcs(), drizzled::simplify_joins(), drizzled::Join::skip_sort_order, drizzled::Join::sort_by_table, drizzled::substitute_for_best_equal_field(), drizzled::Join::tables, drizzled::Join::tables_list, drizzled::test_if_skip_sort_order(), drizzled::test_if_subpart(), drizzled::Join::tmp_having, drizzled::Item::top_level_item(), drizzled::JoinTable::type, drizzled::Join::unit, drizzled::Session::unlockSomeTables(), drizzled::Session::used_tables, drizzled::Item::used_tables(), drizzled::Session::variables, and drizzled::Join::zero_result_cause.
Referenced by drizzled::subselect_hash_sj_engine::exec(), and drizzled::select_query().
void drizzled::optimize_keyuse | ( | Join * | join, |
DYNAMIC_ARRAY * | keyuse_array | ||
) |
Update some values in keyuse for faster choose_plan() loop.
Definition at line 716 of file sql_select.cc.
References drizzled::Table::cursor.
Referenced by drizzled::make_join_statistics().
|
static |
Select the best ways to access the tables in a query without reordering them.
Find the best access paths for each query table and compute their costs according to their order in the array 'join->best_ref' (thus without reordering the join tables). The function calls sequentially 'best_access_path' for each table in the query to select the best table access method. The final optimal plan is stored in the array 'join->best_positions', and the corresponding cost in 'join->best_read'.
join | pointer to the structure providing all context info for the query |
join_tables | set of the tables in the query |
Definition at line 4033 of file join.cc.
References drizzled::best_access_path(), drizzled::Join::best_read, drizzled::Join::copyPartialPlanIntoOptimalPlan(), drizzled::Join::getPosFromPartialPlan(), drizzled::optimizer::Position::hasTableForSorting(), drizzled::Table::map, drizzled::Join::sort_by_table, and TIME_FOR_COMPARE.
Referenced by drizzled::choose_plan().
int drizzled::Join::prepare | ( | Item *** | rref_pointer_array, |
TableList * | tables_init, | ||
uint32_t | wild_num, | ||
COND * | conds_init, | ||
uint32_t | og_num, | ||
Order * | order_init, | ||
Order * | group_init, | ||
Item * | having_init, | ||
Select_Lex * | select_lex_arg, | ||
Select_Lex_Unit * | unit_arg | ||
) |
Prepare of whole select (including sub queries in future).
-1 | on error |
0 | on success |
Definition at line 332 of file join.cc.
References drizzled::Join::all_fields, drizzled::Join::alloc_func_list(), drizzled::count_field_types(), drizzled::Session::derived_tables_processing, drizzled::Join::fields_list, drizzled::Item::fixed, drizzled::Join::group_list, drizzled::Session::is_error(), drizzled::Join::join_list, drizzled::TableList::next_leaf, drizzled::Join::optimized, drizzled::Join::ref_pointer_array, drizzled::Join::ref_pointer_array_size, drizzled::Join::rollup_init(), drizzled::Join::select_lex, drizzled::setup_without_group(), drizzled::Join::tables, drizzled::Join::tables_list, drizzled::Join::union_part, and drizzled::Join::unit.
Referenced by drizzled::select_query().
void drizzled::print_join | ( | Session * | session, |
String * | str, | ||
List< TableList > * | tables | ||
) |
Print joins from the FROM clause.
session | thread Cursor |
str | string where table should be printed |
tables | list of tables in join |
Definition at line 6787 of file sql_select.cc.
Referenced by drizzled::TableList::print().
Item * drizzled::remove_additional_cond | ( | Item * | conds | ) |
Remove additional condition inserted by IN/ALL/ANY transformation.
conds | condition for processing |
Definition at line 2584 of file sql_select.cc.
References drizzled::in_additional_cond, and drizzled::Item::name.
Referenced by drizzled::Join::optimize().
|
static |
Remove all constants and check if order_st only contains simple expressions.
simple_order is set to 1 if sort_order only uses fields from head table and the head table is not a LEFT JOIN table.
join | Join handler |
first_order | List of SORT or GROUP order |
cond | WHERE statement |
change_list | Set to 1 if we should remove things from list. If this is not set, then only simple_order is calculated. |
simple_order | Set to 1 if we are only using simple expressions |
Definition at line 5114 of file join.cc.
References drizzled::const_expression_in_where(), drizzled::Table::map, drizzled::JoinTable::on_expr_ref, drizzled::Item::str_value, drizzled::Join::tables, drizzled::update_depend_map(), drizzled::Item::used_tables(), drizzled::Item::val_str(), and drizzled::Item::with_subselect.
Referenced by drizzled::Join::optimize().
int drizzled::remove_dup_with_hash_index | ( | Session * | session, |
Table * | table, | ||
uint32_t | field_count, | ||
Field ** | first_field, | ||
uint32_t | key_length, | ||
Item * | having | ||
) |
Generate a hash index for each row to quickly find duplicate rows.
Definition at line 5524 of file sql_select.cc.
References drizzled::Table::cursor, and drizzled::Item::val_int().
COND * drizzled::remove_eq_conds | ( | Session * | session, |
COND * | cond, | ||
Item::cond_result * | cond_value | ||
) |
Remove const and eq items.
Definition at line 2851 of file sql_select.cc.
References drizzled::Item::eq(), drizzled::Session::first_successful_insert_id_in_prev_stmt, drizzled::Item::maybe_null, drizzled::Session::options, drizzled::Session::substitute_null_with_insert_id, and drizzled::Field::table.
Referenced by drizzled::delete_query(), and drizzled::update_query().
void drizzled::Join::reset | ( | Session * | session_arg, |
List< Item > & | fields_arg, | ||
uint64_t | select_options_arg, | ||
select_result * | result_arg | ||
) |
This method is currently only used when a subselect EXPLAIN is performed. I pulled out the init() method and have simply reset the values to what was previously in the init() method. See the note about the hack in sql_union.cc...
Definition at line 232 of file join.cc.
References drizzled::Join::all_fields, drizzled::Join::exec_tmp_table1, drizzled::Join::fetch_limit, drizzled::Join::fields_list, drizzled::Join::group_optimized_away, drizzled::Join::having_history, drizzled::Join::items0, drizzled::Join::join_list, drizzled::Join::join_tab_save, drizzled::Join::map2table, drizzled::Join::no_const_tables, drizzled::Join::no_order, drizzled::Join::optimized, drizzled::Join::outer_tables, drizzled::Join::ref_pointer_array, drizzled::Join::ref_pointer_array_size, drizzled::Join::resume_nested_loop, drizzled::Join::return_tab, drizzled::Join::rollup, drizzled::Join::select, drizzled::Join::select_distinct, drizzled::Join::select_lex, drizzled::Join::skip_sort_order, drizzled::Join::sort_by_table, drizzled::Join::sum_funcs2, drizzled::Join::tables, drizzled::Join::tmp_having, drizzled::Join::tmp_join, drizzled::Join::union_part, drizzled::Join::unit, and drizzled::Join::zero_result_cause.
|
static |
Set NestedJoin::counter=0 in all nested joins in passed list.
Recursively set NestedJoin::counter=0 for all nested joins contained in the passed join_list.
join_list | List of nested joins to process. It may also contain base tables which will be ignored. |
Definition at line 6081 of file join.cc.
Referenced by drizzled::choose_plan(), and drizzled::Join::optimize().
|
static |
Nested joins perspective: Remove the last table from the join order.
The algorithm is the reciprocal of check_interleaving_with_nj(), hence parent join nest nodes are updated only when the last table in its child node is removed. The ASCII graphic below will clarify.
A table nesting such as t1 x [ ( t2 x t3 ) x ( t4 x t5 ) ]
is represented by the below join nest tree.
NJ1 _/ / \ _/ / NJ2 _/ / / \ / / / \ t1 x [ (t2 x t3) x (t4 x t5) ]
At the point in time when check_interleaving_with_nj() adds the table t5 to the query execution plan, QEP, it also directs the node named NJ2 to mark the table as covered. NJ2 does so by incrementing its counter
member. Since all of NJ2's tables are now covered by the QEP, the algorithm proceeds up the tree to NJ1, incrementing its counter as well. All join nests are now completely covered by the QEP.
restore_prev_nj_state() does the above in reverse. As seen above, the node NJ1 contains the nodes t2, t3, and NJ2. Its counter being equal to 3 means that the plan covers t2, t3, and NJ2, and that the sub-plan (t4 x t5) completely covers NJ2. The removal of t5 from the partial plan will first decrement NJ2's counter to 1. It will then detect that NJ2 went from being completely to partially covered, and hence the algorithm must continue upwards to NJ1 and decrement its counter to 2. A subsequent removal of t4 will however not influence NJ1 since it did not un-cover the last table in NJ2.
SYNOPSIS restore_prev_nj_state() last join table to remove, it is assumed to be the last in current partial join order.
DESCRIPTION
Remove the last table from the partial join order and update the nested joins counters and join->cur_embedding_map. It is ok to call this function for the first table in join order (for which check_interleaving_with_nj has not been called)
last | join table to remove, it is assumed to be the last in current partial join order. |
Definition at line 6165 of file join.cc.
References drizzled::Join::cur_embedding_map.
Referenced by drizzled::best_extension_by_limited_search().
void drizzled::Join::restore_tmp | ( | ) |
Restore values in temporary join.
Definition at line 1288 of file join.cc.
References drizzled::Join::tmp_join.
Referenced by drizzled::Join::init_save_join_tab().
bool drizzled::Join::rollup_init | ( | ) |
Allocate memory needed for other rollup functions.
Definition at line 2218 of file join.cc.
References drizzled::Join::all_fields, drizzled::memory::Root::alloc(), drizzled::change_group_ref(), drizzled::Join::fields_list, drizzled::Join::group_list, drizzled::Join::ref_pointer_array_size, and drizzled::Join::rollup.
Referenced by drizzled::Join::prepare().
bool drizzled::Join::rollup_make_fields | ( | List< Item > & | fields_arg, |
List< Item > & | sel_fields, | ||
Item_sum *** | func | ||
) |
Fill up rollup structures with pointers to fields to use.
Creates copies of item_sum items for each sum level.
fields_arg | List of all fields (hidden and real ones) |
sel_fields | Pointer to selected fields |
func | Store here a pointer to all fields |
0 | if ok; In this case func is pointing to next not used element. |
1 | on error |
Definition at line 2326 of file join.cc.
References drizzled::Item::const_item(), drizzled::Join::group_list, drizzled::Item::maybe_null, drizzled::Join::rollup, and drizzled::Join::select_lex.
Referenced by drizzled::Join::make_sum_func_list().
int drizzled::Join::rollup_send_data | ( | uint32_t | idx | ) |
Send all rollup levels higher than the current one to the client.
SAMPLE
idx | Level we are on:
|
0 | ok |
1 | If send_data_failed() |
Definition at line 2454 of file join.cc.
References drizzled::Join::ref_pointer_array, drizzled::Join::ref_pointer_array_size, drizzled::Join::rollup, and drizzled::Item::val_int().
int drizzled::Join::rollup_write_data | ( | uint32_t | idx, |
Table * | table_arg | ||
) |
Write all rollup levels higher than the current one to a temp table.
SAMPLE
idx | Level we are on:
|
table | reference to temp table |
0 | ok |
1 | if write_data_failed() |
Definition at line 2495 of file join.cc.
References drizzled::copy_sum_funcs(), drizzled::Table::cursor, drizzled::Join::ref_pointer_array, drizzled::Join::ref_pointer_array_size, drizzled::Join::rollup, and drizzled::Item::val_int().
bool drizzled::select_query | ( | Session * | session, |
Item *** | rref_pointer_array, | ||
TableList * | tables, | ||
uint32_t | wild_num, | ||
List< Item > & | fields, | ||
COND * | conds, | ||
uint32_t | og_num, | ||
Order * | order, | ||
Order * | group, | ||
Item * | having, | ||
uint64_t | select_options, | ||
select_result * | result, | ||
Select_Lex_Unit * | unit, | ||
Select_Lex * | select_lex | ||
) |
An entry point to single-unit select (a select without UNION).
session | thread Cursor |
rref_pointer_array | a reference to ref_pointer_array of the top-level select_lex for this query |
tables | list of all tables used in this query. The tables have been pre-opened. |
wild_num | number of wildcards used in the top level select of this query. For example statement SELECT *, t1.*, catalog.t2.* FROM t0, t1, t2; has 3 wildcards. |
fields | list of items in SELECT list of the top-level select e.g. SELECT a, b, c FROM t1 will have Item_field for a, b and c in this list. |
conds | top level item of an expression representing WHERE clause of the top level select |
og_num | total number of ORDER BY and GROUP BY clauses arguments |
order | linked list of ORDER BY agruments |
group | linked list of GROUP BY arguments |
having | top level item of HAVING expression |
select_options | select options (BIG_RESULT, etc) |
result | an instance of result set handling class. This object is responsible for send result set rows to the client or inserting them into a table. |
select_lex | the only Select_Lex of this query |
unit | top-level UNIT of this query UNIT is an artificial object created by the parser for every SELECT clause. e.g. SELECT * FROM t1 WHERE a1 IN (SELECT * FROM t2) has 2 unions. |
false | success |
true | an error |
Definition at line 368 of file sql_select.cc.
References drizzled::Join::change_result(), drizzled::Join::conds_history, drizzled::Join::exec(), drizzled::Join::having_history, drizzled::Session::is_error(), drizzled::Join::optimize(), drizzled::Join::prepare(), drizzled::Session::set_proc_info(), drizzled::Join::tmp_having, and drizzled::Session::used_tables.
Referenced by drizzled::handle_select().
|
static |
Save const tables first as used tables.
Definition at line 3394 of file join.cc.
References drizzled::Join::setPosInPartialPlan().
Referenced by drizzled::make_join_statistics().
bool drizzled::setup_copy_fields | ( | Session * | session, |
Tmp_Table_Param * | param, | ||
Item ** | ref_pointer_array, | ||
List< Item > & | res_selected_fields, | ||
List< Item > & | res_all_fields, | ||
uint32_t | elements, | ||
List< Item > & | all_fields | ||
) |
Setup copy_fields to save fields at start of new group.
Setup copy_fields to save fields at start of new group
Only FIELD_ITEM:s and FUNC_ITEM:s needs to be saved between groups. Change old item_field to use a new field with points at saved fieldvalue This function is only called before use of send_fields.
session | Session pointer |
param | temporary table parameters |
ref_pointer_array | array of pointers to top elements of filed list |
res_selected_fields | new list of items of select item list |
res_all_fields | new list of all items |
elements | number of elements in select item list |
all_fields | all fields list |
0 | ok |
!=0 | error |
Definition at line 6245 of file sql_select.cc.
References drizzled::Session::mem_root, drizzled::Item::name, and drizzled::Field::pack_length().
Referenced by drizzled::Join::exec().
Next_select_func drizzled::setup_end_select_func | ( | Join * | join | ) |
Rows produced by a join sweep may end up in a temporary table or be sent to a client. Setup the function of the nested loop join algorithm which handles final fully constructed and matched records.
join | join to setup the function for. |
Definition at line 3137 of file sql_select.cc.
References drizzled::end_unique_update(), and drizzled::end_update().
Referenced by drizzled::do_select().
int drizzled::setup_group | ( | Session * | session, |
Item ** | ref_pointer_array, | ||
TableList * | tables, | ||
List< Item > & | fields, | ||
List< Item > & | all_fields, | ||
Order * | order, | ||
bool * | hidden_group_fields | ||
) |
Intitialize the GROUP BY list.
session | Thread Cursor |
ref_pointer_array | We store references to all fields that was not in 'fields' here. |
fields | All fields in the select part. Any item in 'order' that is part of these list is replaced by a pointer to this fields. |
all_fields | Total list of all unique fields used by the select. All items in 'order' that was not part of fields will be added first to this list. |
order | The fields we should do GROUP BY on. |
hidden_group_fields | Pointer to flag that is set to 1 if we added any fields to all_fields. |
0 | ok |
1 | error (probably out of memory) |
Definition at line 5951 of file sql_select.cc.
References drizzled::Item::const_item(), drizzled::find_order_in_list(), and drizzled::Item::used_tables().
Referenced by drizzled::setup_without_group().
int drizzled::setup_order | ( | Session * | session, |
Item ** | ref_pointer_array, | ||
TableList * | tables, | ||
List< Item > & | fields, | ||
List< Item > & | all_fields, | ||
Order * | order | ||
) |
Change order to point at item in select list.
If item isn't a number and doesn't exits in the select list, add it the the field list.
Definition at line 5908 of file sql_select.cc.
References drizzled::find_order_in_list().
Referenced by drizzled::delete_query(), and drizzled::setup_without_group().
bool drizzled::Join::setup_subquery_materialization | ( | ) |
Setup for execution all subqueries of a query, for which the optimizer chose hash semi-join.
Iterate over all subqueries of the query, and if they are under an IN predicate, and the optimizer chose to compute it via hash semi-join:
This method is part of the "code generation" query processing phase.
This phase must be called after substitute_for_best_equal_field() because that function may replace items with other items from a multiple equality, and we need to reference the correct items in the index access method of the IN predicate.
false | success. |
true | error occurred. |
Definition at line 1904 of file join.cc.
References drizzled::Join::select_lex, and drizzled::Item_in_subselect::setup_engine().
Referenced by drizzled::Join::optimize().
bool drizzled::setup_sum_funcs | ( | Session * | session, |
Item_sum ** | func_ptr | ||
) |
Call ::setup for all sum functions.
session | thread Cursor |
func_ptr | sum function list |
false | ok |
true | error |
Definition at line 6555 of file sql_select.cc.
Referenced by drizzled::Join::exec(), and drizzled::Join::optimize().
|
static |
Function to setup clauses without sum functions.
Definition at line 5525 of file join.cc.
References drizzled::setup_group(), and drizzled::setup_order().
Referenced by drizzled::Join::prepare().
|
static |
Simplify joins replacing outer joins by inner joins whenever it's possible.
The function, during a retrieval of join_list, eliminates those outer joins that can be converted into inner join, possibly nested. It also moves the on expressions for the converted outer joins and from inner joins to conds. The function also calculates some attributes for nested joins:
E.g. in the query:
the predicate t2.b < 5 rejects nulls. The query is converted first to:
then to the equivalent form:
Similarly the following query:
is converted to:
One conversion might trigger another:
The function removes all unnecessary braces from the expression produced by the conversions. E.g.
finally is converted to:
It also will remove braces from the following queries:
The benefit of this simplification procedure is that it might return a query for which the optimizer can evaluate execution plan with more join orders. With a left join operation the optimizer does not consider any plan where one of the inner tables is before some of outer tables.
IMPLEMENTATION The function is implemented by a recursive procedure. On the recursive ascent all attributes are calculated, all outer joins that can be converted are replaced and then all unnecessary braces are removed. As join list contains join tables in the reverse order sequential elimination of outer joins does not require extra recursive calls.
SEMI-JOIN NOTES Remove all semi-joins that have are within another semi-join (i.e. have an "ancestor" semi-join nest)
EXAMPLES Here is an example of a join query with invalid cross references:
join | reference to the query info |
join_list | list representation of the join to be converted |
conds | conditions to add on expressions for converted joins |
top | true <=> conds is the where condition |
Definition at line 5325 of file join.cc.
References drizzled::Item::fixed, drizzled::Table::map, drizzled::Item::not_null_tables(), drizzled::TableList::on_expr, drizzled::TableList::straight, drizzled::TableList::table, drizzled::Item::top_level_item(), and drizzled::Item::used_tables().
Referenced by drizzled::Join::optimize().
bool drizzled::store_val_in_field | ( | Field * | field, |
Item * | item, | ||
enum_check_fields | check_flag | ||
) |
This function is only called for const items on fields which are keys.
Definition at line 975 of file sql_select.cc.
References drizzled::Session::cuted_fields, and drizzled::Table::in_use.
Referenced by drizzled::matching_cond().
enum_nested_loop_state drizzled::sub_select | ( | Join * | join, |
JoinTable * | join_tab, | ||
bool | end_of_records | ||
) |
Retrieve records ends with a given beginning from the result of a join.
For a given partial join record consisting of records from the tables preceding the table join_tab in the execution plan, the function retrieves all matching full records from the result set and send them to the result set stream.
join | pointer to the structure providing all context info for the query |
join_tab | the first next table of the execution plan to be retrieved |
end_records | true when we need to perform final steps of retrival |
Definition at line 3486 of file sql_select.cc.
References drizzled::evaluate_join_record(), drizzled::evaluate_null_complemented_join_record(), drizzled::JoinTable::first_unmatched, drizzled::JoinTable::found, drizzled::JoinTable::last_inner, drizzled::JoinTable::not_null_compl, drizzled::Join::resume_nested_loop, drizzled::Join::return_tab, drizzled::Session::row_count, and drizzled::Join::tables.
Referenced by drizzled::do_select().
COND * drizzled::substitute_for_best_equal_field | ( | COND * | cond, |
COND_EQUAL * | cond_equal, | ||
void * | table_join_idx | ||
) |
Substitute every field reference in a condition by the best equal field and eliminate all multiple equality predicates.
The function retrieves the cond condition and for each encountered multiple equality predicate it sorts the field references in it according to the order of tables specified by the table_join_idx parameter. Then it eliminates the multiple equality predicate it replacing it by the conjunction of simple equality predicates equating every field from the multiple equality to the first field in it, or to the constant, if there is any. After this the function retrieves all other conjuncted predicates substitute every field reference by the field reference to the first equal field or equal constant if there are any.
cond | condition to process |
cond_equal | multiple equalities to take into consideration |
table_join_idx | index to tables determining field preference |
Definition at line 2354 of file sql_select.cc.
References drizzled::compare_fields_by_table_order(), drizzled::eliminate_item_equal(), drizzled::Item_equal::sort(), and drizzled::Item::val_bool().
Referenced by drizzled::Join::optimize().
|
static |
Test if one can use the key to resolve order_st BY.
used_key_parts is set to correct key parts used if return value != 0 (On other cases, used_key_part may be changed). Note that the value may actually be greater than the number of index key parts. This can happen for storage engines that have the primary key parts as a suffix for every secondary key.
order | Sort order |
table | Table to sort |
idx | Index to check |
used_key_parts | Return value for used key parts. |
1 | key is ok. |
0 | Key can't be used |
-1 | Reverse key can be used |
Definition at line 4521 of file sql_select.cc.
References drizzled::Table::cursor, and drizzled::Table::key_info.
Referenced by drizzled::test_if_skip_sort_order(), and drizzled::test_if_subkey().
bool drizzled::test_if_skip_sort_order | ( | JoinTable * | tab, |
Order * | order, | ||
ha_rows | select_limit, | ||
bool | no_changes, | ||
const key_map * | map | ||
) |
Test if we can skip the ORDER BY by using an index.
SYNOPSIS test_if_skip_sort_order() tab order select_limit no_changes map
If we can use an index, the JoinTable / tab->select struct is changed to use the index.
The index must cover all fields in <order>, or it will not be considered.
0 | We have to use filesort to do the sorting |
1 | We can use an index. |
Definition at line 4838 of file sql_select.cc.
References drizzled::optimizer::SqlSelect::cond, drizzled::Table::cursor, drizzled::optimizer::QuickSelectInterface::get_type(), drizzled::Join::getPosFromOptimalPlan(), drizzled::Join::group_list, drizzled::optimizer::QuickSelectInterface::index, drizzled::join_read_last_key(), drizzled::table_reference_st::key, drizzled::Table::key_info, drizzled::table_reference_st::key_parts, drizzled::JoinTable::keyuse, drizzled::JoinTable::limit, drizzled::JoinTable::pre_idx_push_select_cond, drizzled::optimizer::SqlSelect::quick, drizzled::Table::quick_condition_rows, drizzled::Join::tables, drizzled::test_if_order_by_key(), drizzled::test_if_subkey(), drizzled::JoinTable::type, drizzled::Join::unit, and drizzled::optimizer::QuickSelectInterface::used_key_parts.
Referenced by drizzled::Join::exec(), and drizzled::Join::optimize().
|
static |
Test if we can use one of the 'usable_keys' instead of 'ref' key for sorting.
ref | Number of key, used for WHERE clause |
usable_keys | Keys for testing |
Definition at line 4660 of file sql_select.cc.
References drizzled::is_subkey(), drizzled::Table::key_info, and drizzled::test_if_order_by_key().
Referenced by drizzled::test_if_skip_sort_order().
|
static |
Return 1 if second is a subpart of first argument.
If first parts has different direction, change it to second part (group is sorted like order)
Definition at line 6101 of file join.cc.
Referenced by drizzled::Join::exec(), and drizzled::Join::optimize().
void drizzled::update_const_equal_items | ( | COND * | cond, |
JoinTable * | tab | ||
) |
Check appearance of new constant items in multiple equalities of a condition after reading a constant table.
The function retrieves the cond condition and for each encountered multiple equality checks whether new constants have appeared after reading the constant (single row) table tab. If so it adjusts the multiple equality appropriately.
cond | condition whose multiple equalities are to be checked |
table | constant table that has been read |
Definition at line 2442 of file sql_select.cc.
References drizzled::JoinTable::const_keys, drizzled::Table::key_info, drizzled::Field::key_start, drizzled::JoinTable::keyuse, drizzled::Table::map, drizzled::Item_equal::update_const(), and drizzled::Item::used_tables().
|
static |
Update the dependency map for the tables.
Definition at line 5053 of file join.cc.
References drizzled::table_reference_st::depend_map, drizzled::table_reference_st::items, drizzled::table_reference_st::key_parts, drizzled::Join::map2table, drizzled::Join::tables, and drizzled::Item::used_tables().
Referenced by drizzled::get_best_combination(), and drizzled::remove_constants().
|
static |
Update the dependency map for the sort order.
Definition at line 5076 of file join.cc.
References drizzled::Join::map2table, and drizzled::Item::used_tables().
void drizzled::update_ref_and_keys | ( | Session * | session, |
DYNAMIC_ARRAY * | keyuse, | ||
JoinTable * | join_tab, | ||
uint32_t | tables, | ||
COND * | cond, | ||
COND_EQUAL * | , | ||
table_map | normal_tables, | ||
Select_Lex * | select_lex, | ||
vector< optimizer::SargableParam > & | sargables | ||
) |
Update keyuse array with all possible keys we can use to fetch rows.
session | ||
[out] | keyuse | Put here ordered array of KeyUse structures |
join_tab | Array in tablenr_order | |
tables | Number of tables in join | |
cond | WHERE condition (note that the function analyzes join_tab[i]->on_expr too) | |
normal_tables | Tables not inner w.r.t some outer join (ones for which we can make ref access based the WHERE clause) | |
select_lex | current SELECT | |
[out] | sargables | std::vector of found sargable candidates |
0 | OK |
1 | Out of memory. |
Definition at line 566 of file sql_select.cc.
References drizzled::JoinTable::checked_keys, drizzled::Join::join_list, drizzled::JoinTable::keyuse, drizzled::Table::map, and drizzled::JoinTable::on_expr_ref.
Referenced by drizzled::make_join_statistics().
void drizzled::update_tmptable_sum_func | ( | Item_sum ** | func_ptr, |
Table * | |||
) |
Update record 0 in tmp_table from record 1.
Definition at line 6578 of file sql_select.cc.
Referenced by drizzled::end_unique_update(), and drizzled::end_update().