[MDEV-30763] SELECT STRAIGHT_JOIN doesn't print cost_for_plan, rows_for_plan Created: 2023-03-01  Updated: 2023-11-28

Status: Open
Project: MariaDB Server
Component/s: None
Affects Version/s: 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11
Fix Version/s: 10.6, 10.11

Type: Bug Priority: Major
Reporter: Sergei Petrunia Assignee: Sergei Petrunia
Resolution: Unresolved Votes: 0
Labels: None


 Description   

optimize_straight_join() doesn't print cost_for_plan and rows_for_plan, which makes it hard to debug join optimization.

We should add the printouts.



 Comments   
Comment by Sergei Petrunia [ 2023-03-01 ]

diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index fa33f0e0500..2b45fcd518f 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -8976,6 +8976,11 @@ optimize_straight_join(JOIN *join, table_map join_tables)
     read_time+= COST_ADD(read_time - filter_cmp_gain,
                          COST_ADD(position->read_time,
                                   record_count / TIME_FOR_COMPARE));
+    if (unlikely(thd->trace_started()))
+    {
+      trace_one_table.add("rows_for_plan", record_count);
+      trace_one_table.add("cost_for_plan", read_time);
+    }
     advance_sj_state(join, join_tables, idx, &record_count, &read_time,
                      &loose_scan_pos);
 
@@ -8985,6 +8990,16 @@ optimize_straight_join(JOIN *join, table_map join_tables)
       pushdown_cond_selectivity= table_cond_selectivity(join, idx, s,
                                                         join_tables);
     position->cond_selectivity= pushdown_cond_selectivity;
+
+    if (unlikely(thd->trace_started()))
+    {
+      if (pushdown_cond_selectivity < 1.0)
+      {
+        trace_one_table.add("selectivity", pushdown_cond_selectivity);
+        trace_one_table.add("estimated_join_cardinality",
+                            (record_count * pushdown_cond_selectivity));
+      }
+    }
     ++idx;
   }
 

Generated at Thu Feb 08 10:18:42 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.