Bug #58369 invalid memory reads and crash
Submitted: 22 Nov 2010 5:36 Modified: 15 Oct 2012 14:38
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S1 (Critical)
Version:5.0.92,5.1.52, 5.1.54, 5.5.8, 5.6.1 OS:Any
Assigned to: CPU Architecture:Any

[22 Nov 2010 5:36] Shane Bester
Description:
5.1.52:
mysqld-debug.exe!Item_field::print()[item.cc:5728]
mysqld-debug.exe!st_select_lex::print_order()[sql_lex.cc:2046]
mysqld-debug.exe!st_select_lex::print()[sql_select.cc:17191]
mysqld-debug.exe!st_select_lex_unit::print()[sql_lex.cc:2015]
mysqld-debug.exe!TABLE_LIST::print()[sql_select.cc:17034]
mysqld-debug.exe!print_join()[sql_select.cc:16952]
mysqld-debug.exe!TABLE_LIST::print()[sql_select.cc:17011]
mysqld-debug.exe!print_join()[sql_select.cc:16938]
mysqld-debug.exe!st_select_lex::print()[sql_select.cc:17162]
mysqld-debug.exe!subselect_single_select_engine::print()[item_subselect.cc:2464]
mysqld-debug.exe!Item_subselect::print()[item_subselect.cc:337]
mysqld-debug.exe!Item_func::print_args()[item_func.cc:393]
mysqld-debug.exe!Item_func::print()[item_func.cc:383]
mysqld-debug.exe!change_to_use_tmp_fields()[sql_select.cc:15666]
mysqld-debug.exe!JOIN::exec()[sql_select.cc:1945]
mysqld-debug.exe!mysql_select()[sql_select.cc:2536]
mysqld-debug.exe!handle_select()[sql_select.cc:269]
mysqld-debug.exe!execute_sqlcom_select()[sql_parse.cc:5127]
mysqld-debug.exe!mysql_execute_command()[sql_parse.cc:2292]
mysqld-debug.exe!mysql_parse()[sql_parse.cc:6055]
mysqld-debug.exe!dispatch_command()[sql_parse.cc:1262]
mysqld-debug.exe!do_command()[sql_parse.cc:888]
mysqld-debug.exe!handle_one_connection()[sql_connect.cc:1136]
mysqld-debug.exe!pthread_start()[my_winthread.c:85]
mysqld-debug.exe!_callthreadstart()[thread.c:295]
mysqld-debug.exe!_threadstart()[thread.c:277]

How to repeat:
run mysqld in valgrind if crash doesn't happen:

drop table if exists `h`;
create table `h` (`id` int,`data` int) engine=innodb;
select 1 from `h`
group by 
elt(1,1,`h`.`data`,1,1,
(
        select 1 from `h` `b` 
	inner join (
                select sum(distinct(select 1)) as id 
                from `h`
                left join `h` `c` on 1
                group by `c`.`id`,`c`.`data`
                order by `h`.`id`
           )  as `d` on 1
)
)
;
[22 Nov 2010 5:37] MySQL Verification Team
some details....

Attachment: bug58369_5.5.8_valgrind_output.txt (text/plain), 17.13 KiB.

[22 Nov 2010 8:00] Valeriy Kravchuk
Verified with valgrind build of 5.1.54 on 32-bit Ubuntu:

