List:Commits« Previous MessageNext Message »
From:Roy Lyseng Date:February 8 2012 10:34am
Subject:bzr push into mysql-trunk branch (roy.lyseng:3859 to 3860)
View as plain text  
 3860 Roy Lyseng	2012-02-08
      Refactoring: Remove member and_tables_cache of Item_cond.
      
      The Item_cond class maintains both not_null_tables_cache
      and and_tables_cache to implement the not_null_tables()
      interface. and_tables_cache is only used for conditions of
      type AND, but it is simple to replace its use with
      not_null_tables_cache.
      
      sql/item.h:
        Deleted Item_name_const::const_item() and
        Item_sp_variable::const_item(), as they are the same as for the
        base class.
      
      sql/item_cmpfunc.cc:
        Maintain not_null_tables_cache instead of and_tables_cache.
      
      sql/item_cmpfunc.h:
        Remove member and_tables_cache, remove function not_null_tables()
        for class Item_cond.

    modified:
      sql/item.h
      sql/item_cmpfunc.cc
      sql/item_cmpfunc.h
 3859 Vasil Dimov	2012-02-08
      Fix compilation failure when compiling with partitioning disabled.
      partition_names is not defined in this case.
      
      Reviewed by:	mattiasj (via IM)

    modified:
      sql/sql_lex.cc
=== modified file 'sql/item.h'
--- a/sql/item.h	2012-02-07 10:30:39 +0000
+++ b/sql/item.h	2012-02-08 10:33:37 +0000
@@ -1045,6 +1045,8 @@ public:
   /* 
     Returns true if this is constant (during query execution, i.e. its value
     will not change until next fix_fields) and its value is known.
+    When the default implementation of used_tables() is effective, this
+    function will always return true (because used_tables() is empty).
   */
   virtual bool const_item() const { return used_tables() == 0; }
   /* 
@@ -1548,10 +1550,7 @@ public:
   bool is_null();
 
 public:
-  inline void make_field(Send_field *field);
-  
-  inline bool const_item() const;
-  
+  inline void make_field(Send_field *field);  
   inline int save_in_field(Field *field, bool no_conversions);
   inline bool send(Protocol *protocol, String *str);
 }; 
@@ -1571,11 +1570,6 @@ inline void Item_sp_variable::make_field
   it->make_field(field);
 }
 
-inline bool Item_sp_variable::const_item() const
-{
-  return TRUE;
-}
-
 inline int Item_sp_variable::save_in_field(Field *field, bool no_conversions)
 {
   return this_item()->save_in_field(field, no_conversions);
@@ -1767,11 +1761,6 @@ public:
     return value_item->result_type();
   }
 
-  bool const_item() const
-  {
-    return TRUE;
-  }
-
   int save_in_field(Field *field, bool no_conversions)
   {
     return  value_item->save_in_field(field, no_conversions);

=== modified file 'sql/item_cmpfunc.cc'
--- a/sql/item_cmpfunc.cc	2012-01-25 09:57:22 +0000
+++ b/sql/item_cmpfunc.cc	2012-02-08 10:33:37 +0000
@@ -4722,8 +4722,7 @@ longlong Item_func_bit_and::val_int()
 
 Item_cond::Item_cond(THD *thd, Item_cond *item)
   :Item_bool_func(thd, item),
-   abort_on_null(item->abort_on_null),
-   and_tables_cache(item->and_tables_cache)
+   abort_on_null(item->abort_on_null)
 {
   /*
     item->list will be copied by copy_andor_arguments() call
@@ -4748,16 +4747,16 @@ Item_cond::fix_fields(THD *thd, Item **r
   st_select_lex::Resolve_place save_resolve=
     thd->lex->current_select->resolve_place;
   uchar buff[sizeof(char*)];			// Max local vars in function
-  not_null_tables_cache= used_tables_cache= 0;
-  const_item_cache= 1;
+  used_tables_cache= 0;
+  const_item_cache= true;
 
   if (functype() != COND_AND_FUNC)
     thd->lex->current_select->resolve_place= st_select_lex::RESOLVE_NONE;
-  /*
-    and_table_cache is the value that Item_cond_or() returns for
-    not_null_tables()
-  */
-  and_tables_cache= ~(table_map) 0;
+
+  if (functype() == COND_AND_FUNC && abort_on_null)
+    not_null_tables_cache= 0;
+  else
+    not_null_tables_cache= ~(table_map) 0;
 
   if (check_stack_overrun(thd, STACK_MIN_SIZE, buff))
     return TRUE;				// Fatal error flag is set!
