Bug #52123 Assertion failed: aggregator == aggr->Aggrtype(), file .\item_sum.cc, line 587
Submitted: 17 Mar 2010 6:17 Modified: 1 Mar 2011 1:22
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Data Types Severity:S1 (Critical)
Version:5.6.99-m4-debug, 6.0-codebase-bugfixing OS:Any
Assigned to: Tor Didriksen CPU Architecture:Any
Tags: regression

[17 Mar 2010 6:17] Shane Bester
Description:
When ordering by avg distinct on a decimal column, we get assertion:

Version: '5.6.99-m4-debug'  socket: ''  port: 3306  Source distribution
Assertion failed: aggregator == aggr->Aggrtype(), file .\item_sum.cc, line 587

mysqld.exe!my_sigabrt_handler()[my_thr_init.c:519]
mysqld.exe!raise()[winsig.c:590]
mysqld.exe!abort()[abort.c:71]
mysqld.exe!_wassert()[assert.c:212]
mysqld.exe!Item_sum::set_aggregator()[item_sum.cc:587]
mysqld.exe!prepare_sum_aggregators()[sql_select.cc:15786]
mysqld.exe!JOIN::exec()[sql_select.cc:2167]
mysqld.exe!mysql_select()[sql_select.cc:2508]
mysqld.exe!handle_select()[sql_select.cc:271]
mysqld.exe!execute_sqlcom_select()[sql_parse.cc:4703]
mysqld.exe!mysql_execute_command()[sql_parse.cc:2191]
mysqld.exe!mysql_parse()[sql_parse.cc:5735]
mysqld.exe!dispatch_command()[sql_parse.cc:1024]
mysqld.exe!do_command()[sql_parse.cc:710]
mysqld.exe!do_handle_one_connection()[sql_connect.cc:1174]
mysqld.exe!handle_one_connection()[sql_connect.cc:1113]
mysqld.exe!pthread_start()[my_winthread.c:61]
mysqld.exe!_callthreadstartex()[threadex.c:348]
mysqld.exe!_threadstartex()[threadex.c:331]
kernel32.dll!FlsSetValue()

5.1.46-debug was not affected.
explain shows:  "Using index for group-by (scanning)"

How to repeat:
#on debug build:

drop table if exists `t1`;
create table `t1`(`a` decimal(20,20),key(`a`)) engine=myisam;
insert into `t1` values (1),(1);
select 1 from `t1` order by avg(distinct `a`);
[17 Mar 2010 8:01] Valeriy Kravchuk
Verified just as described on Ubuntu:

