diff options
author | Igor Babaev <igor@askmonty.org> | 2013-03-31 15:18:55 -0700 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2013-03-31 15:18:55 -0700 |
commit | 0f3f93532bf19464c88b67e502fccec293f91d39 (patch) | |
tree | 7f7a6b3e361e48865ae61c5aac85d1d6cdf31ee3 /sql | |
parent | 993ea79f2df42292eceeee394e8ece9f4a3f6cf2 (diff) | |
parent | 599a1384af7d38e4319bd6258c6954750f5b9ba4 (diff) | |
download | mariadb-git-0f3f93532bf19464c88b67e502fccec293f91d39.tar.gz |
Merge 5.5->10.0-base
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item.cc | 4 | ||||
-rw-r--r-- | sql/item_subselect.cc | 15 | ||||
-rw-r--r-- | sql/item_sum.cc | 33 | ||||
-rw-r--r-- | sql/item_sum.h | 1 | ||||
-rw-r--r-- | sql/sql_const.h | 2 | ||||
-rw-r--r-- | sql/sql_select.cc | 3 |
6 files changed, 48 insertions, 10 deletions
diff --git a/sql/item.cc b/sql/item.cc index 1d8e466b2fd..a425b0cd4ce 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -8109,7 +8109,7 @@ bool Item_default_value::fix_fields(THD *thd, Item **items) } if (!(def_field= (Field*) sql_alloc(field_arg->field->size_of()))) goto error; - memcpy(def_field, field_arg->field, field_arg->field->size_of()); + memcpy((void *)def_field, (void *)field_arg->field, field_arg->field->size_of()); def_field->move_field_offset((my_ptrdiff_t) (def_field->table->s->default_values - def_field->table->record[0])); @@ -8245,7 +8245,7 @@ bool Item_insert_value::fix_fields(THD *thd, Item **items) Field *def_field= (Field*) sql_alloc(field_arg->field->size_of()); if (!def_field) return TRUE; - memcpy(def_field, field_arg->field, field_arg->field->size_of()); + memcpy((void *)def_field, (void *)field_arg->field, field_arg->field->size_of()); def_field->move_field_offset((my_ptrdiff_t) (def_field->table->insert_values - def_field->table->record[0])); diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index f2ef955af05..0544dceb9a0 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -559,8 +559,19 @@ bool Item_subselect::is_expensive() if (!cur_join) continue; - /* If a subquery is not optimized we cannot estimate its cost. */ - if (!cur_join->join_tab) + /* + Subqueries whose result is known after optimization are not expensive. + Such subqueries have all tables optimized away, thus have no join plan. + */ + if (cur_join->optimized && + (cur_join->zero_result_cause || !cur_join->tables_list)) + return false; + + /* + If a subquery is not optimized we cannot estimate its cost. A subquery is + considered optimized if it has a join plan. + */ + if (!(cur_join->optimized && cur_join->join_tab)) return true; if (sl->first_inner_unit()) diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 9410a12f21b..03afd1a4365 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -735,7 +735,15 @@ int simple_raw_key_cmp(void* arg, const void* key1, const void* key2) } -int item_sum_distinct_walk(void *element, element_count num_of_dups, +static int item_sum_distinct_walk_for_count(void *element, + element_count num_of_dups, + void *item) +{ + return ((Aggregator_distinct*) (item))->unique_walk_function_for_count(element); +} + + +static int item_sum_distinct_walk(void *element, element_count num_of_dups, void *item) { return ((Aggregator_distinct*) (item))->unique_walk_function(element); @@ -1105,7 +1113,12 @@ void Aggregator_distinct::endup() { /* go over the tree of distinct keys and calculate the aggregate value */ use_distinct_values= TRUE; - tree->walk(table, item_sum_distinct_walk, (void*) this); + tree_walk_action func; + if (item_sum->sum_func() == Item_sum::COUNT_DISTINCT_FUNC) + func= item_sum_distinct_walk_for_count; + else + func= item_sum_distinct_walk; + tree->walk(table, func, (void*) this); use_distinct_values= FALSE; } /* prevent consecutive recalculations */ @@ -1482,6 +1495,22 @@ bool Aggregator_distinct::unique_walk_function(void *element) } +/* + A variant of unique_walk_function() that is to be used with Item_sum_count. + + COUNT is a special aggregate function: it doesn't need the values, it only + needs to count them. COUNT needs to know the values are not NULLs, but NULL + values are not put into the Unique, so we don't need to check for NULLs here. +*/ + +bool Aggregator_distinct::unique_walk_function_for_count(void *element) +{ + Item_sum_count *sum= (Item_sum_count *)item_sum; + sum->count++; + return 0; +} + + Aggregator_distinct::~Aggregator_distinct() { if (tree) diff --git a/sql/item_sum.h b/sql/item_sum.h index 40a28d8beae..a954b0f65c1 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -642,6 +642,7 @@ public: virtual bool arg_is_null(); bool unique_walk_function(void *element); + bool unique_walk_function_for_count(void *element); static int composite_key_cmp(void* arg, uchar* key1, uchar* key2); }; diff --git a/sql/sql_const.h b/sql/sql_const.h index c6aa52197d5..7dadbb7b8b4 100644 --- a/sql/sql_const.h +++ b/sql/sql_const.h @@ -93,7 +93,7 @@ #define FIELD_NR_MASK 16383 /* To get fieldnumber */ #define FERR -1 /* Error from my_functions */ #define CREATE_MODE 0 /* Default mode on new files */ -#define NAMES_SEP_CHAR '\377' /* Char to sep. names */ +#define NAMES_SEP_CHAR 255 /* Char to sep. names */ #define READ_RECORD_BUFFER (uint) (IO_SIZE*8) /* Pointer_buffer_size */ #define DISK_BUFFER_SIZE (uint) (IO_SIZE*16) /* Size of diskbuffer */ diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 0abac42eb73..ad4324fa7d1 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -13037,9 +13037,6 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top, table->prep_on_expr= table->on_expr= 0; } } - - if (!top) - continue; /* Only inner tables of non-convertible outer joins |