#At file:///export/home/didrik/mysqldev-next-mr/next-mr-bf-bug52123/ based on revid:marc.alff@stripped
3155 Tor Didriksen 2010-04-09
Bug#52123 Assertion failed: aggregator == aggr->Aggrtype(), file .\item_sum.cc, line 587
For certain queries we actually change the aggregator type:
e.g. first initialize and copy aggregator type in
Item_sum::Item_sum(THD *thd, Item_sum *item)
then change the type in prepare_sum_aggregators()
@ mysql-test/r/func_group.result
Add test case.
@ mysql-test/t/func_group.test
Add test case.
@ sql/item_sum.cc
Delete the old aggregator if the type changes.
@ sql/item_sum.h
set_aggregator() may be called multiple times.
modified:
mysql-test/r/func_group.result
mysql-test/t/func_group.test
sql/item_sum.cc
sql/item_sum.h
=== modified file 'mysql-test/r/func_group.result'
--- a/mysql-test/r/func_group.result 2009-12-22 16:23:13 +0000
+++ b/mysql-test/r/func_group.result 2010-04-09 11:20:40 +0000
@@ -1714,3 +1714,13 @@ NULL NULL NULL NULL NULL
drop table t1;
#
End of 5.1 tests
+#
+# Bug#52123 Assertion failed: aggregator == aggr->Aggrtype(),
+# file .\item_sum.cc, line 587
+#
+CREATE TABLE t1(a int, KEY(a));
+INSERT INTO t1 VALUES (1), (2);
+SELECT 1 FROM t1 ORDER BY AVG(DISTINCT a);
+1
+1
+DROP TABLE t1;
=== modified file 'mysql-test/t/func_group.test'
--- a/mysql-test/t/func_group.test 2009-11-24 15:26:13 +0000
+++ b/mysql-test/t/func_group.test 2010-04-09 11:20:40 +0000
@@ -1085,3 +1085,13 @@ drop table t1;
--echo #
--echo End of 5.1 tests
+--echo #
+--echo # Bug#52123 Assertion failed: aggregator == aggr->Aggrtype(),
+--echo # file .\item_sum.cc, line 587
+--echo #
+
+CREATE TABLE t1(a int, KEY(a));
+INSERT INTO t1 VALUES (1), (2);
+SELECT 1 FROM t1 ORDER BY AVG(DISTINCT a);
+DROP TABLE t1;
+
=== modified file 'sql/item_sum.cc'
--- a/sql/item_sum.cc 2010-03-31 14:05:33 +0000
+++ b/sql/item_sum.cc 2010-04-09 11:20:40 +0000
@@ -576,24 +576,27 @@ Item *Item_sum::set_arg(uint i, THD *thd
int Item_sum::set_aggregator(Aggregator::Aggregator_type aggregator)
{
- if (aggr)
+ /*
+ Dependent subselects may be executed multiple times, making
+ set_aggregator to be called multiple times. The aggregator type
+ will be the same, but it needs to be reset so that it is
+ reevaluated with the new dependent data.
+ This function may also be called multiple times during query optimization.
+ In this case, the type may change, so we delete the old aggregator,
+ and create a new one.
+ */
+ if (aggr && aggregator == aggr->Aggrtype())
{
- /*
- Dependent subselects may be executed multiple times, making
- set_aggregator to be called multiple times. The aggregator type
- will be the same, but it needs to be reset so that it is
- reevaluated with the new dependent data.
- */
- DBUG_ASSERT(aggregator == aggr->Aggrtype());
aggr->clear();
return FALSE;
}
+
+ delete aggr;
switch (aggregator)
{
case Aggregator::DISTINCT_AGGREGATOR:
aggr= new Aggregator_distinct(this);
break;
-
case Aggregator::SIMPLE_AGGREGATOR:
aggr= new Aggregator_simple(this);
break;
=== modified file 'sql/item_sum.h'
--- a/sql/item_sum.h 2010-03-31 14:05:33 +0000
+++ b/sql/item_sum.h 2010-04-09 11:20:40 +0000
@@ -441,10 +441,9 @@ public:
*/
virtual void no_rows_in_result()
{
- if (!aggr)
- set_aggregator(with_distinct ?
- Aggregator::DISTINCT_AGGREGATOR :
- Aggregator::SIMPLE_AGGREGATOR);
+ set_aggregator(with_distinct ?
+ Aggregator::DISTINCT_AGGREGATOR :
+ Aggregator::SIMPLE_AGGREGATOR);
reset();
}
virtual void make_unique() { force_copy_fields= TRUE; }
@@ -495,11 +494,10 @@ public:
quick_group= with_distinct ? 0 : 1;
}
- /**
+ /*
Set the type of aggregation : DISTINCT or not.
- Called when the final determination is done about the aggregation
- type and the object is about to be used.
+ May be called multiple times.
*/
int set_aggregator(Aggregator::Aggregator_type aggregator);
Attachment: [text/bzr-bundle] bzr/tor.didriksen@sun.com-20100409112040-ut4xbrynnvbgcrnl.bundle
| Thread |
|---|
| • bzr commit into mysql-next-mr-bugfixing branch (tor.didriksen:3155) Bug#52123 | Tor Didriksen | 14 Apr |