Skip to content

Commit c8d0409

Browse files
committed
MDEV-34720: Poor plan choice for large JOIN with ORDER BY and small LIMIT
(Variant 2b: call greedy_search() twice, correct handling for limited search_depth) Modify the join optimizer to specifically try to produce join orders that can short-cut their execution for ORDER BY..LIMIT clause. The optimization is controlled by @@optimizer_join_limit_pref_ratio. Default value 0 means don't construct short-cutting join orders. Other value means construct short-cutting join order, and prefer it only if it promises speedup of more than #value times. In Optimizer Trace, look for these names: * join_limit_shortcut_is_applicable * join_limit_shortcut_plan_search * join_limit_shortcut_choice
1 parent 819765a commit c8d0409

File tree

9 files changed

+1110
-11
lines changed

9 files changed

+1110
-11
lines changed

mysql-test/main/mysqld--help.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,15 @@ The following specify which files/extra groups are read (specified before remain
724724
keys. This variable will be deleted in MariaDB 11.0 as it
725725
is not needed with the new 11.0 optimizer.
726726
Use 'ALL' to set all combinations.
727+
--optimizer-join-limit-pref-ratio=#
728+
For queries with JOIN and ORDER BY LIMIT : make the
729+
optimizer consider a join order that allows to short-cut
730+
execution after producing #LIMIT matches if that promises
731+
N times speedup. (A conservative setting here would be is
732+
a high value, like 100 so the short-cutting plan is used
733+
if it promises a speedup of 100x or more). Short-cutting
734+
plans are inherently risky so the default is 0 which
735+
means do not consider this optimization
727736
--optimizer-max-sel-arg-weight=#
728737
The maximum weight of the SEL_ARG graph. Set to 0 for no
729738
limit
@@ -1697,6 +1706,7 @@ old-mode UTF8_IS_UTF8MB3
16971706
old-passwords FALSE
16981707
old-style-user-limits FALSE
16991708
optimizer-adjust-secondary-key-costs
1709+
optimizer-join-limit-pref-ratio 0
17001710
optimizer-max-sel-arg-weight 32000
17011711
optimizer-max-sel-args 16000
17021712
optimizer-prune-level 1

0 commit comments

Comments
 (0)