v.21.8Improvement
Add optimize_move_to_prewhere_if_final Setting for FINAL Query Optimization
Add settingoptimize_move_to_prewhere_if_final. If query hasFINAL, the optimizationmove_to_prewherewill be enabled only if bothoptimize_move_to_prewhereandoptimize_move_to_prewhere_if_finalare enabled. Closes #8684. #25940 (Kseniia Sumarokova).
Why it matters
Previously, themove_to_prewhere optimization could interfere with queries using the FINAL modifier. This new setting allows users to enable or disable the optimization specifically for FINAL queries, providing finer control and potentially improving query performance without unexpected side effects.How to use it
To enable the optimization for queries withFINAL, set both optimize_move_to_prewhere and optimize_move_to_prewhere_if_final to 1 (or true). For example, in your session or configuration:SET optimize_move_to_prewhere = 1;
SET optimize_move_to_prewhere_if_final = 1;This ensures that the
move_to_prewhere optimization applies only when the query has the FINAL keyword and both settings are enabled.