MCPcopy Create free account
hub / github.com/MariaDB/server / optimize_straight_join

Function optimize_straight_join

sql/sql_select.cc:10628–10739  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10626*/
10627
10628static void
10629optimize_straight_join(JOIN *join, table_map remaining_tables)
10630{
10631 JOIN_TAB *s;
10632 uint idx= join->const_tables;
10633 bool disable_jbuf= join->thd->variables.join_cache_level == 0;
10634 double record_count= 1.0;
10635 double read_time= 0.0;
10636 uint use_cond_selectivity=
10637 join->thd->variables.optimizer_use_condition_selectivity;
10638 POSITION loose_scan_pos;
10639 THD *thd= join->thd;
10640
10641 init_join_plan_search_state(join);
10642
10643 for (JOIN_TAB **pos= join->best_ref + idx ; (s= *pos) ; pos++)
10644 {
10645 POSITION *position= join->positions + idx;
10646 Json_writer_object trace_one_table(thd);
10647 double original_record_count, current_record_count;
10648
10649 if (unlikely(thd->trace_started()))
10650 trace_plan_prefix(&trace_one_table, join, idx, remaining_tables);
10651 /* Find the best access method from 's' to the current partial plan */
10652 best_access_path(join, s, remaining_tables, join->positions, idx,
10653 disable_jbuf, record_count,
10654 position, &loose_scan_pos);
10655
10656 /* Compute the cost of the new plan extended with 's' */
10657 current_record_count= COST_MULT(record_count, position->records_out);
10658 read_time= COST_ADD(read_time, position->read_time);
10659 original_record_count= current_record_count;
10660 optimize_semi_joins(join, remaining_tables, idx, &current_record_count,
10661 &read_time, &loose_scan_pos);
10662 if (position->sj_strategy != SJ_OPT_NONE && original_record_count)
10663 {
10664 /* Adjust records_out to contain the final number of rows */
10665 double ratio= current_record_count / original_record_count;
10666 if (ratio < 1)
10667 {
10668 position->records_out*= ratio;
10669 }
10670 if (unlikely(trace_one_table.trace_started()))
10671 {
10672 trace_one_table.
10673 add("sj_rows_out", position->records_out).
10674 add("sj_rows_for_plan", current_record_count).
10675 add("sj_filtered", safe_filtered(position->records_out,
10676 position->records_init));
10677 }
10678 }
10679
10680 remaining_tables&= ~(s->table->map);
10681 if (use_cond_selectivity > 1 && position->sj_strategy == SJ_OPT_NONE)
10682 {
10683 double pushdown_cond_selectivity, records_out;
10684 pushdown_cond_selectivity= table_after_join_selectivity(join, idx, s,
10685 remaining_tables,

Callers 1

choose_planFunction · 0.85

Calls 11

trace_plan_prefixFunction · 0.85
best_access_pathFunction · 0.85
COST_MULTFunction · 0.85
COST_ADDFunction · 0.85
optimize_semi_joinsFunction · 0.85
safe_filteredFunction · 0.85
get_qsort_sort_costFunction · 0.85
trace_startedMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected