Commit 3125fed2 authored by unknown's avatar unknown

Merge of the fix for bug #9681 4.1->5.0

mysql-test/r/olap.result:
  Auto merged
mysql-test/t/olap.test:
  Auto merged
sql/sql_select.cc:
  Auto merged
parents 8b001e2a 6a97b079
......@@ -437,3 +437,16 @@ SELECT SQL_CALC_FOUND_ROWS a, SUM(b) FROM t1 GROUP BY a WITH ROLLUP LIMIT 1;
a SUM(b)
1 4
DROP TABLE t1;
CREATE TABLE t1 (a int(11) NOT NULL);
INSERT INTO t1 VALUES (1),(2);
SELECT a, SUM(a) m FROM t1 GROUP BY a WITH ROLLUP;
a m
1 1
2 2
NULL 3
SELECT * FROM ( SELECT a, SUM(a) m FROM t1 GROUP BY a WITH ROLLUP ) t2;
a m
1 1
2 2
NULL 3
DROP TABLE t1;
......@@ -178,3 +178,16 @@ SELECT a, SUM(b) FROM t1 GROUP BY a WITH ROLLUP LIMIT 1;
SELECT SQL_CALC_FOUND_ROWS a, SUM(b) FROM t1 GROUP BY a WITH ROLLUP LIMIT 1;
DROP TABLE t1;
#
# Tests for bug #9681: ROLLUP in subquery for derived table wiht
# a group by field declared as NOT NULL
#
CREATE TABLE t1 (a int(11) NOT NULL);
INSERT INTO t1 VALUES (1),(2);
SELECT a, SUM(a) m FROM t1 GROUP BY a WITH ROLLUP;
SELECT * FROM ( SELECT a, SUM(a) m FROM t1 GROUP BY a WITH ROLLUP ) t2;
DROP TABLE t1;
......@@ -7772,7 +7772,7 @@ Field* create_tmp_field_from_field(THD *thd, Field* org_field,
item->result_field= new_field;
else
new_field->field_name= name;
if (org_field->maybe_null())
if (org_field->maybe_null() || (item && item->maybe_null))
new_field->flags&= ~NOT_NULL_FLAG; // Because of outer join
if (org_field->type() == MYSQL_TYPE_VAR_STRING ||
org_field->type() == MYSQL_TYPE_VARCHAR)
......@@ -12753,7 +12753,19 @@ bool JOIN::rollup_init()
for (j=0 ; j < fields_list.elements ; j++)
rollup.fields[i].push_back(rollup.null_items[i]);
}
List_iterator_fast<Item> it(fields_list);
Item *item;
while ((item= it++))
{
ORDER *group_tmp;
for (group_tmp= group_list; group_tmp; group_tmp= group_tmp->next)
{
if (*group_tmp->item == item)
item->maybe_null= 1;
}
}
return 0;
}
......
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