[Commits] 12d294b7d39: Correcting the value of top_join_tab_count, to not include inner tables of semi-join nest for the tables at the top level

Varun varunraiko1803 at gmail.com
Wed Jul 10 13:14:21 EEST 2019


revision-id: 12d294b7d39320afbf17eb5ad14f7aa651301c2c (mariadb-10.4.4-242-g12d294b7d39)
parent(s): a179de04025443032745ee811a97d8da7afe8996
author: Varun Gupta
committer: Varun Gupta
timestamp: 2019-07-09 15:14:19 +0530
message:

Correcting the value of top_join_tab_count, to not include inner tables of semi-join nest for the tables at the top level

---
 sql/opt_subselect.cc | 32 ++++++++++++++++++++++++++++++++
 sql/opt_subselect.h  |  1 +
 sql/sql_select.cc    |  8 +++++---
 3 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc
index f00d0ed019d..35438461bbd 100644
--- a/sql/opt_subselect.cc
+++ b/sql/opt_subselect.cc
@@ -3853,6 +3853,38 @@ void fix_semijoin_strategies_for_picked_join_order(JOIN *join)
 }
 
 
+/*
+  Return the number of tables at the top-level of the JOIN
+
+  SYNOPSIS
+    get_number_of_tables_at_top_level()
+      join  The join with the picked join order
+
+  DESCRIPTION
+    The number of tables in the JOIN currently include all the inner tables of the
+    mergeable semi-joins. The function would make sure that we only count the semi-join
+    nest and not the inner tables of teh semi-join nest.
+*/
+
+uint get_number_of_tables_at_top_level(JOIN *join)
+{
+  uint j= 0, tables=0;
+  while(j < join->table_count)
+  {
+    POSITION *cur_pos= &join->best_positions[j];
+    tables++;
+    if (cur_pos->sj_strategy == SJ_OPT_MATERIALIZE ||
+        cur_pos->sj_strategy == SJ_OPT_MATERIALIZE_SCAN)
+    {
+      SJ_MATERIALIZATION_INFO *sjm= cur_pos->table->emb_sj_nest->sj_mat_info;
+      j= j + sjm->tables;
+    }
+    else
+      j++;
+  }
+  return tables;
+}
+
 /*
   Setup semi-join materialization strategy for one semi-join nest
   
diff --git a/sql/opt_subselect.h b/sql/opt_subselect.h
index 65131f6bc89..67bfad1a539 100644
--- a/sql/opt_subselect.h
+++ b/sql/opt_subselect.h
@@ -320,6 +320,7 @@ void fix_semijoin_strategies_for_picked_join_order(JOIN *join);
 
 bool setup_sj_materialization_part1(JOIN_TAB *sjm_tab);
 bool setup_sj_materialization_part2(JOIN_TAB *sjm_tab);
+uint get_number_of_tables_at_top_level(JOIN *join);
 
 
 /*
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 1f397b20b98..d5254bc1bb7 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -10153,14 +10153,16 @@ bool JOIN::get_best_combination()
 
   if (aggr_tables > 2)
     aggr_tables= 2;
-  if (!(join_tab= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB)*
-                                        (top_join_tab_count + aggr_tables))))
-    DBUG_RETURN(TRUE);
 
   full_join=0;
   hash_join= FALSE;
 
   fix_semijoin_strategies_for_picked_join_order(this);
+  top_join_tab_count= get_number_of_tables_at_top_level(this);
+
+  if (!(join_tab= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB)*
+                                        (top_join_tab_count + aggr_tables))))
+    DBUG_RETURN(TRUE);
    
   JOIN_TAB_RANGE *root_range;
   if (!(root_range= new (thd->mem_root) JOIN_TAB_RANGE))


More information about the commits mailing list