@@ -4778,7 +4777,6 @@ Item_cond::fix_fields(THD *thd, Item **r
   */
   while ((item=li++))
   {
-    table_map tmp_table_map;
     while (item->type() == Item::COND_ITEM &&
 	   ((Item_cond*) item)->functype() == functype() &&
            !((Item_cond*) item)->list.is_empty())
@@ -4795,26 +4793,26 @@ Item_cond::fix_fields(THD *thd, Item **r
 	 item->fix_fields(thd, li.ref())) ||
 	(item= *li.ref())->check_cols(1))
       return TRUE; /* purecov: inspected */
-    used_tables_cache|=     item->used_tables();
-    if (item->const_item())
-      and_tables_cache= (table_map) 0;
+    used_tables_cache|= item->used_tables();
+    const_item_cache&=  item->const_item();
+
+    // Old code assumed that not_null_tables() was 0 when const_item() was true
+    DBUG_ASSERT(!item->const_item() || !item->not_null_tables());
+
+    if (functype() == COND_AND_FUNC && abort_on_null)
+      not_null_tables_cache|= item->not_null_tables();
     else
-    {
-      tmp_table_map= item->not_null_tables();
-      not_null_tables_cache|= tmp_table_map;
-      and_tables_cache&= tmp_table_map;
-      const_item_cache= FALSE;
-    }  
-    with_sum_func=	    with_sum_func || item->with_sum_func;
-    with_subselect|=        item->has_subquery();
+      not_null_tables_cache&= item->not_null_tables();
+    with_sum_func|=  item->with_sum_func;
+    with_subselect|= item->has_subquery();
     if (item->maybe_null)
-      maybe_null=1;
+      maybe_null= true;
   }
   thd->lex->current_select->cond_count+= list.elements;
   thd->lex->current_select->resolve_place= save_resolve;
   fix_length_and_dec();
-  fixed= 1;
-  return FALSE;
+  fixed= true;
+  return false;
 }
 
 
@@ -4825,29 +4823,24 @@ void Item_cond::fix_after_pullout(st_sel
   List_iterator<Item> li(list);
   Item *item;
 
-  used_tables_cache=0;
-  const_item_cache=1;
+  used_tables_cache= 0;
+  const_item_cache= true;
 
-  and_tables_cache= ~(table_map) 0; // Here and below we do as fix_fields does
-  not_null_tables_cache= 0;
+  if (functype() == COND_AND_FUNC && abort_on_null)
+    not_null_tables_cache= 0;
+  else
+    not_null_tables_cache= ~(table_map) 0;
 
   while ((item=li++))
   {
-    table_map tmp_table_map;
     item->fix_after_pullout(parent_select, removed_select, li.ref());
     item= *li.ref();
     used_tables_cache|= item->used_tables();
     const_item_cache&= item->const_item();
-
-    if (item->const_item())
-      and_tables_cache= (table_map) 0;
+    if (functype() == COND_AND_FUNC && abort_on_null)
+      not_null_tables_cache|= item->not_null_tables();
     else
-    {
-      tmp_table_map= item->not_null_tables();
-      not_null_tables_cache|= tmp_table_map;
-      and_tables_cache&= tmp_table_map;
-      const_item_cache= FALSE;
-    }  
+      not_null_tables_cache&= item->not_null_tables();
   }
 }
 
@@ -5003,13 +4996,6 @@ void Item_cond::split_sum_func(THD *thd,
 }
 
 
-table_map
-Item_cond::used_tables() const
-{						// This caches used_tables
-  return used_tables_cache;
-}
-
-
 void Item_cond::update_used_tables()
 {
   List_iterator_fast<Item> li(list);

=== modified file 'sql/item_cmpfunc.h'
--- a/sql/item_cmpfunc.h	2012-01-30 06:39:02 +0000
+++ b/sql/item_cmpfunc.h	2012-02-08 10:33:37 +0000
@@ -1596,7 +1596,6 @@ class Item_cond :public Item_bool_func
 protected:
   List<Item> list;
   bool abort_on_null;
-  table_map and_tables_cache;
 
 public:
   /* Item_cond() is only used to create top level items */
@@ -1632,7 +1631,7 @@ public:
 
   enum Type type() const { return COND_ITEM; }
   List<Item>* argument_list() { return &list; }
-  table_map used_tables() const;
+  table_map used_tables() const { return used_tables_cache; }
   void update_used_tables();
   virtual void print(String *str, enum_query_type query_type);
   void split_sum_func(THD *thd, Ref_ptr_array ref_pointer_array,
@@ -1821,8 +1820,6 @@ public:
   enum Functype functype() const { return COND_AND_FUNC; }
   longlong val_int();
   const char *func_name() const { return "and"; }
-  table_map not_null_tables() const
-  { return abort_on_null ? not_null_tables_cache: and_tables_cache; }
   Item* copy_andor_structure(THD *thd)
   {
     Item_cond_and *item;
@@ -1852,7 +1849,6 @@ public:
   enum Functype functype() const { return COND_OR_FUNC; }
   longlong val_int();
   const char *func_name() const { return "or"; }
-  table_map not_null_tables() const { return and_tables_cache; }
   Item* copy_andor_structure(THD *thd)
   {
     Item_cond_or *item;

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (roy.lyseng:3859 to 3860) Roy Lyseng8 Feb