diff options
-rw-r--r-- | mysql-test/r/func_group.result | 10 | ||||
-rw-r--r-- | mysql-test/t/func_group.test | 11 | ||||
-rw-r--r-- | sql/item_sum.cc | 21 | ||||
-rw-r--r-- | sql/item_sum.h | 12 |
4 files changed, 38 insertions, 16 deletions
diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result index 1f6e01da0c9..2716a06b22f 100644 --- a/mysql-test/r/func_group.result +++ b/mysql-test/r/func_group.result @@ -1739,6 +1739,16 @@ SELECT RELEASE_LOCK('aaaaaaaaaaaaaaaaa'); # 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; +# # Bug#55648: Server crash on MIN/MAX on maximum time value # CREATE TABLE t1(c1 TIME NOT NULL); diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test index 2c4a7f4c7b1..a0527f70b25 100644 --- a/mysql-test/t/func_group.test +++ b/mysql-test/t/func_group.test @@ -1120,6 +1120,17 @@ SELECT RELEASE_LOCK('aaaaaaaaaaaaaaaaa'); --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; + --echo # --echo # Bug#55648: Server crash on MIN/MAX on maximum time value --echo # diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 0fd526184c4..adfa1ea66f0 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -556,24 +556,27 @@ Item *Item_sum::set_arg(uint i, THD *thd, Item *new_val) 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; diff --git a/sql/item_sum.h b/sql/item_sum.h index 81e5e10fffa..4e2334b6c3b 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -461,10 +461,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); aggregator_clear(); } virtual void make_unique() { force_copy_fields= TRUE; } @@ -515,11 +514,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); |