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():
{
marker= 0;
maybe_null=null_value=with_sum_func=unsigned_flag=0;
in_rollup= 0;
decimals= 0; max_length= 0;
with_subselect= 0;
cmp_context= IMPOSSIBLE_RESULT;
......@@ -420,6 +421,7 @@ Item::Item(THD *thd, Item *item):
marker(item->marker),
decimals(item->decimals),
maybe_null(item->maybe_null),
in_rollup(item->in_rollup),
null_value(item->null_value),
unsigned_flag(item->unsigned_flag),
with_sum_func(item->with_sum_func),
......
......@@ -518,6 +518,8 @@ class Item {
int8 marker;
uint8 decimals;
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 unsigned_flag;
my_bool with_sum_func;
......
......@@ -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
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;
if (table->on_expr)
{
......@@ -9005,6 +9007,8 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top)
while ((tbl= it++))
{
tbl->embedding= table->embedding;
if (!tbl->embedding && !tbl->on_expr && tbl->table)
tbl->table->maybe_null= FALSE;
tbl->join_list= table->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,
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.
*/
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,
modify_item, convert_blob_length);
......@@ -13508,8 +13512,6 @@ static bool
list_contains_unique_index(TABLE *table,
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++)
{
if (keynr == table->s->primary_key ||
......@@ -13523,7 +13525,7 @@ list_contains_unique_index(TABLE *table,
key_part < key_part_end;
key_part++)
{
if (key_part->field->real_maybe_null() ||
if (key_part->field->maybe_null() ||
!find_func(key_part->field, data))
break;
}
......@@ -16337,6 +16339,7 @@ static bool change_group_ref(THD *thd, Item_func *expr, ORDER *group_list,
if (arg_changed)
{
expr->maybe_null= 1;
expr->in_rollup= 1;
*changed= TRUE;
}
}
......@@ -16400,6 +16403,7 @@ bool JOIN::rollup_init()
if (*group_tmp->item == item)
{
item->maybe_null= 1;
item->in_rollup= 1;
found_in_group= 1;
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