Bug #77194 Assertion `param.sort_length != 0' failed in sql/filesort.cc:361
Submitted: 29 May 2015 17:10 Modified: 19 Jun 2015 12:58
Reporter: Ramesh Sivaraman Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:5.6.23 OS:Linux (CentOS 7)
Assigned to: CPU Architecture:Any
Tags: debug

[29 May 2015 17:10] Ramesh Sivaraman
Description:
#0  0x00007f44064f2771 in __pthread_kill (threadid=<optimized out>, signo=6) at ../nptl/sysdeps/unix/sysv/linux/pthread_kill.c:61
#1  0x0000000000a980a6 in my_write_core (sig=6) at /sda/mysql-server-5.6/mysys/stacktrace.c:422
#2  0x00000000007277f0 in handle_fatal_signal (sig=6) at /sda/mysql-server-5.6/sql/signal_handler.cc:230
#3  <signal handler called>
#4  0x00007f44052fe5d7 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#5  0x00007f44052ffcc8 in __GI_abort () at abort.c:90
#6  0x00007f44052f7546 in __assert_fail_base (fmt=0x7f4405447128 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0xf8b661 "param.sort_length != 0", file=file@entry=0xf8b500 "/sda/mysql-server-5.6/sql/filesort.cc", line=line@entry=361, function=function@entry=0xf8bc40 <filesort(THD*, TABLE*, Filesort*, bool, unsigned long long*, unsigned long long*)::__PRETTY_FUNCTION__> "ha_rows filesort(THD*, TABLE*, Filesort*, bool, ha_rows*, ha_rows*)") at assert.c:92
#7  0x00007f44052f75f2 in __GI___assert_fail (assertion=0xf8b661 "param.sort_length != 0", file=0xf8b500 "/sda/mysql-server-5.6/sql/filesort.cc", line=361, function=0xf8bc40 <filesort(THD*, TABLE*, Filesort*, bool, unsigned long long*, unsigned long long*)::__PRETTY_FUNCTION__> "ha_rows filesort(THD*, TABLE*, Filesort*, bool, ha_rows*, ha_rows*)") at assert.c:101
#8  0x000000000091a7e7 in filesort (thd=0x7f43f5fee000, table=0x7f43e7c4f800, filesort=0x7f43e7d548d8, sort_positions=false, examined_rows=0x7f4406aa8868, found_rows=0x7f4406aa8860) at /sda/mysql-server-5.6/sql/filesort.cc:361
#9  0x00000000007a97eb in create_sort_index (thd=0x7f43f5fee000, join=0x7f43e7c1fb58, tab=0x7f43e7c20908) at /sda/mysql-server-5.6/sql/sql_executor.cc:3339
#10 0x00000000007a7321 in st_join_table::sort_table (this=0x7f43e7c20908) at /sda/mysql-server-5.6/sql/sql_executor.cc:2508
#11 0x00000000007a6df0 in join_init_read_record (tab=0x7f43e7c20908) at /sda/mysql-server-5.6/sql/sql_executor.cc:2382
#12 0x00000000007a46f7 in sub_select (join=0x7f43e7c1fb58, join_tab=0x7f43e7c20908, end_of_records=false) at /sda/mysql-server-5.6/sql/sql_executor.cc:1256
#13 0x00000000007a40e1 in do_select (join=0x7f43e7c1fb58) at /sda/mysql-server-5.6/sql/sql_executor.cc:933
#14 0x00000000007a203d in JOIN::exec (this=0x7f43e7c1fb58) at /sda/mysql-server-5.6/sql/sql_executor.cc:194
#15 0x00000000008027a7 in mysql_execute_select (thd=0x7f43f5fee000, select_lex=0x7f43f5ff0878, free_join=true) at /sda/mysql-server-5.6/sql/sql_select.cc:1100
#16 0x0000000000802aa3 in mysql_select (thd=0x7f43f5fee000, tables=0x7f43e7c1f3c0, wild_num=0, fields=..., conds=0x0, order=0x7f43f5ff0a40, group=0x7f43f5ff0978, having=0x0, select_options=2147748608, result=0x7f43e7c1fb30, unit=0x7f43f5ff0230, select_lex=0x7f43f5ff0878) at /sda/mysql-server-5.6/sql/sql_select.cc:1221
#17 0x0000000000800b2b in handle_select (thd=0x7f43f5fee000, result=0x7f43e7c1fb30, setup_tables_done_option=0) at /sda/mysql-server-5.6/sql/sql_select.cc:110
#18 0x00000000007da980 in execute_sqlcom_select (thd=0x7f43f5fee000, all_tables=0x7f43e7c1f3c0) at /sda/mysql-server-5.6/sql/sql_parse.cc:5103
#19 0x00000000007d3730 in mysql_execute_command (thd=0x7f43f5fee000) at /sda/mysql-server-5.6/sql/sql_parse.cc:2649
#20 0x00000000007dd54a in mysql_parse (thd=0x7f43f5fee000, rawbuf=0x7f43e7c1f010 "SELECT COUNT(DISTINCT a)FROM t1 GROUP BY b", length=42, parser_state=0x7f4406aa9e70) at /sda/mysql-server-5.6/sql/sql_parse.cc:6357
#21 0x00000000007d06bc in dispatch_command (command=COM_QUERY, thd=0x7f43f5fee000, packet=0x7f43ef3e1001 "", packet_length=42) at /sda/mysql-server-5.6/sql/sql_parse.cc:1332
#22 0x00000000007cf7ab in do_command (thd=0x7f43f5fee000) at /sda/mysql-server-5.6/sql/sql_parse.cc:1034
#23 0x0000000000797b3d in do_handle_one_connection (thd_arg=0x7f43f5fee000) at /sda/mysql-server-5.6/sql/sql_connect.cc:982
#24 0x0000000000797626 in handle_one_connection (arg=0x7f43f5fee000) at /sda/mysql-server-5.6/sql/sql_connect.cc:898
#25 0x0000000000b5d7f0 in pfs_spawn_thread (arg=0x7f4400ffe600) at /sda/mysql-server-5.6/storage/perfschema/pfs.cc:1860
#26 0x00007f44064eddf5 in start_thread (arg=0x7f4406aab700) at pthread_create.c:308
#27 0x00007f44053bf1ad in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:113

How to repeat:
DROP DATABASE test;CREATE DATABASE test;USE test;
CREATE TABLE t1(a CHAR(0),b CHAR(0) NOT NULL,c int);
INSERT INTO t1(b,c)VALUES (0,0),(0,0),(0,0);
INSERT INTO t1(a,b)VALUES (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0);
REPLACE INTO t1(a)SELECT 3 FROM t1,t1 AS c;
insert INTO t1(b)select a as b FROM t1;
SELECT COUNT(DISTINCT a)FROM t1 GROUP BY b;

$ vi {epoch}_mybase # Update base path in this file (the only change
required!). For non-binary distribution please update SOURCE_DIR
location also.
$ ./{epoch}_init # Initializes the data dir
$ ./{epoch}_start # Starts mysqld
$ ./{epoch}_cl # To check mysqld is up
$ ./{epoch}_run # Run the testcase with pquery binary(produces
output)
$ vi /dev/shm/{epoch}/error.log.out # Verify the error log
$ ./{epoch}_gdb # Brings you to a gdb prompt attached to correct
mysqld
& generated core
$ ./{epoch}_parse_core # Create {epoch}_STD.gdb and {epoch}_FULL.gdb;
standard and full var gdb stack traces
etc.
[29 May 2015 17:11] Ramesh Sivaraman
Testcase bundle

Attachment: 1432888901_bug_bundle.tar.gz (application/gzip, text), 1013.27 KiB.

[29 May 2015 22:17] MySQL Verification Team
C:\dbs>c:\dbs\5.6\bin\mysql -uroot --port=3560 --debug-info --prompt="mysql 5.6 > "
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.26-debug Source distribution PULL: 2015/05/04

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql 5.6 > DROP DATABASE test;CREATE DATABASE test;USE test;
Query OK, 1 row affected (0.09 sec)

Query OK, 1 row affected (0.02 sec)

Database changed
mysql 5.6 > CREATE TABLE t1(a CHAR(0),b CHAR(0) NOT NULL,c int);
Query OK, 0 rows affected (0.25 sec)

mysql 5.6 > INSERT INTO t1(b,c)VALUES (0,0),(0,0),(0,0);
Query OK, 3 rows affected, 3 warnings (0.06 sec)
Records: 3  Duplicates: 0  Warnings: 3

mysql 5.6 > INSERT INTO t1(a,b)VALUES (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0);
Query OK, 20 rows affected, 40 warnings (0.08 sec)
Records: 20  Duplicates: 0  Warnings: 40

mysql 5.6 > REPLACE INTO t1(a)SELECT 3 FROM t1,t1 AS c;
Query OK, 529 rows affected, 530 warnings (0.17 sec)
Records: 529  Duplicates: 0  Warnings: 530

mysql 5.6 > insert INTO t1(b)select a as b FROM t1;
Query OK, 552 rows affected, 3 warnings (0.25 sec)
Records: 552  Duplicates: 0  Warnings: 3

mysql 5.6 > SELECT COUNT(DISTINCT a)FROM t1 GROUP BY b;
ERROR 2013 (HY000): Lost connection to MySQL server during query
[29 May 2015 22:21] MySQL Verification Team
2015-05-29 19:14:48 6024 [Note] C:\dbs\5.6\bin\mysqld: ready for connections.
Version: '5.6.26-debug'  socket: ''  port: 3560  Source distribution PULL: 2015/05/04
Assertion failed: param.sort_length != 0, file C:\2015may04\mysql-5.6\sql\filesort.cc, line 369
22:16:52 UTC - mysqld got exception 0x80000003 ;
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 = 67956 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0xb9b33522a0
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...
7ff6cde896c5    mysqld.exe!my_sigabrt_handler()[my_thr_init.c:458]
7ff6ce46445f    mysqld.exe!raise()[winsig.c:594]
7ff6ce471270    mysqld.exe!abort()[abort.c:82]
7ff6ce461a2b    mysqld.exe!_wassert()[assert.c:380]
7ff6cdd02dc8    mysqld.exe!filesort()[filesort.cc:369]
7ff6cdd55aac    mysqld.exe!create_sort_index()[sql_executor.cc:3339]
7ff6cdd50253    mysqld.exe!st_join_table::sort_table()[sql_executor.cc:2508]
7ff6cdd4dc02    mysqld.exe!join_init_read_record()[sql_executor.cc:2382]
7ff6cdd4cb12    mysqld.exe!sub_select()[sql_executor.cc:1256]
7ff6cdd5277c    mysqld.exe!do_select()[sql_executor.cc:933]
7ff6cdd50e95    mysqld.exe!JOIN::exec()[sql_executor.cc:194]
7ff6cdcd235e    mysqld.exe!mysql_execute_select()[sql_select.cc:1103]
7ff6cdcc51a9    mysqld.exe!mysql_select()[sql_select.cc:1221]
7ff6cdcc4dbd    mysqld.exe!handle_select()[sql_select.cc:110]
7ff6cdad3c23    mysqld.exe!execute_sqlcom_select()[sql_parse.cc:5134]
7ff6cdac56c5    mysqld.exe!mysql_execute_command()[sql_parse.cc:2656]
7ff6cdac415a    mysqld.exe!mysql_parse()[sql_parse.cc:6386]
7ff6cdacd7a2    mysqld.exe!dispatch_command()[sql_parse.cc:1343]
7ff6cdacc865    mysqld.exe!do_command()[sql_parse.cc:1037]
7ff6cdb1dc02    mysqld.exe!do_handle_one_connection()[sql_connect.cc:982]
7ff6cdb1da32    mysqld.exe!handle_one_connection()[sql_connect.cc:899]
7ff6ce33db95    mysqld.exe!pfs_spawn_thread()[pfs.cc:1862]
7ff6cde87c66    mysqld.exe!pthread_start()[my_winthread.c:62]
7ff6ce474ab5    mysqld.exe!_callthreadstartex()[threadex.c:376]
7ff6ce474d07    mysqld.exe!_threadstartex()[threadex.c:359]
7ffa72e313d2    KERNEL32.DLL!BaseThreadInitThunk()
7ffa739e5444    ntdll.dll!RtlUserThreadStart()

Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (b9b3609890): SELECT COUNT(DISTINCT a)FROM t1 GROUP BY bConnection ID (thread ID): 1
[29 May 2015 22:26] MySQL Verification Team
C:\dbs>c:\dbs\5.6\bin\mysql -uroot --port=3560 --debug-info --prompt="mysql 5.6 > "
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.26 Source distribution PULL: 2015/05/04

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql 5.6 > DROP DATABASE test;CREATE DATABASE test;USE test;
Query OK, 1 row affected (0.17 sec)

Query OK, 1 row affected (0.00 sec)

Database changed
mysql 5.6 > CREATE TABLE t1(a CHAR(0),b CHAR(0) NOT NULL,c int);
Query OK, 0 rows affected (0.19 sec)

mysql 5.6 > INSERT INTO t1(b,c)VALUES (0,0),(0,0),(0,0);
Query OK, 3 rows affected, 3 warnings (0.03 sec)
Records: 3  Duplicates: 0  Warnings: 3

mysql 5.6 > INSERT INTO t1(a,b)VALUES (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0);
Query OK, 20 rows affected, 40 warnings (0.06 sec)
Records: 20  Duplicates: 0  Warnings: 40

mysql 5.6 > REPLACE INTO t1(a)SELECT 3 FROM t1,t1 AS c;
Query OK, 529 rows affected, 530 warnings (0.03 sec)
Records: 529  Duplicates: 0  Warnings: 530

mysql 5.6 > insert INTO t1(b)select a as b FROM t1;
Query OK, 552 rows affected, 3 warnings (0.05 sec)
Records: 552  Duplicates: 0  Warnings: 3

mysql 5.6 > SELECT COUNT(DISTINCT a)FROM t1 GROUP BY b;
+-------------------+
| COUNT(DISTINCT a) |
+-------------------+
|                 1 |
+-------------------+
1 row in set (0.00 sec)
[29 May 2015 22:39] MySQL Verification Team
Thank you for the bug report. Debug version of 5.5 and 5.7 not affected I was able to repeat only with 5.6 debug version.
[12 Jun 2015 10:41] Tor Didriksen
Posted by developer:
 
This affects debug versions only.
The bug was fixed (for order-by-with-limit) in 5.6.22 by the patch for
Bug #19660891 HANDLE_FATAL_SIGNAL (SIG=11) IN QUEUE_INSERT

Merge-sort uses the same compare function,
and *does* handle zero-length keys during merge sort.
So the DBUG_ASSERT is wrong.
[19 Jun 2015 12:58] Tor Didriksen
Duplicate of
Bug #74008 	handle_fatal_signal (sig=11) in queue_insert