Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
10.6
Description
(Filing based on discussion with monty )
When analyzing the trace MDEV-30877, noted this:
The derived table has
"table_scan": {
|
"rows": 13304563,
|
"cost": 1.33e7
|
}
|
Compare to the non-derived table in the same query:
"table": "es",
|
"table_scan": {
|
"rows": 12840562,
|
"cost": 103969
|
}
|
The numbers of rows are similar but there's 128x difference in costs.
The number comes from here:
double JOIN_TAB::scan_time() |
{
|
if (table->is_created()) |
...
|
else |
{
|
found_records= records=table->stat_records();
|
read_time= found_records ? (double)found_records: 10.0;// TODO:fix this stub |
res= read_time;
|
}
|
Note the read_time= found_records assignment...
However, the code was rewritten in 11.0's cost model change:
scan_time is now called JOIN_TAB::estimate_scan_time(), There one can see:
...
{
The following is same as calling
TABLE_SHARE::update_optimizer_costs, but without locks
*/
file->set_optimizer_costs(thd);
table->s->optimizer_costs_inited=1;
records= table->stat_records();
DBUG_ASSERT(table->opt_range_condition_rows == records);
cost->row_cost= table->file->ha_scan_time(MY_MAX(records, 1000));
read_time= file->cost(cost->row_cost);
row_copy_cost= table->s->optimizer_costs.row_copy_cost;
}