diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/field.cc | 2 | ||||
-rw-r--r-- | sql/item.cc | 25 | ||||
-rw-r--r-- | sql/item.h | 1 | ||||
-rw-r--r-- | sql/item_cmpfunc.cc | 23 | ||||
-rw-r--r-- | sql/sql_select.cc | 9 |
5 files changed, 46 insertions, 14 deletions
diff --git a/sql/field.cc b/sql/field.cc index 0c097eeb54e..a6c452a91bf 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -11400,7 +11400,7 @@ void Field::statistics_available_via_keys() void Field::statistics_available_via_stat_tables() { THD *thd= get_thd(); - if (thd->variables.optimizer_use_condition_selectivity > 1 && + if (thd->variables.optimizer_use_condition_selectivity > 2 && check_eits_preferred(thd)) { if (read_stats && !read_stats->no_stat_values_provided()) diff --git a/sql/item.cc b/sql/item.cc index 71b73ae314f..34931af2c55 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -7507,7 +7507,8 @@ Item *Item::build_pushable_cond(THD *thd, col op const where op can be >/>=/</<=/=/<> Also the other cases are with [NOT] IN predicate, - [NOT] NULL predicate and LIKE predicate fall in the same category. + [NOT] NULL predicate and LIKE predicate fall + in the same category. The predicate should have only one non-constant argument and this argument will be a reference to a column that is used either as the first component of an index or statistics are available via @@ -7572,7 +7573,8 @@ Item *Item::build_pushable_cond(THD *thd, The implementation for this function use the 'walk' method to traverse the tree of this item with predicate_selectivity_checker() as the call-back parameter of the method. - + propagate_equal_fields() is called before this function is called so + Item_field::item_equal and Item_direct_view_ref::item_equal is set. @retval TRUE selectivity estimates are accurate @@ -7581,6 +7583,10 @@ Item *Item::build_pushable_cond(THD *thd, bool Item::with_accurate_selectivity_estimation() { + /* + For the below test one could use a virtual function but that would + take a lot of space for other item as there will be entires in the vtable + */ if (type() == Item::COND_ITEM && ((Item_cond*) this)->functype() == Item_func::COND_AND_FUNC) { @@ -9344,6 +9350,8 @@ Item_field::excl_dep_on_grouping_fields(st_select_lex *sel) This is used mostly for OR conjuncts where we need to make sure that the entire OR conjunct contains only one column, so that we may get accurate estimates. + An example with top level OR conjunct would be: + WHERE A=1 or A between 100 and 200 or A > 1000 @retval TRUE : the formula does not depend on one column @@ -10800,3 +10808,16 @@ bool Item::cleanup_excluding_immutables_processor (void *arg) return false; } } + + +bool Item::is_non_const_field_item() +{ + /* + calling real_item() here so that if the item is a REF_ITEM + then we would get the item field it is referring to + */ + Item *field_item= real_item(); + if (field_item->type() == Item::FIELD_ITEM && !field_item->const_item()) + return true; + return false; +} diff --git a/sql/item.h b/sql/item.h index 84063322a91..89f00d6762b 100644 --- a/sql/item.h +++ b/sql/item.h @@ -2506,6 +2506,7 @@ public: Checks if this item consists in the left part of arg IN subquery predicate */ bool pushable_equality_checker_for_subquery(uchar *arg); + bool is_non_const_field_item(); }; MEM_ROOT *get_thd_memroot(THD *thd); diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 4fe1d78af45..3b46c86bc1c 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -4320,8 +4320,9 @@ bool Item_func_in::predicate_selectivity_checker(void *arg) SAME_FIELD *field_arg= (SAME_FIELD*)arg; if (!field_arg->is_stats_available) return true; - all_items_are_consts(args + 1, arg_count - 1); - return false; + if (all_items_are_consts(args + 1, arg_count - 1)) + return false; + return true; } @@ -5557,7 +5558,7 @@ bool Item_func_null_predicate::predicate_selectivity_checker(void *arg) if (!field_arg->is_stats_available) return true; - if (is_range_predicate(args[0], NULL)) + if (args[0]->is_non_const_field_item()) return false; return true; } @@ -5769,7 +5770,7 @@ bool Item_func_like::predicate_selectivity_checker(void *arg) return true; if (with_sargable_pattern()) - return false; + return false; return true; } @@ -7220,6 +7221,20 @@ bool Item_equal::predicate_selectivity_checker(void *arg) available for all the fields in the multiple equality or not. */ Item_equal_fields_iterator it(*this); + + if (with_const) + { + while (it++) + { + Field *field= it.get_curr_field(); + if (!(field->is_range_statistics_available() || + field->is_ndv_available())) + return true; + } + return false; + } + + while (it++) { Field *field= it.get_curr_field(); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index c04eda05c57..414cab6f511 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -29478,13 +29478,8 @@ void unpack_to_base_table_fields(TABLE *table) bool is_range_predicate(Item *item, Item *value) { - /* - calling real_item() here so that if the item is a REF_ITEM - then we would get the item field it is referring to - */ - Item *field= item->real_item(); - if (field->type() == Item::FIELD_ITEM && !field->const_item() && - (!value || !value->is_expensive())) + if (item->is_non_const_field_item() && + (value->const_item() && !value->is_expensive())) return true; return false; } |