Commit 6736d404 authored by unknown's avatar unknown

Bug #31156: mysqld: item_sum.cc:918: virtual bool

  Item_sum_distinct::setup(THD*): Assertion

There was an assertion to detect a bug in ROLLUP
implementation. However the assertion is not true
when used in a subquery context with non-cacheable
statements.
Fixed by turning the assertion to accepted case
(just like it's done for the other aggregate functions). 


mysql-test/r/func_group.result:
  Bug #31156: test case
mysql-test/t/func_group.test:
  Bug #31156: test case
sql/item_sum.cc:
  Bug #31156: make it OK to call setup() several times:
   done for (e.g.) scalar subquery
parent 554d405d
......@@ -1377,4 +1377,14 @@ SELECT MIN(a), MIN(b) FROM t5 WHERE a = 1 and b > 1;
MIN(a) MIN(b)
1 2
DROP TABLE t1, t2, t3, t4, t5;
CREATE TABLE t1 (a INT);
INSERT INTO t1 values (),(),();
SELECT (SELECT SLEEP(0) FROM t1 ORDER BY AVG(DISTINCT a) ) as x FROM t1
GROUP BY x;
x
0
SELECT 1 FROM t1 GROUP BY (SELECT SLEEP(0) FROM t1 ORDER BY AVG(DISTINCT a) );
1
1
DROP TABLE t1;
End of 5.0 tests
......@@ -860,5 +860,18 @@ SELECT MIN(a), MIN(b) FROM t5 WHERE a = 1 and b > 1;
DROP TABLE t1, t2, t3, t4, t5;
#
# Bug #31156: mysqld: item_sum.cc:918:
# virtual bool Item_sum_distinct::setup(THD*): Assertion
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 values (),(),();
SELECT (SELECT SLEEP(0) FROM t1 ORDER BY AVG(DISTINCT a) ) as x FROM t1
GROUP BY x;
SELECT 1 FROM t1 GROUP BY (SELECT SLEEP(0) FROM t1 ORDER BY AVG(DISTINCT a) );
DROP TABLE t1;
###
--echo End of 5.0 tests
......@@ -905,7 +905,9 @@ bool Item_sum_distinct::setup(THD *thd)
List<create_field> field_list;
create_field field_def; /* field definition */
DBUG_ENTER("Item_sum_distinct::setup");
DBUG_ASSERT(tree == 0);
/* It's legal to call setup() more than once when in a subquery */
if (tree)
return FALSE;
/*
Virtual table and the tree are created anew on each re-execution of
......@@ -2443,6 +2445,7 @@ bool Item_sum_count_distinct::setup(THD *thd)
/*
Setup can be called twice for ROLLUP items. This is a bug.
Please add DBUG_ASSERT(tree == 0) here when it's fixed.
It's legal to call setup() more than once when in a subquery
*/
if (tree || table || tmp_table_param)
return FALSE;
......
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