Bug #52171 distinct aggregates on unsigned decimal fields trigger assertions
Submitted: 18 Mar 2010 10:05 Modified: 30 Mar 2011 17:01
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 OS:Any
Assigned to: Mats Kindahl CPU Architecture:Any
Tags: assertion, decimal, regression

[18 Mar 2010 10:05] Shane Bester
Description:
Version: '5.6.99-m4-debug'  socket: ''  port: 3306  Source distribution
Assertion failed: scale >= 0 && precision > 0 && scale <= precision, file decimal.c, line 1443

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!decimal_bin_size()[decimal.c:1443]
mysqld.exe!my_decimal_get_binary_size()[my_decimal.h:230]
mysqld.exe!Field_new_decimal::Field_new_decimal()[field.cc:2537]
mysqld.exe!make_field()[field.cc:9783]
mysqld.exe!create_virtual_tmp_table()[sql_select.cc:10706]
mysqld.exe!Aggregator_distinct::setup()[item_sum.cc:910]
mysqld.exe!Item_sum::aggregator_setup()[item_sum.h:476]
mysqld.exe!setup_sum_funcs()[sql_select.cc:15771]
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]

5.1.45 was not affected.

How to repeat:
#on debug build run:

drop table if exists `t1`;
create table `t1`(`a` decimal(4,4)unsigned)engine=myisam;
insert into`t1` values (0);
select avg(distinct `a`) from `t1`;
select sum(distinct `a`) from `t1`;
[18 Mar 2010 10:25] Sveta Smirnova
Thank you for the report.

Verified as described.
[28 Mar 2010 12:02] Guilhem Bichot
regression source (found by bzrfind and confirmed manually):
Mats Kindahl	2009-12-14
      revision-id:mats@sun.com-20091214110455-g6lw2yfiu14prdnu
      WL#5151: Conversion between different types when replicating
[20 Sep 2010 22:00] 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/118648

3086 Mats Kindahl	2010-09-20
      BUG#52171: distinct aggregates on unsigned decimal fields trigger assertions
      
      When creating virtual tables, make_field() will create a Field_new_decimal,
      with FIELDFLAG_DECIMAL set, which unfortunately means that the field always
      is considered signed, which in turns offsets the computation of precision
      from length.
      
      This patch solves this by not setting the FIELDFLAG_DECIMAL, which instead
      will be set by make_field() if the field is indicated as unsigned.
[23 Sep 2010 18:35] Mats Kindahl
Patch queued to mysql-5.5-bugfixing, mysql-trunk-bugfixing, and mysql-next-mr-bugfixing.
[30 Mar 2011 17:01] Paul DuBois
Noted in 5.6.2 changelog.

DISTINCT aggregates on DECIMAL UNSIGNED fields could trigger an
assertion. 

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