Bug #11186 Server segfaults on query, but only when run via slave thread
Submitted: 8 Jun 2005 22:39 Modified: 4 Jul 2005 21:33
Reporter: Douglas Fischer Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Replication Severity:S2 (Serious)
Version:4.1.12 OS:Linux (Linux)
Assigned to: CPU Architecture:Any

[8 Jun 2005 22:39] Douglas Fischer
Description:
MySQL 4.1.12 Community Edition, RPM from mysql.com
Red Hat Enterprise Linux 2.1 ES (kernel 2.4.9-e.59smp)

When running a query of the form:

UPDATE a
       INNER JOIN (
           SELECT a.c
           FROM   a INNER JOIN b USING (c)
       ) AS subquery
       USING (c)
SET a.c2 = a.c;

The query runs fine on the master, and if run directly via client on the slave. However, if the query is allowed to replicate to the slave (i.e. it runs on the slave via the slave thread), the slave server crashes with the segmentation fault.

The above is the simplest case we were able to reduce our original query to and still have it crash. The original query was of the form:

UPDATE a
       INNER JOIN (
           SELECT   a.c, COUNT(*) AS num_c
           FROM     a INNER JOIN b USING (c)
           GROUP BY a.c
       ) AS subquery
       USING (c)
SET c_count = subquery.num_c;

It appears to crash when updating a column other than the one used for the JOIN condition.

Here is the output into the error log (stack trace resolved via resolve_stack_dump):

------------------------------------------------------------------------------------------------------
050607 15:11:29  mysqld restarted
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=33554432
read_buffer_size=1044480
max_used_connections=2
max_connections=25
threads_connected=2
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_connections = 160667 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd=0x897cba8
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...
Cannot determine thread, fp=0xbfe3ef18, backtrace may not be correct.
Stack range sanity check OK, backtrace follows:
0x808df77 init_common_variables__FPCciPPcPPCc + 391
0x82e8af8 lseek + 8
0x80ba663 setup_conds__FP3THDP13st_table_listPP4Item + 1715
0x80beb5f optimize__4JOIN + 1455
0x812f6ef exec__18st_select_lex_unit + 2543
0x8130c7d read_one_row + 29
0x8130bbb cli_read_rows + 443
0x80da90e do_updates__12multi_updateb + 158
0x80a47e1 create_table_precheck__FP3THDP13st_table_listT1 + 289
0x809e0f5 mysql_execute_command__FP3THD + 2869
0x80a2c9f add_field_to_list__FP3THDPc16enum_field_typesT1T1UiP4ItemT6P13st_lex_stringT1Pt4List1Z6StringP15charset_info_stUi + 2447
0x80e34f3 exec_event__14Load_log_eventP6st_netP17st_relay_log_infob + 419
0x812a649 process_io_create_file__FP14st_master_infoP21Create_file_log_event + 793
0x812b3ad next_event__FP17st_relay_log_info + 957
0x82e62ac pthread_getschedparam + 108
0x830fc3a getservbyname + 154
New value of fp=(nil) failed sanity check, terminating stack trace!
Please read http://dev.mysql.com/doc/mysql/en/Using_stack_trace.html and follow instructions on how to resolve the stack trace. Resolved
stack trace is much more helpful in diagnosing the problem, so please do
resolve it
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 0x895606c = UPDATE a
       INNER JOIN (
           SELECT a.c
           FROM   a INNER JOIN b USING (c)
       ) AS subquery
       USING (c)
SET a.c2 = a.c
thd->thread_id=4
The manual page at http://www.mysql.com/doc/en/Crashing.html contains
information that should help you find out what is causing the crash.

Number of processes running now: 0
050607 15:11:29  mysqld restarted
-----------------------------------------------------------------------------------------------------

How to repeat:
In a replication environment, set up the following tables:

DROP TABLE IF EXISTS a;
DROP TABLE IF EXISTS b;
CREATE TABLE a (
    c  INT,
    c2 INT
);
CREATE TABLE b (
    c  INT
);
INSERT a VALUES(1,NULL);
INSERT b VALUES(1);

Execute the following query on the master. It should run properly on the master but crash the slave upon replication:

UPDATE a
       INNER JOIN (
           SELECT a.c
           FROM   a INNER JOIN b USING (c)
       ) AS subquery
       USING (c)
SET a.c2 = a.c;

Alternatively:

UPDATE a
       INNER JOIN (
           SELECT   a.c, COUNT(*) AS num_c
           FROM     a INNER JOIN b USING (c)
           GROUP BY a.c
       ) AS subquery
       USING (c)
SET c2 = subquery.num_c;
[2 Jul 2005 10:00] Aleksey Kishkin
tested and got slave crashed.

stack resolve for me:

0x808b7a3 handle_segfault + 423
0x82e0a48 pthread_sighandler + 184
0x80b75a3 setup_tables__FP13st_table_list + 35
0x80bb9cf prepare__4JOINPPP4ItemP13st_table_listUiP4ItemUiP8st_orderT6T4T6P13st_
select_lexP18st_select_lex_unit + 127
0x812a6df prepare__18st_select_lex_unitP3THDP13select_resultUlPCc + 1063
0x812bc55 mysql_derived__FP3THDP6st_lexP18st_select_lex_unitP13st_table_list + 1
21
0x812bb9b mysql_handle_derived__FP6st_lex + 75
0x80d7132 mysql_multi_update_lock__FP3THDP13st_table_listPt4List1Z4ItemP13st_sel
ect_lex + 174
0x80a18f1 check_multi_update_lock__FP3THDP13st_table_listPt4List1Z4ItemP13st_sel
ect_lex + 181
0x809b2b9 mysql_execute_command__FP3THD + 181
0x809fdef mysql_parse__FP3THDPcUi + 207
0x80dfa3d exec_event__15Query_log_eventP17st_relay_log_info + 401
0x8125749 exec_relay_log_event__FP3THDP17st_relay_log_info + 625
0x81264ad handle_slave_sql + 785
0x82de1fc pthread_start_thread + 220
0x8307b8a thread_start + 4
[4 Jul 2005 21:30] Elliot Murphy
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

This issue is a duplicate of #10442, which has been fixed for 4.1.13 with this patch:
http://lists.mysql.com/internals/26262.
[4 Jul 2005 21:33] Elliot Murphy
This patch contains the fix:
http://lists.mysql.com/internals/26123