diff options
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r-- | sql/sql_select.cc | 70 |
1 files changed, 28 insertions, 42 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 46c68d7cd4d..1361930b65d 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -924,19 +924,6 @@ Item* SELECT_LEX::period_setup_conds(THD *thd, TABLE_LIST *tables, Item *where) DBUG_RETURN(result); } -/** - Setup System Versioning conditions - - Add WHERE condition according to FOR SYSTEM_TIME clause. - - If the table is partitioned by SYSTEM_TIME and there is no FOR SYSTEM_TIME - clause, then select now-partition instead of modifying WHERE condition. - - @retval - -1 on error - @retval - 0 on success -*/ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables) { DBUG_ENTER("SELECT_LEX::vers_setup_conds"); @@ -994,13 +981,12 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables) vers_select_conds_t &vers_conditions= table->vers_conditions; #ifdef WITH_PARTITION_STORAGE_ENGINE - Vers_part_info *vers_info; - if (table->table->part_info && (vers_info= table->table->part_info->vers_info)) - { - if (table->partition_names) + /* + if the history is stored in partitions, then partitions + themselves are not versioned + */ + if (table->partition_names && table->table->part_info->vers_info) { - /* If the history is stored in partitions, then partitions - themselves are not versioned. */ if (vers_conditions.is_set()) { my_error(ER_VERS_QUERY_IN_PARTITION, MYF(0), table->alias.str); @@ -1009,19 +995,6 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables) else vers_conditions.init(SYSTEM_TIME_ALL); } - else if (!vers_conditions.is_set() && - /* We cannot optimize REPLACE .. SELECT because it may need - to call vers_set_hist_part() to update history. */ - thd->lex->sql_command != SQLCOM_REPLACE_SELECT) - { - table->partition_names= newx List<String>; - String *s= newx String(vers_info->now_part->partition_name, - system_charset_info); - table->partition_names->push_back(s); - table->table->file->change_partitions_to_open(table->partition_names); - vers_conditions.init(SYSTEM_TIME_ALL); - } - } #endif if (outer_table && !vers_conditions.is_set()) @@ -1076,7 +1049,6 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables) DBUG_RETURN(0); } -#undef newx /***************************************************************************** Check fields, find best join, do the select and output fields. @@ -8831,6 +8803,7 @@ void JOIN::get_prefix_cost_and_fanout(uint n_tables, record_count= COST_MULT(record_count, best_positions[i].records_read); read_time= COST_ADD(read_time, best_positions[i].read_time); } + /* TODO: Take into account condition selectivities here */ } *read_time_arg= read_time;// + record_count / TIME_FOR_COMPARE; *record_count_arg= record_count; @@ -9071,6 +9044,7 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, KEYUSE *keyuse= pos->key; KEYUSE *prev_ref_keyuse= keyuse; uint key= keyuse->key; + bool used_range_selectivity= false; /* Check if we have a prefix of key=const that matches a quick select. @@ -9096,6 +9070,7 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, keyparts++; } sel /= (double)table->quick_rows[key] / (double) table->stat_records(); + used_range_selectivity= true; } } @@ -9131,13 +9106,14 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, if (keyparts > keyuse->keypart) { /* Ok this is the keyuse that will be used for ref access */ - uint fldno; - if (is_hash_join_key_no(key)) - fldno= keyuse->keypart; - else - fldno= table->key_info[key].key_part[keyparts-1].fieldnr - 1; - if (keyuse->val->const_item()) + if (!used_range_selectivity && keyuse->val->const_item()) { + uint fldno; + if (is_hash_join_key_no(key)) + fldno= keyuse->keypart; + else + fldno= table->key_info[key].key_part[keyparts-1].fieldnr - 1; + if (table->field[fldno]->cond_selectivity > 0) { sel /= table->field[fldno]->cond_selectivity; @@ -16718,10 +16694,20 @@ void optimize_wo_join_buffering(JOIN *join, uint first_tab, uint last_tab, reopt_remaining_tables &= ~rs->table->map; rec_count= COST_MULT(rec_count, pos.records_read); cost= COST_ADD(cost, pos.read_time); - - + cost= COST_ADD(cost, rec_count / (double) TIME_FOR_COMPARE); + //TODO: take into account join condition selectivity here + double pushdown_cond_selectivity= 1.0; + table_map real_table_bit= rs->table->map; + if (join->thd->variables.optimizer_use_condition_selectivity > 1) + { + pushdown_cond_selectivity= table_cond_selectivity(join, i, rs, + reopt_remaining_tables & + ~real_table_bit); + } + (*outer_rec_count) *= pushdown_cond_selectivity; if (!rs->emb_sj_nest) *outer_rec_count= COST_MULT(*outer_rec_count, pos.records_read); + } join->cur_sj_inner_tables= save_cur_sj_inner_tables; @@ -28676,7 +28662,7 @@ select_handler *SELECT_LEX::find_select_handler(THD *thd) return 0; if (master_unit()->outer_select()) return 0; - for (TABLE_LIST *tbl= join->tables_list; tbl; tbl= tbl->next_local) + for (TABLE_LIST *tbl= join->tables_list; tbl; tbl= tbl->next_global) { if (!tbl->table) continue; |