1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

Split cost calculations into fetch and total

This patch causes no changes in costs or result files.

Changes:
- Store row compare cost separately in Cost_estimate::comp_cost
- Store cost of fetching rows separately in OPT_RANGE
- Use range->fetch_cost instead of adjust_quick_cost(total_cost)

This was done to simplify cost calculation in sql_select.cc:
- We can use range->fetch_cost directly without having to call
  adjust_quick_cost(). adjust_quick_cost() is now removed.

Other things:
- Removed some not used functions in Cost_estimate
This commit is contained in:
Monty
2021-10-21 19:40:58 +03:00
committed by Sergei Petrunia
parent 766bae2b31
commit e6205c966d
5 changed files with 42 additions and 42 deletions

View File

@@ -7834,26 +7834,6 @@ double cost_for_index_read(const THD *thd, const TABLE *table, uint key,
}
/*
Adjust cost from table->quick_costs calculated by
multi_range_read_info_const() to be comparable with cost_for_index_read()
This functions is needed because best_access_path() doesn't add
TIME_FOR_COMPARE to it's costs until very late.
Preferably we should fix so that all costs are comparably.
(All compared costs should include TIME_FOR_COMPARE for all found
rows).
*/
double adjust_quick_cost(double quick_cost, ha_rows records)
{
double cost= (quick_cost - MULTI_RANGE_READ_SETUP_COST -
rows2double(records)/TIME_FOR_COMPARE);
DBUG_ASSERT(cost > 0.0);
return cost;
}
/**
Find the best access path for an extension of a partial execution
plan and add this path to the plan.
@@ -8117,7 +8097,7 @@ best_access_path(JOIN *join,
add("access_type", join_type_str[type]).
add("index", keyinfo->name);
if (!found_ref && table->opt_range_keys.is_set(key))
tmp= adjust_quick_cost(table->opt_range[key].cost, 1);
tmp= table->opt_range[key].fetch_cost;
else
tmp= table->file->avg_io_cost();
/*
@@ -8158,8 +8138,7 @@ best_access_path(JOIN *join,
{
records= (double) table->opt_range[key].rows;
trace_access_idx.add("used_range_estimates", true);
tmp= adjust_quick_cost(table->opt_range[key].cost,
table->opt_range[key].rows);
tmp= table->opt_range[key].fetch_cost;
goto got_cost2;
}
/* quick_range couldn't use key! */
@@ -8285,8 +8264,7 @@ best_access_path(JOIN *join,
table->opt_range[key].ranges == 1 + MY_TEST(ref_or_null_part)) //(C3)
{
records= (double) table->opt_range[key].rows;
tmp= adjust_quick_cost(table->opt_range[key].cost,
table->opt_range[key].rows);
tmp= table->opt_range[key].fetch_cost;
trace_access_idx.add("used_range_estimates", true);
goto got_cost2;
}