From 4f568ab503c91840779ac493f3c7f7bbbfa4fb57 Mon Sep 17 00:00:00 2001 From: Monty Date: Fri, 3 Jun 2022 13:24:18 +0300 Subject: Reduced size of POSITION Replaced Cost_estimate prefix_cost with a double as prefix_cost was only used to store and retrive total prefix cost. This also speeds up things (a bit) as don't have to call Cost_estimate::total_cost() for every access to the prefix_cost. Sizeof POSITION decreased from 304 to 256. --- sql/opt_subselect.cc | 17 ++++++++--------- sql/sql_select.cc | 2 +- sql/sql_select.h | 6 +++--- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 3e58a2788c8..2440047638e 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -2895,7 +2895,7 @@ void optimize_semi_joins(JOIN *join, table_map remaining_tables, uint idx, pos[-1].inner_tables_handled_with_other_sjs; } - pos->prefix_cost.convert_from_cost(*current_read_time); + pos->prefix_cost= *current_read_time; pos->prefix_record_count= *current_record_count; { @@ -3017,7 +3017,7 @@ void optimize_semi_joins(JOIN *join, table_map remaining_tables, uint idx, update_sj_state(join, new_join_tab, idx, remaining_tables); - pos->prefix_cost.convert_from_cost(*current_read_time); + pos->prefix_cost= *current_read_time; pos->prefix_record_count= *current_record_count; pos->dups_producing_tables= dups_producing_tables; } @@ -3107,15 +3107,15 @@ bool Sj_materialization_picker::check_qep(JOIN *join, else { /* This is SJ-Materialization with lookups */ - Cost_estimate prefix_cost; + double prefix_cost; signed int first_tab= (int)idx - mat_info->tables; - double prefix_rec_count; + double prefix_rec_count, mat_read_time; Json_writer_object trace(join->thd); trace.add("strategy", "SJ-Materialization"); if (first_tab < (int)join->const_tables) { - prefix_cost.reset(); + prefix_cost= 0; prefix_rec_count= 1.0; } else @@ -3124,9 +3124,8 @@ bool Sj_materialization_picker::check_qep(JOIN *join, prefix_rec_count= join->positions[first_tab].prefix_record_count; } - double mat_read_time= prefix_cost.total_cost(); mat_read_time= - COST_ADD(mat_read_time, + COST_ADD(prefix_cost, COST_ADD(mat_info->materialization_cost.total_cost(), COST_MULT(prefix_rec_count, mat_info->lookup_cost.total_cost()))); @@ -3171,7 +3170,7 @@ bool Sj_materialization_picker::check_qep(JOIN *join, } else { - prefix_cost= join->positions[first_tab - 1].prefix_cost.total_cost(); + prefix_cost= join->positions[first_tab - 1].prefix_cost; prefix_rec_count= join->positions[first_tab - 1].prefix_record_count; } @@ -3535,7 +3534,7 @@ bool Duplicate_weedout_picker::check_qep(JOIN *join, } else { - dups_cost= join->positions[first_tab - 1].prefix_cost.total_cost(); + dups_cost= join->positions[first_tab - 1].prefix_cost; prefix_rec_count= join->positions[first_tab - 1].prefix_record_count; temptable_rec_size= 8; /* This is not true but we'll make it so */ } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 0aea34fffb7..3b07122e7c1 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -17946,7 +17946,7 @@ void optimize_wo_join_buffering(JOIN *join, uint first_tab, uint last_tab, if (first_tab > join->const_tables) { - cost= join->positions[first_tab - 1].prefix_cost.total_cost(); + cost= join->positions[first_tab - 1].prefix_cost; rec_count= join->positions[first_tab - 1].prefix_record_count; } else diff --git a/sql/sql_select.h b/sql/sql_select.h index 8e318503b18..46a359c746f 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -952,6 +952,9 @@ public: double prefix_record_count; + /* Cost for the join prefix */ + double prefix_cost; + /* NULL - 'index' or 'range' or 'index_merge' or 'ALL' access is used. Other - [eq_]ref[_or_null] access is used. Pointer to {t.keypart1 = expr} @@ -983,9 +986,6 @@ public: LooseScan_picker loosescan_picker; Sj_materialization_picker sjmat_picker; - /* Cumulative cost and record count for the join prefix */ - Cost_estimate prefix_cost; - /* Current optimization state: Semi-join strategy to be used for this and preceding join tables. -- cgit v1.2.1