From e38e9589a8b2743dffdcb8b208baaa1ba7fdf14f Mon Sep 17 00:00:00 2001 From: tianfengli Date: Tue, 6 Aug 2024 18:04:20 +0800 Subject: [PATCH] Adjust the number of subquery evaluations to ensure that the EXISTS strategy is fairly comparable to the materialization strategy. --- sql/sql_optimizer.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sql/sql_optimizer.cc b/sql/sql_optimizer.cc index 0909e2192f0..bb471c5e8cf 100644 --- a/sql/sql_optimizer.cc +++ b/sql/sql_optimizer.cc @@ -11250,10 +11250,13 @@ bool JOIN::compare_costs_of_subquery_strategies(Subquery_strategy *method) { /* The number of evaluations of the subquery influences costs, we need to - compute it. + compute it. Ensure that the number of evaluations of the subquery is + at least 1.0, so the cost_of_EXISTS is always greater than + cost_of_one_EXISTS. */ Opt_trace_object trace_subq_mat_decision(trace, "subq_mat_decision"); - const double subq_executions = calculate_subquery_executions(in_pred, trace); + double subq_executions = calculate_subquery_executions(in_pred, trace); + subq_executions = std::max(subq_executions, 1.0); const double cost_exists = subq_executions * saved_best_read; const double cost_mat_table = sjm.materialization_cost.total_cost(); const double cost_mat = -- 2.19.1