Version: '5.6.99-m4-debug'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
mysqld: item_sum.cc:587: int Item_sum::set_aggregator(Aggregator::Aggregator_type): Assertion `aggregator == aggr->Aggrtype()' failed.
100317  9:57:59 - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.

key_buffer_size=8388608
read_buffer_size=131072
max_used_connections=1
max_threads=151
thread_count=1
connection_count=1
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 337841 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd: 0x93ec1a0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0xa90203b0 thread_stack 0x30000
/home2/openxs/dbs/next-mr/libexec/mysqld(my_print_stacktrace+0x26)[0x877fd41]
/home2/openxs/dbs/next-mr/libexec/mysqld(handle_segfault+0x2ee)[0x82c7452]
[0xb7f65420]
/lib/tls/i686/cmov/libc.so.6(abort+0x101)[0xb7da8a01]
/lib/tls/i686/cmov/libc.so.6(__assert_fail+0xee)[0xb7da010e]
/home2/openxs/dbs/next-mr/libexec/mysqld(_ZN8Item_sum14set_aggregatorEN10Aggregator15Aggregator_typeE+0x51)[0x820dfc7]
/home2/openxs/dbs/next-mr/libexec/mysqld[0x8350a10]
/home2/openxs/dbs/next-mr/libexec/mysqld(_ZN4JOIN4execEv+0x1a20)[0x8374832]
/home2/openxs/dbs/next-mr/libexec/mysqld(_Z12mysql_selectP3THDPPP4ItemP10TABLE_LISTjR4ListIS1_ES2_jP8st_orderSB_S2_SB_yP13select_resultP18st_select_lex_unitP13st_select_lex+0x30d)[0x836fce9]
/home2/openxs/dbs/next-mr/libexec/mysqld(_Z13handle_selectP3THDP3LEXP13select_resultm+0x1ec)[0x83753d6]
/home2/openxs/dbs/next-mr/libexec/mysqld[0x82d8d4b]
/home2/openxs/dbs/next-mr/libexec/mysqld(_Z21mysql_execute_commandP3THD+0x9c1)[0x82daa81]
/home2/openxs/dbs/next-mr/libexec/mysqld(_Z11mysql_parseP3THDPKcjPS2_+0x229)[0x82e2cd1]
/home2/openxs/dbs/next-mr/libexec/mysqld(_Z16dispatch_command19enum_server_commandP3THDPcj+0x9e0)[0x82e3846]
/home2/openxs/dbs/next-mr/libexec/mysqld(_Z10do_commandP3THD+0x241)[0x82e4da5]
/home2/openxs/dbs/next-mr/libexec/mysqld(_Z24do_handle_one_connectionP3THD+0x15b)[0x82d2001]
/home2/openxs/dbs/next-mr/libexec/mysqld(handle_one_connection+0x25)[0x82d20bf]
/lib/tls/i686/cmov/libpthread.so.0[0xb7f444fb]
/lib/tls/i686/cmov/libc.so.6(clone+0x5e)[0xb7e52e5e]
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 0x945f820 = select 1 from `t1` order by avg(distinct `a`)
[24 Mar 2010 22:13] Patrick Crews
This occurs when using any query with the pattern:
SELECT <aggregate_function>( DISTINCT <field_name>) as <field_alias>
FROM <table>
ORDER BY <field_alias>
[28 Mar 2010 12:11] Guilhem Bichot
regression source:
tor.didriksen@sun.com-20091028100730-ml3e9cnrl3xjx6f8
Bug#48060 Memory leak - Item::val_bool() (item.cc:184) from optimizer_subquery grammar
(found by bzrfind; it's expected, this is the revision which added the failing assertion to code).
[30 Mar 2010 7:55] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/104598

3144 Tor Didriksen	2010-03-30
      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/subselect3.result
        Add test case.
     @ mysql-test/t/subselect3.test
        Add test case.
     @ sql/item_sum.cc
        Delete the old aggregator if the type changes.
[7 Apr 2010 7:08] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/105123

3144 Tor Didriksen	2010-04-07
      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/subselect3.result
        Add test case.
     @ mysql-test/t/subselect3.test
        Add test case.
     @ sql/item_sum.cc
        Delete the old aggregator if the type changes.
[9 Apr 2010 11:21] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/105295

3144 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.
[14 Apr 2010 9:03] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/105611

3153 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.
[14 Apr 2010 10:42] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/105625

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.
[15 Apr 2010 6:08] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/105685

3156 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.
[15 Apr 2010 7:02] Tor Didriksen
Pushed to
bzr+ssh://bk-internal.mysql.com/bzrroot/server/mysql-6.0-codebase-bugfixing/
bzr+ssh://bk-internal.mysql.com/bzrroot/server/mysql-next-mr-bugfixing/
[27 Apr 2010 9:44] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20100427094135-5s49ecp3ckson6e2) (version source revid:alik@sun.com-20100427093843-uekr85qkd7orx12t) (merge vers: 6.0.14-alpha) (pib:16)
[27 Apr 2010 9:50] Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20100427094036-38frbg3famdlvjup) (version source revid:alik@sun.com-20100427093825-92wc8b22d4yg34ju) (pib:16)
[4 Aug 2010 8:05] Bugs System
Pushed into mysql-trunk 5.6.1-m4 (revid:alik@ibmvm-20100804080001-bny5271e65xo34ig) (version source revid:alik@sun.com-20100427095914-pzlxbqjjtnngxmf0) (merge vers: 5.6.99-m4) (pib:18)
[4 Aug 2010 8:21] Bugs System
Pushed into mysql-trunk 5.6.1-m4 (revid:alik@ibmvm-20100804081533-c1d3rbipo9e8rt1s) (version source revid:alik@sun.com-20100427095914-pzlxbqjjtnngxmf0) (merge vers: 5.6.99-m4) (pib:18)
[5 Aug 2010 5:53] Tor Didriksen
Patric Crews described the kind of queries affected.
A debug server would crash, a non-debug server might return wrong results.
[14 Dec 2010 23:45] Paul DuBois
Bug does not appear in any released 5.6.x version, so no changelog entry needed after all.
[23 Jan 2011 16:24] MySQL Verification Team
see bug #59679
[2 Feb 2011 9:19] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/130188

3295 Tor Didriksen	2011-02-02
      Backport of fix for Bug#52123
[2 Feb 2011 9:22] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/130189

3589 Tor Didriksen	2011-02-02 [merge]
      Empty merge of Backport of fix for Bug#52123
[2 Feb 2011 9:22] Bugs System
Pushed into mysql-trunk 5.6.2 (revid:tor.didriksen@oracle.com-20110202092141-9pvozmc78k2cgbgj) (version source revid:tor.didriksen@oracle.com-20110202092141-9pvozmc78k2cgbgj) (merge vers: 5.6.2) (pib:24)
[2 Feb 2011 9:22] Bugs System
Pushed into mysql-5.5 5.5.10 (revid:tor.didriksen@oracle.com-20110202091844-kt1gsyymbonb8fwi) (version source revid:tor.didriksen@oracle.com-20110202091844-kt1gsyymbonb8fwi) (merge vers: 5.5.10) (pib:24)
[2 Feb 2011 9:24] Tor Didriksen
Backported and pushed to 5.5
[2 Feb 2011 9:41] Tor Didriksen
Asking for re-triage, since it was backported from trunk to 5.5

http://bugs.mysql.com/bug.php?id=59679
is a duplicate of this one.
[1 Mar 2011 1:22] Paul DuBois
Noted in 5.5.10 changelog.

Sorting using ORDER BY AVG(DISTINCT decimal_col) caused a server 
crash or incorrect results. 

CHANGESET - http://lists.mysql.com/commits/130189