...
101122  9:56:21 [Note] /home2/openxs/dbs/5.1/libexec/mysqld: ready for connections.
Version: '5.1.54-valgrind-max-debug'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
101122  9:56:28 - mysqld got signal 11 ;
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=8384512
read_buffer_size=131072
max_used_connections=1
max_threads=151
threads_connected=1
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 337768 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd: 0x9817438
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 = 0xb43f438c thread_stack 0x30000
/home2/openxs/dbs/5.1/libexec/mysqld(my_print_stacktrace+0x26)[0x85fc914]
/home2/openxs/dbs/5.1/libexec/mysqld(handle_segfault+0x2b9)[0x827b042]
[0xf2b400]
/home2/openxs/dbs/5.1/libexec/mysqld(_ZN13st_select_lex11print_orderEP6StringP8st_order15enum_query_type+0x9c)[0x819a9a6]
/home2/openxs/dbs/5.1/libexec/mysqld(_ZN13st_select_lex5printEP3THDP6String15enum_query_type+0x48a)[0x831db7a]
/home2/openxs/dbs/5.1/libexec/mysqld(_ZN18st_select_lex_unit5printEP6String15enum_query_type+0xd6)[0x819a834]
/home2/openxs/dbs/5.1/libexec/mysqld(_ZN10TABLE_LIST5printEP3THDP6String15enum_query_type+0x1be)[0x831d410]
/home2/openxs/dbs/5.1/libexec/mysqld[0x831d079]
/home2/openxs/dbs/5.1/libexec/mysqld(_ZN10TABLE_LIST5printEP3THDP6String15enum_query_type+0x84)[0x831d2d6]
/home2/openxs/dbs/5.1/libexec/mysqld[0x831cfc4]
/home2/openxs/dbs/5.1/libexec/mysqld(_ZN13st_select_lex5printEP3THDP6String15enum_query_type+0x375)[0x831da65]
/home2/openxs/dbs/5.1/libexec/mysqld(_ZN30subselect_single_select_engine5printEP6String15enum_query_type+0x2c)[0x8232590]
/home2/openxs/dbs/5.1/libexec/mysqld(_ZN14Item_subselect5printEP6String15enum_query_type+0x49)[0x822c08f]
/home2/openxs/dbs/5.1/libexec/mysqld(_ZN9Item_func10print_argsEP6Stringj15enum_query_type+0x65)[0x81d92e1]
/home2/openxs/dbs/5.1/libexec/mysqld(_ZN9Item_func5printEP6String15enum_query_type+0x5d)[0x81d9267]
/home2/openxs/dbs/5.1/libexec/mysqld[0x8318eff]
/home2/openxs/dbs/5.1/libexec/mysqld(_ZN4JOIN4execEv+0xc5a)[0x82f6ca8]
/home2/openxs/dbs/5.1/libexec/mysqld(_Z12mysql_selectP3THDPPP4ItemP10TABLE_LISTjR4ListIS1_ES2_jP8st_orderSB_S2_SB_yP13select_resultP18st_select_lex_unitP13st_select_lex+0x353)[0x82f8c21]
/home2/openxs/dbs/5.1/libexec/mysqld(_Z13handle_selectP3THDP6st_lexP13select_resultm+0x1e2)[0x82f13a5]
/home2/openxs/dbs/5.1/libexec/mysqld[0x8296c92]
/home2/openxs/dbs/5.1/libexec/mysqld(_Z21mysql_execute_commandP3THD+0x91b)[0x828d3c2]
/home2/openxs/dbs/5.1/libexec/mysqld(_Z11mysql_parseP3THDPcjPPKc+0x265)[0x8298ee2]
/home2/openxs/dbs/5.1/libexec/mysqld(_Z16dispatch_command19enum_server_commandP3THDPcj+0xbee)[0x828ad29]
/home2/openxs/dbs/5.1/libexec/mysqld(_Z10do_commandP3THD+0x26c)[0x8289e31]
/home2/openxs/dbs/5.1/libexec/mysqld(handle_one_connection+0x159)[0x8287fd2]
/lib/tls/i686/cmov/libpthread.so.0(+0x596e)[0x36c96e]
/lib/tls/i686/cmov/libc.so.6(clone+0x5e)[0x275a4e]
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 0x985d118 = select 1 from `h`
group by 
elt(1,1,`h`.`data`,1,1,
(
        select 1 from `h` `b` 
inner join (
                select sum(distinct(select 1)) as id 
                from `h`
                left join `h` `c` on 1
                group by `c`.`id`,`c`.`data`
                order by `h`.`id`
           )  as `d` on 1
)
)
thd->thread_id=1
thd->killed=NOT_KILLED
...