diff options
Diffstat (limited to 'sql/opt_range.cc')
-rw-r--r-- | sql/opt_range.cc | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 3f8509a4b47..2987f2ebab6 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -2645,6 +2645,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, { uint idx; double scan_time; + Item *notnull_cond= NULL; DBUG_ENTER("SQL_SELECT::test_quick_select"); DBUG_PRINT("enter",("keys_to_use: %lu prev_tables: %lu const_tables: %lu", (ulong) keys_to_use.to_ulonglong(), (ulong) prev_tables, @@ -2659,6 +2660,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, if (keys_to_use.is_clear_all() || head->is_filled_at_execution()) DBUG_RETURN(0); records= head->stat_records(); + notnull_cond= head->notnull_cond; if (!records) records++; /* purecov: inspected */ scan_time= (double) records / TIME_FOR_COMPARE + 1; @@ -2666,7 +2668,10 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, if (head->force_index) scan_time= read_time= DBL_MAX; if (limit < records) + { read_time= (double) records + scan_time + 1; // Force to use index + notnull_cond= NULL; + } possible_keys.clear_all(); @@ -2689,6 +2694,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, uchar buff[STACK_BUFF_ALLOC]; MEM_ROOT alloc; SEL_TREE *tree= NULL; + SEL_TREE *notnull_cond_tree= NULL; KEY_PART *key_parts; KEY *key_info; PARAM param; @@ -2825,6 +2831,9 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, TRP_GROUP_MIN_MAX *group_trp= NULL; double best_read_time= read_time; + if (notnull_cond) + notnull_cond_tree= notnull_cond->get_mm_tree(¶m, ¬null_cond); + if (cond) { { @@ -2852,6 +2861,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, } } } + tree= tree_and(¶m, tree, notnull_cond_tree); /* Try to construct a QUICK_GROUP_MIN_MAX_SELECT. @@ -8128,16 +8138,6 @@ SEL_TREE *Item_bool_func::get_full_func_mm_tree(RANGE_OPT_PARAM *param, table_map ref_tables= 0; table_map param_comp= ~(param->prev_tables | param->read_tables | param->current_table); -#ifdef HAVE_SPATIAL - Field::geometry_type sav_geom_type; - const bool geometry= field_item->field->type() == MYSQL_TYPE_GEOMETRY; - if (geometry) - { - sav_geom_type= ((Field_geom*) field_item->field)->geom_type; - /* We have to be able to store all sorts of spatial features here */ - ((Field_geom*) field_item->field)->geom_type= Field::GEOM_GEOMETRY; - } -#endif /*HAVE_SPATIAL*/ for (uint i= 0; i < arg_count; i++) { @@ -8165,12 +8165,6 @@ SEL_TREE *Item_bool_func::get_full_func_mm_tree(RANGE_OPT_PARAM *param, } } -#ifdef HAVE_SPATIAL - if (geometry) - { - ((Field_geom*) field_item->field)->geom_type= sav_geom_type; - } -#endif /*HAVE_SPATIAL*/ DBUG_RETURN(ftree); } |