mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Change cost for REF to take into account cost for 1 extra key read_next
The main difference in code path between EQ_REF and REF is that for REF we have to do an extra read_next on the index to check that there is no more matching rows. Before this patch we added a preference of EQ_REF by ensuring that REF would always estimate to find at least 2 rows. This patch adds the cost of the extra key read_next to REF access and removes the code that limited REF to at least 2 rows. For some queries this can have a big effect as the total estimated rows will be halved for each REF table with 1 rows. multi_range cost calculations are also changed to take into account the difference between EQ_REF and REF. The effect of the patch to the test suite: - About 80 test case changed - Almost all changes where for EXPLAIN where estimated rows for REF where changed from 2 to 1. - A few test cases using explain extended had a change of 'filtered'. This is because of the estimated rows are now closer to the calculated selectivity. - A very few test had a change of table order. This is because the change of estimated rows from 2 to 1 or the small cost change for REF (main.subselect_sj_jcl6, main.group_by, main.dervied_cond_pushdown, main.distinct, main.join_nested, main.order_by, main.join_cache) - No key statistics and the estimated rows are now smaller which cased estimated filtering to be lower. (main.subselect_sj_mat) - The number of total rows are halved. (main.derived_cond_pushdown) - Plans with 1 row changed to use RANGE instead of REF. (main.group_min_max) - ALL changed to REF (main.key_diff) - Key changed from ref + index_only to PRIMARY key for InnoDB, as OPTIMIZER_ROW_LOOKUP_COST + OPTIMIZER_ROW_NEXT_FIND_COST is smaller than OPTIMIZER_KEY_LOOKUP_COST + OPTIMIZER_KEY_NEXT_FIND_COST. (main.join_outer_innodb) - Cost changes printouts (main.opt_trace*) - Result order change (innodb_gis.rtree)
This commit is contained in:
@ -113,12 +113,12 @@ explain select * from t1 where a=1 or b=1 {
|
||||
"using_mrr": false,
|
||||
"index_only": true,
|
||||
"rows": 1,
|
||||
"cost": 0.001388369,
|
||||
"cost": 0.001478954,
|
||||
"chosen": true
|
||||
}
|
||||
],
|
||||
"index_to_merge": "a",
|
||||
"cumulated_cost": 0.001388369
|
||||
"cumulated_cost": 0.001478954
|
||||
},
|
||||
{
|
||||
"range_scan_alternatives": [
|
||||
@ -129,15 +129,15 @@ explain select * from t1 where a=1 or b=1 {
|
||||
"using_mrr": false,
|
||||
"index_only": true,
|
||||
"rows": 1,
|
||||
"cost": 0.001388369,
|
||||
"cost": 0.001478954,
|
||||
"chosen": true
|
||||
}
|
||||
],
|
||||
"index_to_merge": "b",
|
||||
"cumulated_cost": 0.002776738
|
||||
"cumulated_cost": 0.002957908
|
||||
}
|
||||
],
|
||||
"cost_of_reading_ranges": 0.002776738,
|
||||
"cost_of_reading_ranges": 0.002957908,
|
||||
"use_roworder_union": true,
|
||||
"cause": "always cheaper than non roworder retrieval",
|
||||
"analyzing_roworder_scans": [
|
||||
@ -160,7 +160,7 @@ explain select * from t1 where a=1 or b=1 {
|
||||
}
|
||||
}
|
||||
],
|
||||
"index_roworder_union_cost": 0.005004612,
|
||||
"index_roworder_union_cost": 0.005185782,
|
||||
"members": 2,
|
||||
"chosen": true
|
||||
}
|
||||
@ -189,7 +189,7 @@ explain select * from t1 where a=1 or b=1 {
|
||||
]
|
||||
},
|
||||
"rows_for_plan": 2,
|
||||
"cost_for_plan": 0.005004612,
|
||||
"cost_for_plan": 0.005185782,
|
||||
"chosen": true
|
||||
}
|
||||
}
|
||||
@ -222,7 +222,7 @@ explain select * from t1 where a=1 or b=1 {
|
||||
"rows": 2,
|
||||
"rows_after_filter": 2,
|
||||
"rows_out": 2,
|
||||
"cost": 0.005004612,
|
||||
"cost": 0.005185782,
|
||||
"chosen": true
|
||||
}
|
||||
],
|
||||
@ -230,7 +230,7 @@ explain select * from t1 where a=1 or b=1 {
|
||||
"type": "index_merge",
|
||||
"rows_read": 2,
|
||||
"rows_out": 2,
|
||||
"cost": 0.005004612,
|
||||
"cost": 0.005185782,
|
||||
"uses_join_buffering": false
|
||||
}
|
||||
}
|
||||
@ -241,14 +241,14 @@ explain select * from t1 where a=1 or b=1 {
|
||||
"plan_prefix": "",
|
||||
"table": "t1",
|
||||
"rows_for_plan": 2,
|
||||
"cost_for_plan": 0.005004612
|
||||
"cost_for_plan": 0.005185782
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"best_join_order": ["t1"],
|
||||
"rows": 2,
|
||||
"cost": 0.005004612
|
||||
"cost": 0.005185782
|
||||
},
|
||||
{
|
||||
"substitute_best_equal": {
|
||||
@ -347,7 +347,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
|
||||
"using_mrr": false,
|
||||
"index_only": false,
|
||||
"rows": 2243,
|
||||
"cost": 2.770260666,
|
||||
"cost": 2.770351251,
|
||||
"chosen": true
|
||||
},
|
||||
{
|
||||
@ -358,7 +358,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
|
||||
"using_mrr": false,
|
||||
"index_only": false,
|
||||
"rows": 2243,
|
||||
"cost": 2.770260666,
|
||||
"cost": 2.770351251,
|
||||
"chosen": false,
|
||||
"cause": "cost"
|
||||
},
|
||||
@ -370,7 +370,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
|
||||
"using_mrr": false,
|
||||
"index_only": false,
|
||||
"rows": 2243,
|
||||
"cost": 2.770260666,
|
||||
"cost": 2.770351251,
|
||||
"chosen": false,
|
||||
"cause": "cost"
|
||||
}
|
||||
@ -492,7 +492,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
|
||||
"using_mrr": false,
|
||||
"index_only": true,
|
||||
"rows": 2243,
|
||||
"cost": 0.312832109,
|
||||
"cost": 0.312922694,
|
||||
"chosen": true
|
||||
},
|
||||
{
|
||||
@ -503,13 +503,13 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
|
||||
"using_mrr": false,
|
||||
"index_only": true,
|
||||
"rows": 2243,
|
||||
"cost": 0.312832109,
|
||||
"cost": 0.312922694,
|
||||
"chosen": false,
|
||||
"cause": "cost"
|
||||
}
|
||||
],
|
||||
"index_to_merge": "key1",
|
||||
"cumulated_cost": 0.312832109
|
||||
"cumulated_cost": 0.312922694
|
||||
},
|
||||
{
|
||||
"range_scan_alternatives":
|
||||
@ -522,7 +522,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
|
||||
"using_mrr": false,
|
||||
"index_only": true,
|
||||
"rows": 2243,
|
||||
"cost": 0.312832109,
|
||||
"cost": 0.312922694,
|
||||
"chosen": true
|
||||
},
|
||||
{
|
||||
@ -533,16 +533,16 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
|
||||
"using_mrr": false,
|
||||
"index_only": true,
|
||||
"rows": 2243,
|
||||
"cost": 0.312832109,
|
||||
"cost": 0.312922694,
|
||||
"chosen": false,
|
||||
"cause": "cost"
|
||||
}
|
||||
],
|
||||
"index_to_merge": "key3",
|
||||
"cumulated_cost": 0.625664218
|
||||
"cumulated_cost": 0.625845388
|
||||
}
|
||||
],
|
||||
"cost_of_reading_ranges": 0.625664218,
|
||||
"cost_of_reading_ranges": 0.625845388,
|
||||
"use_roworder_union": true,
|
||||
"cause": "always cheaper than non roworder retrieval",
|
||||
"analyzing_roworder_scans":
|
||||
|
Reference in New Issue
Block a user