← Back to team overview

maria-developers team mailing list archive

Likely a dead optimizer related code

 

Hi Igor,

I noticed that during Item_cond::fix_fields() and Item_func_between::fix_fields() update these optimizer
related SELECT_LEX members:

thd->lex->current_select->cond_count and
thd->lex->current_select->between_count

The purpose of these members is to allocate optimizer related buffers
in:
- update_ref_and_keys() in sql_select.cc and
- check_func_dependency() in opt_table_elimination,cc
and it seems they have no any other purposes..


From my understanding, this is a dead code and the collected values are
never used:

- cond_count and_between_count are later always initialized to 0
before the walk(count_sargable_conds) call in update_ref_and_keys().


- moreover, using the values collected during fix_fields() would not be
correct to allocate optimized related buffers, because the code
in fix_fields() does not distinguish between different query parts,
so the items can be just a part of the SELECT list rather than a
part of WHERE/HAVING/ON.


Is the attached patch correct? All tests pass.


Thanks.
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index a192675..6971135 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -2151,18 +2151,6 @@ longlong Item_func_interval::val_int()
     1   got error
 */
 
-bool Item_func_between::fix_fields(THD *thd, Item **ref)
-{
-  if (Item_func_opt_neg::fix_fields(thd, ref))
-    return 1;
-
-  thd->lex->current_select->between_count++;
-
-
-  return 0;
-}
-
-
 bool Item_func_between::eval_not_null_tables(uchar *opt_arg)
 {
   if (Item_func_opt_neg::eval_not_null_tables(NULL))
@@ -4337,7 +4325,6 @@ Item_cond::fix_fields(THD *thd, Item **ref)
     if (item->maybe_null)
       maybe_null=1;
   }
-  thd->lex->current_select->cond_count+= list.elements;
   fix_length_and_dec();
   fixed= 1;
   return FALSE;
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index f2d0032..f78c7d2 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -644,7 +644,6 @@ class Item_func_between :public Item_func_opt_neg
   optimize_type select_optimize() const { return OPTIMIZE_KEY; }
   enum Functype functype() const   { return BETWEEN; }
   const char *func_name() const { return "between"; }
-  bool fix_fields(THD *, Item **);
   void fix_length_and_dec();
   virtual void print(String *str, enum_query_type query_type);
   CHARSET_INFO *compare_collation() const { return cmp_collation.collation; }
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 20b156a..d08f1b0 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -800,7 +800,7 @@ class st_select_lex: public st_select_lex_node
     list during split_sum_func
   */
   uint select_n_having_items;
-  uint cond_count;    /* number of arguments of and/or/xor in where/having/on */
+  uint cond_count;    /* number of sargable Items in where/having/on          */
   uint between_count; /* number of between predicates in where/having/on      */
   uint max_equal_elems; /* maximal number of elements in multiple equalities  */   
   /*

Follow ups