Bug #57687 crash when reporting duplicate group_key error and utf8
Submitted: 23 Oct 2010 15:34 Modified: 30 Dec 2010 18:49
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: General Severity:S1 (Critical)
Version:5.5.8 OS:Any
Assigned to: Alexander Barkov CPU Architecture:Any
Tags: group_key, regression

[23 Oct 2010 15:34] Shane Bester
Description:
5.5.8 crashes with stack trace:

Invalid read of size 4
at: key_unpack (key.cc:367)
by: handler::print_keydup_error (handler.cc:2621)
by: handler::print_error (handler.cc:2672)
by: create_myisam_from_heap (sql_select.cc:11173)
by: end_update (sql_select.cc:12856)
by: flush_cached_records (sql_select.cc:11956)
by: sub_select_cache (sql_select.cc:11495)
by: sub_select (sql_select.cc:11642)
by: do_select (sql_select.cc:11431)
by: JOIN::exec (sql_select.cc:1968)
by: mysql_select (sql_select.cc:2568)
by: handle_select (sql_select.cc:296)
by: execute_sqlcom_select (sql_parse.cc:4464)
by: mysql_execute_command (sql_parse.cc:2066)
by: mysql_parse (sql_parse.cc:5500)
by: dispatch_command (sql_parse.cc:1030)
by: do_command (sql_parse.cc:770)
by: do_handle_one_connection (sql_connect.cc:745)
by: handle_one_connection (sql_connect.cc:684)

When using "set names latin1", the result is this:
ERROR 1062 (23000): Duplicate entry '107374182410737418241' for key 'group_key'

How to repeat:
drop table if exists `g1`;
create table `g1`(`a` int) engine=myisam ;
insert into `g1` values (0),(0),(1),(0),(0);
set names utf8; 
select count(*) from `g1`,`g1` `g2` 
group by insert('',`g2`.`a`,`g1`.`a`,(@@global.max_binlog_size));
[23 Oct 2010 15:57] Valeriy Kravchuk
Verified on Mac OS X:

macbook-pro:5.5 openxs$ bin/mysql -uroot test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.5.7-rc-debug Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> drop table if exists `g1`;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> create table `g1`(`a` int) engine=myisam ;
Query OK, 0 rows affected (0.06 sec)

mysql> insert into `g1` values (0),(0),(1),(0),(0);
Query OK, 5 rows affected (0.00 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> set names utf8; 
Query OK, 0 rows affected (0.00 sec)

mysql> select count(*) from `g1`,`g1` `g2` 
    -> group by insert('',`g2`.`a`,`g1`.`a`,(@@global.max_binlog_size));
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql> 101023 18:56:20 mysqld_safe mysqld restarted

mysql> exit
Bye
macbook-pro:5.5 openxs$ tail -80 var/macbook-pro.err 
101023 18:56:20 - mysqld got signal 10 ;
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 = 337937 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd: 0x1038e00
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 = 0xb077ef34 thread_stack 0x30000
0   mysqld                              0x005c37f1 my_print_stacktrace + 44
1   mysqld                              0x001058fa handle_segfault + 884
2   libSystem.B.dylib                   0x940472bb _sigtramp + 43
3   ???                                 0xffffffff 0x0 + 4294967295
4   mysqld                              0x0025a1cf _ZN7handler18print_keydup_errorEjPKc + 195
5   mysqld                              0x0025a66e _ZN7handler11print_errorEii + 990
6   mysqld                              0x001910cd _Z23create_myisam_from_heapP3THDP5TABLEP15TMP_TABLE_PARAMib + 197
7   mysqld                              0x0019216a _ZN4JOIN17rollup_write_dataEjP5TABLE + 2572
8   mysqld                              0x0018f4c2 _Z18error_if_full_joinP4JOIN + 3878
9   mysqld                              0x0018f5b8 _Z16sub_select_cacheP4JOINP13st_join_tableb + 44
10  mysqld                              0x0018e491 _Z10sub_selectP4JOINP13st_join_tableb + 65
11  mysqld                              0x0019e4ba _ZN4JOIN9join_freeEv + 1610
12  mysqld                              0x001aea73 _ZN4JOIN4execEv + 2635
13  mysqld                              0x001ab0cb _Z12mysql_selectP3THDPPP4ItemP10TABLE_LISTjR4ListIS1_ES2_jP8st_orderSB_S2_SB_yP13select_resultP18st_select_lex_unitP13st_select_lex + 797
14  mysqld                              0x001b0597 _Z13handle_selectP3THDP3LEXP13select_resultm + 547
15  mysqld                              0x00116fd3 _Z15update_precheckP3THDP10TABLE_LIST + 1075
16  mysqld                              0x0011979a _Z21mysql_execute_commandP3THD + 3058
17  mysqld                              0x0012136c _Z11mysql_parseP3THDPcjP12Parser_state + 624
18  mysqld                              0x00121efe _Z16dispatch_command19enum_server_commandP3THDPcj + 2632
19  mysqld                              0x00123307 _Z10do_commandP3THD + 621
20  mysqld                              0x001109e2 _Z24do_handle_one_connectionP3THD + 512
21  mysqld                              0x00110ad5 handle_one_connection + 37
22  libSystem.B.dylib                   0x9400c095 _pthread_start + 321
23  libSystem.B.dylib                   0x9400bf52 thread_start + 34
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 0x109d010 = select count(*) from `g1`,`g1` `g2` 
group by insert('',`g2`.`a`,`g1`.`a`,(@@global.max_binlog_size))
thd->thread_id=7
thd->killed=NOT_KILLED
[23 Oct 2010 16:00] Valeriy Kravchuk
No crash with 5.1:

macbook-pro:5.1 openxs$ bin/mysql -uroot test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.52-debug Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> drop table if exists `g1`;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> create table `g1`(`a` int) engine=myisam ;
Query OK, 0 rows affected (0.23 sec)

mysql> insert into `g1` values (0),(0),(1),(0),(0);
Query OK, 5 rows affected (0.00 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> set names utf8; 
Query OK, 0 rows affected (0.00 sec)

mysql> select count(*) from `g1`,`g1` `g2` 
    -> group by insert('',`g2`.`a`,`g1`.`a`,(@@global.max_binlog_size));
ERROR 1062 (23000): Duplicate entry '107374182410737418241' for key 'group_key'

So, this is a regression bug.
[13 Nov 2010 0:52] Paul DuBois
Noted in 5.5.8 changelog.
[13 Nov 2010 0:52] Paul DuBois
Changelog entry:

Under rare circumstances, a GROUP BY query could cause a server crash
when grouping by long character strings.
[16 Dec 2010 21:46] Bugs System
Pushed into mysql-trunk 5.6.1 (revid:alexander.nozdrin@oracle.com-20101216181820-7afubgk2fmuv9qsb) (version source revid:alexander.nozdrin@oracle.com-20101216173826-ze3y5h450sksotrh) (merge vers: 5.6.1) (pib:23)
[16 Dec 2010 22:25] Bugs System
Pushed into mysql-5.5 5.5.9 (revid:jonathan.perkin@oracle.com-20101216101358-fyzr1epq95a3yett) (version source revid:jonathan.perkin@oracle.com-20101216101358-fyzr1epq95a3yett) (merge vers: 5.5.9) (pib:24)
[20 Dec 2010 10:03] Tor Didriksen
Introduced this:
Bug #59021  Valgrind warning in key_unpack()
[22 Dec 2010 21:29] Bugs System
Pushed into mysql-trunk 5.6.1 (revid:alexander.nozdrin@oracle.com-20101222212842-y0t3ibtd32wd9qaw) (version source revid:alexander.nozdrin@oracle.com-20101222212842-y0t3ibtd32wd9qaw) (merge vers: 5.6.1) (pib:24)
[29 Dec 2010 12:53] Bugs System
Pushed into mysql-5.5 5.5.9 (revid:alexander.nozdrin@oracle.com-20101229113652-km2v993aurv7h79j) (version source revid:alexander.nozdrin@oracle.com-20101229113132-uonlbcc2uopff8yb) (merge vers: 5.5.9) (pib:24)
[19 Mar 2013 9:45] MySQL Verification Team
removing private flag, this is fixed long ago.