[Commits] 74ce152dca3: cc

Oleksandr Byelkin sanja at mariadb.com
Tue Apr 16 09:55:51 EEST 2019


revision-id: 74ce152dca39685cf534d86a9b2c553f4bb1551c (mariadb-5.5.63-19-g74ce152dca3)
parent(s): d85bf9f2d9bad832db72f62a942e38173bbf31ed
author: Oleksandr Byelkin
committer: Oleksandr Byelkin
timestamp: 2019-04-16 08:55:51 +0200
message:

cc

---
 sql/item_subselect.cc | 36 +++++++++++++++++++++++++++++++-----
 sql/item_subselect.h  | 19 ++++---------------
 sql/opt_subselect.cc  |  5 ++++-
 3 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index c578beb9fc9..c7e638c1772 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -3043,13 +3043,23 @@ bool subselect_union_engine::no_rows()
 }
 
 
+// constructor can assign THD because it will be called after JOIN::prepare
+subselect_uniquesubquery_engine::subselect_uniquesubquery_engine(THD *thd_arg,
+  st_join_table *tab_arg, Item_subselect *subs, Item *where, uint8* uncache)
+  :subselect_engine(subs, 0), tab(tab_arg), cond(where),
+   uncacheable_ref(uncache)
+{
+  Item_in_subselect *in_subs= (Item_in_subselect *) item;
+  DBUG_ASSERT(item->unit->first_select()->next_select() == 0);
+  *uncacheable_ref= (in_subs->left_expr->const_item() ?
+                     0 :
+                     UNCACHEABLE_DEPENDENT_INJECTED);
+}
+
 void subselect_uniquesubquery_engine::cleanup()
 {
   DBUG_ENTER("subselect_uniquesubquery_engine::cleanup");
   Item_in_subselect *in_subs= (Item_in_subselect *) item;
-  tab->select->uncacheable= (in_subs->left_expr->const_item() ?
-                             0 :
-                             UNCACHEABLE_DEPENDENT_INJECTED);
   /* 
     Note for mergers: we don't have to, and actually must not de-initialize
     tab->table->file here.
@@ -3475,7 +3485,7 @@ bool subselect_uniquesubquery_engine::copy_ref_key(bool skip_constants)
 
 uint8 subselect_uniquesubquery_engine::uncacheable()
 {
-  return tab->select->uncachable;
+  return *uncacheable_ref;
 }
 
 
@@ -3616,6 +3626,17 @@ subselect_uniquesubquery_engine::~subselect_uniquesubquery_engine()
  //psergey-merge: don't need this after all: tab->table->file->ha_index_end();
 }
 
+// constructor can assign THD because it will be called after JOIN::prepare
+subselect_indexsubquery_engine::subselect_indexsubquery_engine
+   (THD *thd_arg, st_join_table *tab_arg, Item_subselect *subs, Item *where,
+    Item *having_arg, bool chk_null)
+    :subselect_uniquesubquery_engine(thd_arg, tab_arg, subs, where,
+                                     &subs->unit->first_select()->uncacheable),
+     check_null(chk_null),
+     having(having_arg)
+{
+  DBUG_ASSERT(subs->unit->first_select()->next_select() == 0);
+}
 
 /**
   Execute subselect via unique index lookup
@@ -4590,8 +4611,13 @@ subselect_hash_sj_engine::make_unique_engine()
   tab->preread_init_done= FALSE;
   tab->ref.tmp_table_index_lookup_init(thd, tmp_key, it, FALSE);
 
+  DBUG_ASSERT(item->unit->first_select()->next_select() == 0);
+
   DBUG_RETURN(new subselect_uniquesubquery_engine(thd, tab, item,
-                                                  semi_join_conds));
+                                                  semi_join_conds,
+                                                  &item->unit->
+                                                   first_select()->
+                                                   uncacheable));
 }
 
 
diff --git a/sql/item_subselect.h b/sql/item_subselect.h
index ebb2445fc4f..f315491d46c 100644
--- a/sql/item_subselect.h
+++ b/sql/item_subselect.h
@@ -887,19 +887,13 @@ class subselect_uniquesubquery_engine: public subselect_engine
     TRUE<=> last execution produced empty set. Valid only when left
     expression is NULL.
   */
+  uint8 *uncacheable_ref;
   bool empty_result_set;
 public:
 
-  // constructor can assign THD because it will be called after JOIN::prepare
   subselect_uniquesubquery_engine(THD *thd_arg, st_join_table *tab_arg,
-				  Item_subselect *subs, Item *where)
-    :subselect_engine(subs, 0), tab(tab_arg), cond(where)
-  {
-    Item_in_subselect *in_subs= (Item_in_subselect *) item;
-    tab->select->uncacheable= (in_subs->left_expr->const_item() ?
-                               0 :
-                               UNCACHEABLE_DEPENDENT_INJECTED);
-  }
+				  Item_subselect *subs, Item *where,
+                                  uint8 *uncach_ref);
   ~subselect_uniquesubquery_engine();
   void cleanup();
   int prepare(THD *);
@@ -958,14 +952,9 @@ class subselect_indexsubquery_engine: public subselect_uniquesubquery_engine
   Item *having;
 public:
 
-  // constructor can assign THD because it will be called after JOIN::prepare
   subselect_indexsubquery_engine(THD *thd_arg, st_join_table *tab_arg,
 				 Item_subselect *subs, Item *where,
-                                 Item *having_arg, bool chk_null)
-    :subselect_uniquesubquery_engine(thd_arg, tab_arg, subs, where),
-     check_null(chk_null),
-     having(having_arg)
-  {}
+                                 Item *having_arg, bool chk_null);
   int exec();
   virtual void print (String *str, enum_query_type query_type);
   virtual enum_engine_type engine_type() { return INDEXSUBQUERY_ENGINE; }
diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc
index 62a5b0793e9..9266ccc0d9f 100644
--- a/sql/opt_subselect.cc
+++ b/sql/opt_subselect.cc
@@ -5102,7 +5102,10 @@ int rewrite_to_index_subquery_engine(JOIN *join)
                                   subselect_uniquesubquery_engine(thd,
                                                                   join_tab,
                                                                   unit->item,
-                                                                  where)));
+                                                                  where,
+                                                                  &join->
+                                                                  select_lex->
+                                                                  uncacheable)));
       }
       else if (join_tab[0].type == JT_REF &&
 	       join_tab[0].ref.items[0]->name == in_left_expr_name)


More information about the commits mailing list