1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +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:
Monty
2022-12-27 14:49:27 +02:00
parent b5df077e85
commit 3fa99f0c0e
81 changed files with 765 additions and 740 deletions

View File

@ -58,7 +58,7 @@ JS
"index": "a",
"used_range_estimates": true,
"rows": 104,
"cost": 0.060906438,
"cost": 0.060988785,
"chosen": true
},
{
@ -66,7 +66,7 @@ JS
"index": "b",
"used_range_estimates": true,
"rows": 340,
"cost": 0.14153631,
"cost": 0.141618657,
"chosen": false,
"cause": "cost"
},
@ -75,7 +75,7 @@ JS
"index": "c",
"used_range_estimates": true,
"rows": 632,
"cost": 0.241743894,
"cost": 0.241826241,
"chosen": false,
"cause": "cost"
},
@ -156,7 +156,7 @@ JS
"index": "a",
"used_range_estimates": true,
"rows": 6,
"cost": 0.005306142,
"cost": 0.005388489,
"chosen": true
},
{
@ -164,7 +164,7 @@ JS
"index": "b",
"used_range_estimates": true,
"rows": 232,
"cost": 0.104637894,
"cost": 0.104720241,
"chosen": false,
"cause": "cost"
},
@ -173,7 +173,7 @@ JS
"index": "c",
"used_range_estimates": true,
"rows": 293,
"cost": 0.125478666,
"cost": 0.125561013,
"chosen": false,
"cause": "cost"
},
@ -188,7 +188,7 @@ JS
"type": "ref",
"rows_read": 6,
"rows_out": 0.6,
"cost": 0.005306142,
"cost": 0.005388489,
"uses_join_buffering": false
}
}
@ -199,7 +199,7 @@ JS
"plan_prefix": "",
"table": "t1",
"rows_for_plan": 0.6,
"cost_for_plan": 0.005306142,
"cost_for_plan": 0.005388489,
"pushdown_cond_selectivity": 0.1,
"filtered": 10,
"rows_out": 0.6