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

MDEV-34894: Poor query plan, because range estimates are not reused for ref(const)

(Variant 4, with @@optimizer_adjust_secondary_key_costs, reuse in two
places, and conditions are replaced with equivalent simpler forms in two more)

In best_access_path(), ReuseRangeEstimateForRef-3,  the check
for whether
 "all used key_part_i used key_part_i=const"
was incorrect: it may produced a "NO" answer for cases when we
had:
 key_part1= const // some key parts are usable
 key_part2= value_not_in_join_prefix  //present but unusable
 key_part3= non_const_value // unusable due to gap in key parts.

This caused the optimizer to fail to apply ReuseRangeEstimateForRef
heuristics. The consequence is poor query plan choice when the index
in question has very skewed data distribution.

The fix is enabled if its @@optimizer_adjust_secondary_key_costs flag
is set.
This commit is contained in:
Sergei Petrunia
2024-09-07 17:17:44 +03:00
parent c41ab95a38
commit c630e23a18
9 changed files with 214 additions and 22 deletions

View File

@@ -721,8 +721,10 @@ The following specify which files/extra groups are read (specified before remain
disable_forced_index_in_group_by = Disable automatic
forced index in GROUP BY. fix_innodb_cardinality =
Disable doubling of the Cardinality for InnoDB secondary
keys. This variable will be deleted in MariaDB 11.0 as it
is not needed with the new 11.0 optimizer.
keys. fix_reuse_range_for_ref = Do a better job at
reusing range access estimates when estimating ref
access. This variable will be deleted in MariaDB 11.0 as
it is not needed with the new 11.0 optimizer.
Use 'ALL' to set all combinations.
--optimizer-join-limit-pref-ratio=#
For queries with JOIN and ORDER BY LIMIT : make the
@@ -1705,7 +1707,7 @@ old-alter-table DEFAULT
old-mode UTF8_IS_UTF8MB3
old-passwords FALSE
old-style-user-limits FALSE
optimizer-adjust-secondary-key-costs
optimizer-adjust-secondary-key-costs fix_reuse_range_for_ref
optimizer-join-limit-pref-ratio 0
optimizer-max-sel-arg-weight 32000
optimizer-max-sel-args 16000