Commit 721a6a6a authored by Michael Widenius's avatar Michael Widenius

A proper fix for bug #57688.

Introduced a new flag in the class Item. The flag is set
to 1 only for items that are used in GROUP BY lists of
queries with ROLLUP.
parent babdbbbf
...@@ -380,6 +380,7 @@ Item::Item(): ...@@ -380,6 +380,7 @@ Item::Item():
{ {
marker= 0; marker= 0;
maybe_null=null_value=with_sum_func=unsigned_flag=0; maybe_null=null_value=with_sum_func=unsigned_flag=0;
in_rollup= 0;
decimals= 0; max_length= 0; decimals= 0; max_length= 0;
with_subselect= 0; with_subselect= 0;
cmp_context= IMPOSSIBLE_RESULT; cmp_context= IMPOSSIBLE_RESULT;
...@@ -420,6 +421,7 @@ Item::Item(THD *thd, Item *item): ...@@ -420,6 +421,7 @@ Item::Item(THD *thd, Item *item):
marker(item->marker), marker(item->marker),
decimals(item->decimals), decimals(item->decimals),
maybe_null(item->maybe_null), maybe_null(item->maybe_null),
in_rollup(item->in_rollup),
null_value(item->null_value), null_value(item->null_value),
unsigned_flag(item->unsigned_flag), unsigned_flag(item->unsigned_flag),
with_sum_func(item->with_sum_func), with_sum_func(item->with_sum_func),
......
...@@ -518,6 +518,8 @@ class Item { ...@@ -518,6 +518,8 @@ class Item {
int8 marker; int8 marker;
uint8 decimals; uint8 decimals;
my_bool maybe_null; /* If item may be null */ my_bool maybe_null; /* If item may be null */
my_bool in_rollup; /* If used in GROUP BY list
of a query with ROLLUP */
my_bool null_value; /* if item is null */ my_bool null_value; /* if item is null */
my_bool unsigned_flag; my_bool unsigned_flag;
my_bool with_sum_func; my_bool with_sum_func;
......
...@@ -8919,6 +8919,8 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top) ...@@ -8919,6 +8919,8 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top)
For some of the inner tables there are conjunctive predicates For some of the inner tables there are conjunctive predicates
that reject nulls => the outer join can be replaced by an inner join. that reject nulls => the outer join can be replaced by an inner join.
*/ */
if (table->outer_join && !table->embedding && table->table)
table->table->maybe_null= FALSE;
table->outer_join= 0; table->outer_join= 0;
if (table->on_expr) if (table->on_expr)
{ {
...@@ -9005,6 +9007,8 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top) ...@@ -9005,6 +9007,8 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top)
while ((tbl= it++)) while ((tbl= it++))
{ {
tbl->embedding= table->embedding; tbl->embedding= table->embedding;
if (!tbl->embedding && !tbl->on_expr && tbl->table)
tbl->table->maybe_null= FALSE;
tbl->join_list= table->join_list; tbl->join_list= table->join_list;
} }
li.replace(nested_join->join_list); li.replace(nested_join->join_list);
...@@ -9882,7 +9886,7 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, ...@@ -9882,7 +9886,7 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
If item have to be able to store NULLs but underlaid field can't do it, If item have to be able to store NULLs but underlaid field can't do it,
create_tmp_field_from_field() can't be used for tmp field creation. create_tmp_field_from_field() can't be used for tmp field creation.
*/ */
if (field->maybe_null && !field->field->maybe_null()) if (field->maybe_null && field->in_rollup && !field->field->maybe_null())
{ {
result= create_tmp_field_from_item(thd, item, table, NULL, result= create_tmp_field_from_item(thd, item, table, NULL,
modify_item, convert_blob_length); modify_item, convert_blob_length);
...@@ -13508,8 +13512,6 @@ static bool ...@@ -13508,8 +13512,6 @@ static bool
list_contains_unique_index(TABLE *table, list_contains_unique_index(TABLE *table,
bool (*find_func) (Field *, void *), void *data) bool (*find_func) (Field *, void *), void *data)
{ {
if (table->pos_in_table_list->outer_join)
return 0;
for (uint keynr= 0; keynr < table->s->keys; keynr++) for (uint keynr= 0; keynr < table->s->keys; keynr++)
{ {
if (keynr == table->s->primary_key || if (keynr == table->s->primary_key ||
...@@ -13523,7 +13525,7 @@ list_contains_unique_index(TABLE *table, ...@@ -13523,7 +13525,7 @@ list_contains_unique_index(TABLE *table,
key_part < key_part_end; key_part < key_part_end;
key_part++) key_part++)
{ {
if (key_part->field->real_maybe_null() || if (key_part->field->maybe_null() ||
!find_func(key_part->field, data)) !find_func(key_part->field, data))
break; break;
} }
...@@ -16337,6 +16339,7 @@ static bool change_group_ref(THD *thd, Item_func *expr, ORDER *group_list, ...@@ -16337,6 +16339,7 @@ static bool change_group_ref(THD *thd, Item_func *expr, ORDER *group_list,
if (arg_changed) if (arg_changed)
{ {
expr->maybe_null= 1; expr->maybe_null= 1;
expr->in_rollup= 1;
*changed= TRUE; *changed= TRUE;
} }
} }
...@@ -16400,6 +16403,7 @@ bool JOIN::rollup_init() ...@@ -16400,6 +16403,7 @@ bool JOIN::rollup_init()
if (*group_tmp->item == item) if (*group_tmp->item == item)
{ {
item->maybe_null= 1; item->maybe_null= 1;
item->in_rollup= 1;
found_in_group= 1; found_in_group= 1;
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment