Bug #48884 Assertion failed in int join_read_key2(JOIN_TAB*, TABLE*, TABLE_REF*)
Submitted: 18 Nov 2009 21:14 Modified: 9 Feb 2010 8:47
Reporter: Patrick Crews Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:5.0+ OS:Any
Assigned to: Assigned Account CPU Architecture:Any
Tags: assertion, crashing bug

[18 Nov 2009 21:14] Patrick Crews
Description:
Crashing bug in all versions of the server (5.0+).  Note:  The example query here is but one of many that hit this failure.  

SELECT `date_key`  
FROM C  
WHERE ( `int_key`  , `int_key`  )  IN (  
SELECT `int_key`  , `pk`  
FROM CC  )  XOR '2001-03-28'  ;

produces this partial crash output (full output attached as separate file):
mysqld: sql_select.cc:17126: int join_read_key2(JOIN_TAB*, TABLE*, TABLE_REF*): Assertion `tab->ref.has_record' failed.

<snip>
Thread 1 (process 27551):
#0  0xb7f56430 in __kernel_vsyscall ()
#1  0xb7f2e1c8 in pthread_kill () from /lib/tls/i686/cmov/libpthread.so.0
#2  0x090dfb8a in my_write_core (sig=6) at stacktrace.c:309
#3  0x084b0e6a in handle_segfault (sig=6) at mysqld.cc:2765
#4  <signal handler called>
#5  0xb7f56430 in __kernel_vsyscall ()
#6  0xb7c776d0 in raise () from /lib/tls/i686/cmov/libc.so.6
#7  0xb7c79098 in abort () from /lib/tls/i686/cmov/libc.so.6
#8  0xb7c705ce in __assert_fail () from /lib/tls/i686/cmov/libc.so.6
#9  0x0865ae0f in join_read_key2 (tab=0xacb5900, table=0xabbbd20, table_ref=0xacb5a34) at sql_select.cc:17126
#10 0x0865af3a in join_read_key (tab=0xacb5900) at sql_select.cc:17076
#11 0x0866275b in sub_select (join=0xacaf438, join_tab=0xacb5900, end_of_records=false) at sql_select.cc:16460
#12 0x0868743b in do_select (join=0xacaf438, fields=0xabdf2ac, table=0x0, procedure=0x0) at sql_select.cc:16023
#13 0x086c8396 in JOIN::exec (this=0xacaf438) at sql_select.cc:2949
#14 0x083d05b6 in subselect_single_select_engine::exec (this=0xabdfef8) at item_subselect.cc:2316
#15 0x083dc577 in Item_subselect::exec (this=0xabdfe30) at item_subselect.cc:283
#16 0x083dca29 in Item_in_subselect::exec (this=0xabdfe30) at item_subselect.cc:333
#17 0x083c818e in Item_in_subselect::val_bool (this=0xabdfe30) at item_subselect.cc:928
#18 0x0828bc93 in Item::val_bool_result (this=0xabdfe30) at ../item.h:760
#19 0x08316872 in Item_in_optimizer::val_int (this=0xabe01e8) at item_cmpfunc.cc:1658
#20 0x08312783 in Item_cond_xor::val_int (this=0xabdffa8) at item_cmpfunc.cc:5030
#21 0x08661af7 in evaluate_join_record (join=0xacaa5d8, join_tab=0xacb4ea8, error=0) at sql_select.cc:16645
#22 0x08662bd1 in sub_select (join=0xacaa5d8, join_tab=0xacb4ea8, end_of_records=false) at sql_select.cc:16495
#23 0x0868743b in do_select (join=0xacaa5d8, fields=0xac336dc, table=0x0, procedure=0x0) at sql_select.cc:16023
#24 0x086c8396 in JOIN::exec (this=0xacaa5d8) at sql_select.cc:2949
#25 0x086b9313 in mysql_select (thd=0xac321e8, rref_pointer_array=0xac3374c, tables=0xabdebe8, wild_num=0, fields=@0xac336dc, conds=0xabdffa8, og_num=0, order=0x0, group=0x0, 
    having=0x0, proc_param=0x0, select_options=2147748352, result=0xabe00b0, unit=0xac33190, select_lex=0xac33648) at sql_select.cc:3140
#26 0x086c8a1c in handle_select (thd=0xac321e8, lex=0xac33134, result=0xabe00b0, setup_tables_done_option=0) at sql_select.cc:308
#27 0x084e4456 in execute_sqlcom_select (thd=0xac321e8, all_tables=0xabdebe8) at sql_parse.cc:4961
#28 0x084e8ebd in mysql_execute_command (thd=0xac321e8) at sql_parse.cc:2156
#29 0x08505a9a in mysql_parse (thd=0xac321e8, 
    inBuf=0xabde9a8 "SELECT `date_key`  \nFROM C  \nWHERE ( `int_key`  , `int_key`  )  IN (  \nSELECT `int_key`  , `pk`  \nFROM CC  )  XOR '2001-03-28'", length=126, 
    found_semicolon=0xb7334984) at sql_parse.cc:5975
#30 0x08507f37 in dispatch_command (command=COM_QUERY, thd=0xac321e8, packet=0xabb6cc9 "", packet_length=128) at sql_parse.cc:1076
#31 0x0850c36e in do_command (thd=0xac321e8) at sql_parse.cc:758
#32 0x084d236f in handle_one_connection (arg=0xac321e8) at sql_connect.cc:1164
#33 0xb7f294ff in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#34 0xb7d3049e in clone () from /lib/tls/i686/cmov/libc.so.6

How to repeat:
MTR test case (please disable certain SET statements depending on the version of the server you are testing against)

#/* Server0: MySQL 6.0.14-alpha-gcov-debug-log */

/*!50400 SET SESSION optimizer_switch = 'firstmatch=off,index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,loosescan=off,materialization=off,semijoin=off' */;
/*!50400 SET SESSION optimizer_use_mrr = 'force' */;
/*!50400 SET SESSION engine_condition_pushdown = 'ON' */;
/*!50400 SET SESSION join_cache_level = 1 */;
/*!50400 SET SESSION debug = '+d,optimizer_no_icp' */;

#/* Begin test case for query 0 */

--disable_warnings
DROP TABLE /*! IF EXISTS */ CC;
DROP TABLE /*! IF EXISTS */ C;
--enable_warnings

CREATE TABLE `CC` (
  `pk` int(11) NOT NULL AUTO_INCREMENT,
  `int_key` int(11) DEFAULT NULL,
  `date_key` date DEFAULT NULL,
  PRIMARY KEY (`pk`),
  KEY `int_key` (`int_key`),
  KEY `date_key` (`date_key`),
  KEY `varchar_key` (`int_key`)
) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=latin1;
INSERT INTO `CC` VALUES (10,8,NULL);
INSERT INTO `CC` VALUES (11,9,'2006-06-14');
INSERT INTO `CC` VALUES (12,9,'2002-09-12');
INSERT INTO `CC` VALUES (13,186,'2005-02-15');
INSERT INTO `CC` VALUES (14,NULL,NULL);
INSERT INTO `CC` VALUES (15,2,'2008-11-04');
INSERT INTO `CC` VALUES (16,3,'2004-09-04');
INSERT INTO `CC` VALUES (17,0,'2006-06-05');
INSERT INTO `CC` VALUES (18,133,'1900-01-01');
INSERT INTO `CC` VALUES (19,1,'1900-01-01');
INSERT INTO `CC` VALUES (20,8,'1900-01-01');
INSERT INTO `CC` VALUES (21,5,'2005-01-13');
INSERT INTO `CC` VALUES (22,5,'2006-05-21');
INSERT INTO `CC` VALUES (23,8,'2003-09-08');
INSERT INTO `CC` VALUES (24,6,'2006-12-23');
INSERT INTO `CC` VALUES (25,51,'2006-10-15');
INSERT INTO `CC` VALUES (26,4,'2005-04-06');
INSERT INTO `CC` VALUES (27,7,'2008-04-07');
INSERT INTO `CC` VALUES (28,6,'2006-10-10');
INSERT INTO `CC` VALUES (29,4,'1900-01-01');
CREATE TABLE `C` (
  `pk` int(11) NOT NULL AUTO_INCREMENT,
  `int_key` int(11) DEFAULT NULL,
  `date_key` date DEFAULT NULL,
  PRIMARY KEY (`pk`),
  KEY `int_key` (`int_key`),
  KEY `date_key` (`date_key`),
  KEY `varchar_key` (`int_key`)
) ENGINE=MyISAM AUTO_INCREMENT=21 DEFAULT CHARSET=latin1;
INSERT INTO `C` VALUES (1,2,NULL);
INSERT INTO `C` VALUES (2,9,'2001-09-19');
INSERT INTO `C` VALUES (3,3,'2004-09-12');
INSERT INTO `C` VALUES (4,9,NULL);
INSERT INTO `C` VALUES (5,NULL,'2002-07-19');
INSERT INTO `C` VALUES (6,9,'2002-12-16');
INSERT INTO `C` VALUES (7,3,'2006-02-08');
INSERT INTO `C` VALUES (8,8,'2006-08-28');
INSERT INTO `C` VALUES (9,8,'2001-04-14');
INSERT INTO `C` VALUES (10,53,'2000-01-05');
INSERT INTO `C` VALUES (11,0,'2003-12-06');
INSERT INTO `C` VALUES (12,5,'1900-01-01');
INSERT INTO `C` VALUES (13,166,'2002-11-27');
INSERT INTO `C` VALUES (14,3,NULL);
INSERT INTO `C` VALUES (15,0,'2003-05-27');
INSERT INTO `C` VALUES (16,1,'2005-05-03');
INSERT INTO `C` VALUES (17,9,'2001-04-18');
INSERT INTO `C` VALUES (18,5,'2005-12-27');
INSERT INTO `C` VALUES (19,6,'2004-08-20');
INSERT INTO `C` VALUES (20,2,'1900-01-01');

 
SELECT `date_key`  
FROM C  
WHERE ( `int_key`  , `int_key`  )  IN (  
SELECT `int_key`  , `pk`  
FROM CC  )  XOR '2001-03-28'  ;

DROP TABLE CC;
DROP TABLE C;
#/* End of test case for query 0 */
[18 Nov 2009 21:33] Patrick Crews
Full MTR crash output:
Trying 'gdb' to get a backtrace
Core generated by '<path>/mysql-6.0/sql/mysqld'
Output from gdb follows. The first stack trace is from the failing thread.
The following stack traces are from all threads (so the failing one is
duplicated).
--------------------------

warning: Can't read pathname for load map: Input/output error.
Core was generated by `<path>/mysql-6.0/sql/mysqld --defaults-group-suffi'.
Program terminated with signal 6, Aborted.
[New process 27551]
[New process 27541]
[New process 27539]
#0  0xb7f56430 in __kernel_vsyscall ()
#0  0xb7f56430 in __kernel_vsyscall ()
#1  0xb7f2e1c8 in pthread_kill () from /lib/tls/i686/cmov/libpthread.so.0
#2  0x090dfb8a in my_write_core (sig=6) at stacktrace.c:309
#3  0x084b0e6a in handle_segfault (sig=6) at mysqld.cc:2765
#4  <signal handler called>
#5  0xb7f56430 in __kernel_vsyscall ()
#6  0xb7c776d0 in raise () from /lib/tls/i686/cmov/libc.so.6
#7  0xb7c79098 in abort () from /lib/tls/i686/cmov/libc.so.6
#8  0xb7c705ce in __assert_fail () from /lib/tls/i686/cmov/libc.so.6
#9  0x0865ae0f in join_read_key2 (tab=0xacb5900, table=0xabbbd20, table_ref=0xacb5a34) at sql_select.cc:17126
#10 0x0865af3a in join_read_key (tab=0xacb5900) at sql_select.cc:17076
#11 0x0866275b in sub_select (join=0xacaf438, join_tab=0xacb5900, end_of_records=false) at sql_select.cc:16460
#12 0x0868743b in do_select (join=0xacaf438, fields=0xabdf2ac, table=0x0, procedure=0x0) at sql_select.cc:16023
#13 0x086c8396 in JOIN::exec (this=0xacaf438) at sql_select.cc:2949
#14 0x083d05b6 in subselect_single_select_engine::exec (this=0xabdfef8) at item_subselect.cc:2316
#15 0x083dc577 in Item_subselect::exec (this=0xabdfe30) at item_subselect.cc:283
#16 0x083dca29 in Item_in_subselect::exec (this=0xabdfe30) at item_subselect.cc:333
#17 0x083c818e in Item_in_subselect::val_bool (this=0xabdfe30) at item_subselect.cc:928
#18 0x0828bc93 in Item::val_bool_result (this=0xabdfe30) at ../item.h:760
#19 0x08316872 in Item_in_optimizer::val_int (this=0xabe01e8) at item_cmpfunc.cc:1658
#20 0x08312783 in Item_cond_xor::val_int (this=0xabdffa8) at item_cmpfunc.cc:5030
#21 0x08661af7 in evaluate_join_record (join=0xacaa5d8, join_tab=0xacb4ea8, error=0) at sql_select.cc:16645
#22 0x08662bd1 in sub_select (join=0xacaa5d8, join_tab=0xacb4ea8, end_of_records=false) at sql_select.cc:16495
#23 0x0868743b in do_select (join=0xacaa5d8, fields=0xac336dc, table=0x0, procedure=0x0) at sql_select.cc:16023
#24 0x086c8396 in JOIN::exec (this=0xacaa5d8) at sql_select.cc:2949
#25 0x086b9313 in mysql_select (thd=0xac321e8, rref_pointer_array=0xac3374c, tables=0xabdebe8, wild_num=0, fields=@0xac336dc, conds=0xabdffa8, og_num=0, order=0x0, group=0x0, 
    having=0x0, proc_param=0x0, select_options=2147748352, result=0xabe00b0, unit=0xac33190, select_lex=0xac33648) at sql_select.cc:3140
#26 0x086c8a1c in handle_select (thd=0xac321e8, lex=0xac33134, result=0xabe00b0, setup_tables_done_option=0) at sql_select.cc:308
#27 0x084e4456 in execute_sqlcom_select (thd=0xac321e8, all_tables=0xabdebe8) at sql_parse.cc:4961
#28 0x084e8ebd in mysql_execute_command (thd=0xac321e8) at sql_parse.cc:2156
#29 0x08505a9a in mysql_parse (thd=0xac321e8, 
    inBuf=0xabde9a8 "SELECT `date_key`  \nFROM C  \nWHERE ( `int_key`  , `int_key`  )  IN (  \nSELECT `int_key`  , `pk`  \nFROM CC  )  XOR '2001-03-28'", length=126, 
    found_semicolon=0xb7334984) at sql_parse.cc:5975
#30 0x08507f37 in dispatch_command (command=COM_QUERY, thd=0xac321e8, packet=0xabb6cc9 "", packet_length=128) at sql_parse.cc:1076
#31 0x0850c36e in do_command (thd=0xac321e8) at sql_parse.cc:758
#32 0x084d236f in handle_one_connection (arg=0xac321e8) at sql_connect.cc:1164
#33 0xb7f294ff in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#34 0xb7d3049e in clone () from /lib/tls/i686/cmov/libc.so.6

Thread 3 (process 27539):
#0  0xb7f56430 in __kernel_vsyscall ()
#1  0xb7d287b1 in select () from /lib/tls/i686/cmov/libc.so.6
#2  0x084b2846 in handle_connections_sockets () at mysqld.cc:5362
#3  0x084c1987 in main (argc=8, argv=0xbfa70134) at mysqld.cc:4855

Thread 2 (process 27541):
#0  0xb7f56430 in __kernel_vsyscall ()
#1  0xb7f31300 in sigwait () from /lib/tls/i686/cmov/libpthread.so.0
#2  0x084ae04d in signal_hand (arg=0x0) at mysqld.cc:2967
#3  0xb7f294ff in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#4  0xb7d3049e in clone () from /lib/tls/i686/cmov/libc.so.6

Thread 1 (process 27551):
#0  0xb7f56430 in __kernel_vsyscall ()
#1  0xb7f2e1c8 in pthread_kill () from /lib/tls/i686/cmov/libpthread.so.0
#2  0x090dfb8a in my_write_core (sig=6) at stacktrace.c:309
#3  0x084b0e6a in handle_segfault (sig=6) at mysqld.cc:2765
#4  <signal handler called>
#5  0xb7f56430 in __kernel_vsyscall ()
#6  0xb7c776d0 in raise () from /lib/tls/i686/cmov/libc.so.6
#7  0xb7c79098 in abort () from /lib/tls/i686/cmov/libc.so.6
#8  0xb7c705ce in __assert_fail () from /lib/tls/i686/cmov/libc.so.6
#9  0x0865ae0f in join_read_key2 (tab=0xacb5900, table=0xabbbd20, table_ref=0xacb5a34) at sql_select.cc:17126
#10 0x0865af3a in join_read_key (tab=0xacb5900) at sql_select.cc:17076
#11 0x0866275b in sub_select (join=0xacaf438, join_tab=0xacb5900, end_of_records=false) at sql_select.cc:16460
#12 0x0868743b in do_select (join=0xacaf438, fields=0xabdf2ac, table=0x0, procedure=0x0) at sql_select.cc:16023
#13 0x086c8396 in JOIN::exec (this=0xacaf438) at sql_select.cc:2949
#14 0x083d05b6 in subselect_single_select_engine::exec (this=0xabdfef8) at item_subselect.cc:2316
#15 0x083dc577 in Item_subselect::exec (this=0xabdfe30) at item_subselect.cc:283
#16 0x083dca29 in Item_in_subselect::exec (this=0xabdfe30) at item_subselect.cc:333
#17 0x083c818e in Item_in_subselect::val_bool (this=0xabdfe30) at item_subselect.cc:928
#18 0x0828bc93 in Item::val_bool_result (this=0xabdfe30) at ../item.h:760
#19 0x08316872 in Item_in_optimizer::val_int (this=0xabe01e8) at item_cmpfunc.cc:1658
#20 0x08312783 in Item_cond_xor::val_int (this=0xabdffa8) at item_cmpfunc.cc:5030
#21 0x08661af7 in evaluate_join_record (join=0xacaa5d8, join_tab=0xacb4ea8, error=0) at sql_select.cc:16645
#22 0x08662bd1 in sub_select (join=0xacaa5d8, join_tab=0xacb4ea8, end_of_records=false) at sql_select.cc:16495
#23 0x0868743b in do_select (join=0xacaa5d8, fields=0xac336dc, table=0x0, procedure=0x0) at sql_select.cc:16023
#24 0x086c8396 in JOIN::exec (this=0xacaa5d8) at sql_select.cc:2949
#25 0x086b9313 in mysql_select (thd=0xac321e8, rref_pointer_array=0xac3374c, tables=0xabdebe8, wild_num=0, fields=@0xac336dc, conds=0xabdffa8, og_num=0, order=0x0, group=0x0, 
    having=0x0, proc_param=0x0, select_options=2147748352, result=0xabe00b0, unit=0xac33190, select_lex=0xac33648) at sql_select.cc:3140
#26 0x086c8a1c in handle_select (thd=0xac321e8, lex=0xac33134, result=0xabe00b0, setup_tables_done_option=0) at sql_select.cc:308
#27 0x084e4456 in execute_sqlcom_select (thd=0xac321e8, all_tables=0xabdebe8) at sql_parse.cc:4961
#28 0x084e8ebd in mysql_execute_command (thd=0xac321e8) at sql_parse.cc:2156
#29 0x08505a9a in mysql_parse (thd=0xac321e8, 
    inBuf=0xabde9a8 "SELECT `date_key`  \nFROM C  \nWHERE ( `int_key`  , `int_key`  )  IN (  \nSELECT `int_key`  , `pk`  \nFROM CC  )  XOR '2001-03-28'", length=126, 
    found_semicolon=0xb7334984) at sql_parse.cc:5975
#30 0x08507f37 in dispatch_command (command=COM_QUERY, thd=0xac321e8, packet=0xabb6cc9 "", packet_length=128) at sql_parse.cc:1076
#31 0x0850c36e in do_command (thd=0xac321e8) at sql_parse.cc:758
#32 0x084d236f in handle_one_connection (arg=0xac321e8) at sql_connect.cc:1164
#33 0xb7f294ff in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#34 0xb7d3049e in clone () from /lib/tls/i686/cmov/libc.so.6
[19 Nov 2009 13:20] Philip Stoev
I can not reproduce this with 5.1.30 , next-mr-bugfixing and 6.0-codebase-bugfixing. Patrick, does the MTR test case work for you, or just the RQG test case? If it is the RQG test only, then maybe a sequence of queries is required to trigger the problem, not just the final query.
[19 Nov 2009 13:36] Patrick Crews
The test case works for me with servers (all versions) built using compile-pentium-gcov and compile-pentium-debug-max.  From a similar bug - Bug#48709	Assertion failed in sql_select.cc:11782: int join_read_key(JOIN_TAB*), Kostja has said that it shouldn't affect production (makes me think it is limited to -debug builds)
[9 Feb 2010 8:47] Sergei Glukhov
fixed in Joro's patch for bug#48709, duplicated.