[MDEV-11274] Executing EXPLAIN of complex query over join limit causes server to crash Created: 2016-11-11  Updated: 2020-08-25  Resolved: 2018-03-27

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.1.18, 5.5, 10.0, 10.1, 10.2
Fix Version/s: 5.5.60, 10.0.35, 10.1.33, 10.2.15

Type: Bug Priority: Major
Reporter: Geoff Montee (Inactive) Assignee: Varun Gupta (Inactive)
Resolution: Fixed Votes: 2
Labels: crash, explain, optimizer

Issue Links:
Duplicate
is duplicated by MDEV-15632 [ERROR] mysqld got signal 11 - Servic... Closed
Sprint: 10.0.34

 Description   

A user saw the following crash when executing EXPLAIN for a complex query that exceeds the 61 table join limit:

Nov 11 13:50:44 ip-172-30-0-32 mysqld: 161111 13:50:44 [ERROR] mysqld got signal 11 ;
Nov 11 13:50:44 ip-172-30-0-32 mysqld: This could be because you hit a bug. It is also possible that this binary
Nov 11 13:50:44 ip-172-30-0-32 mysqld: or one of the libraries it was linked against is corrupt, improperly built,
Nov 11 13:50:44 ip-172-30-0-32 mysqld: or misconfigured. This error can also be caused by malfunctioning hardware.
Nov 11 13:50:44 ip-172-30-0-32 mysqld: To report this bug, see https://mariadb.com/kb/en/reporting-bugs
Nov 11 13:50:44 ip-172-30-0-32 mysqld: We will try our best to scrape up some info that will hopefully help
Nov 11 13:50:44 ip-172-30-0-32 mysqld: diagnose the problem, but since we have already crashed,
Nov 11 13:50:44 ip-172-30-0-32 mysqld: something is definitely wrong and this may fail.
Nov 11 13:50:44 ip-172-30-0-32 mysqld: Server version: 10.1.18-MariaDB
Nov 11 13:50:44 ip-172-30-0-32 mysqld: key_buffer_size=134217728
Nov 11 13:50:44 ip-172-30-0-32 mysqld: read_buffer_size=131072
Nov 11 13:50:44 ip-172-30-0-32 mysqld: max_used_connections=1
Nov 11 13:50:44 ip-172-30-0-32 mysqld: max_threads=153
Nov 11 13:50:44 ip-172-30-0-32 mysqld: thread_count=1
Nov 11 13:50:44 ip-172-30-0-32 mysqld: It is possible that mysqld could use up to
Nov 11 13:50:44 ip-172-30-0-32 mysqld: key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 467121 K  bytes of memory
Nov 11 13:50:44 ip-172-30-0-32 mysqld: Hope that's ok; if not, decrease some variables in the equation.
Nov 11 13:50:44 ip-172-30-0-32 mysqld: Thread pointer: 0x0x7fdab1c0e008
Nov 11 13:50:44 ip-172-30-0-32 mysqld: Attempting backtrace. You can use the following information to find out
Nov 11 13:50:44 ip-172-30-0-32 mysqld: where mysqld died. If you see no messages after this, something went
Nov 11 13:50:44 ip-172-30-0-32 mysqld: terribly wrong...
Nov 11 13:50:44 ip-172-30-0-32 mysqld: stack_bottom = 0x7fdad8f9c130 thread_stack 0x48400
Nov 11 13:50:44 ip-172-30-0-32 mysqld: /usr/sbin/mysqld(my_print_stacktrace+0x2e)[0x7fdad9b46a6e]
Nov 11 13:50:44 ip-172-30-0-32 mysqld: /usr/sbin/mysqld(handle_fatal_signal+0x2d5)[0x7fdad966c8d5]
Nov 11 13:50:44 ip-172-30-0-32 mysqld: /lib64/libpthread.so.0(+0xf100)[0x7fdad8c87100]
Nov 11 13:50:44 ip-172-30-0-32 mysqld: /usr/sbin/mysqld(_ZN10TABLE_LIST20fetch_number_of_rowsEv+0x30)[0x7fdad9599d70]
Nov 11 13:50:44 ip-172-30-0-32 mysqld: /usr/sbin/mysqld(+0x47df05)[0x7fdad9535f05]
Nov 11 13:50:44 ip-172-30-0-32 mysqld: /usr/sbin/mysqld(_ZN4JOIN14optimize_innerEv+0x72f)[0x7fdad953e6af]
Nov 11 13:50:44 ip-172-30-0-32 mysqld: /usr/sbin/mysqld(_ZN4JOIN8optimizeEv+0x2f)[0x7fdad9540faf]
Nov 11 13:50:44 ip-172-30-0-32 mysqld: /usr/sbin/mysqld(_Z12mysql_selectP3THDPPP4ItemP10TABLE_LISTjR4ListIS1_ES2_jP8st_orderSB_S2_SB_yP13select_resultP18st_select_lex_unitP13st_select_lex+0x8f)[0x7fdad95410ef]
Nov 11 13:50:44 ip-172-30-0-32 mysqld: /usr/sbin/mysqld(_Z19mysql_explain_unionP3THDP18st_select_lex_unitP13select_result+0x120)[0x7fdad9541dd0]
Nov 11 13:50:44 ip-172-30-0-32 mysqld: /usr/sbin/mysqld(+0x428e8b)[0x7fdad94e0e8b]
Nov 11 13:50:44 ip-172-30-0-32 mysqld: /usr/sbin/mysqld(_Z21mysql_execute_commandP3THD+0x5f8f)[0x7fdad94ecfaf]
Nov 11 13:50:44 ip-172-30-0-32 mysqld: /usr/sbin/mysqld(_Z11mysql_parseP3THDPcjP12Parser_state+0x352)[0x7fdad94f0952]
Nov 11 13:50:44 ip-172-30-0-32 mysqld: /usr/sbin/mysqld(_Z16dispatch_command19enum_server_commandP3THDPcj+0x25db)[0x7fdad94f3e2b]
Nov 11 13:50:44 ip-172-30-0-32 mysqld: /usr/sbin/mysqld(_Z10do_commandP3THD+0x169)[0x7fdad94f46a9]
Nov 11 13:50:44 ip-172-30-0-32 mysqld: /usr/sbin/mysqld(_Z24do_handle_one_connectionP3THD+0x18a)[0x7fdad95bb19a]
Nov 11 13:50:44 ip-172-30-0-32 mysqld: /usr/sbin/mysqld(handle_one_connection+0x40)[0x7fdad95bb370]
Nov 11 13:50:44 ip-172-30-0-32 mysqld: /lib64/libpthread.so.0(+0x7dc5)[0x7fdad8c7fdc5]
Nov 11 13:50:44 ip-172-30-0-32 mysqld: /lib64/libc.so.6(clone+0x6d)[0x7fdad70a21cd]



 Comments   
Comment by Elena Stepanova [ 2016-11-12 ]

Reproducible on 5.5, 10.0, 10.1.
Could not reproduce on 10.2, MySQL 5.5-5.7.

5.5 96b62b55149a9297f32c3aad99ece613cc3f788f

#3  <signal handler called>
#4  0x00000000006d3e3c in TABLE_LIST::fetch_number_of_rows (this=0x7fa10e5ef000) at /data/src/5.5/sql/table.cc:6812
#5  0x000000000063a409 in make_join_statistics (join=0x7fa10e7b3ac0, tables_list=..., conds=0x7fa10e7f5938, keyuse_array=0x7fa10e7b3dd8) at /data/src/5.5/sql/sql_select.cc:3223
#6  0x000000000063337c in JOIN::optimize (this=0x7fa10e7b3ac0) at /data/src/5.5/sql/sql_select.cc:1229
#7  0x0000000000639d01 in mysql_select (thd=0x7fa10f674060, rref_pointer_array=0x7fa10f677ce0, tables=0x7fa10e5491f0, wild_num=1, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748612, result=0x7fa10e5f1f30, unit=0x7fa10f677390, select_lex=0x7fa10f677a70) at /data/src/5.5/sql/sql_select.cc:3080
#8  0x000000000066af6f in mysql_explain_union (thd=0x7fa10f674060, unit=0x7fa10f677390, result=0x7fa10e5f1f30) at /data/src/5.5/sql/sql_select.cc:23063
#9  0x0000000000609a31 in execute_sqlcom_select (thd=0x7fa10f674060, all_tables=0x7fa10e5491f0) at /data/src/5.5/sql/sql_parse.cc:4660
#10 0x0000000000602f34 in mysql_execute_command (thd=0x7fa10f674060) at /data/src/5.5/sql/sql_parse.cc:2234
#11 0x000000000060c7ae in mysql_parse (thd=0x7fa10f674060, rawbuf=0x7fa10e548078 "EXPLAIN\nSELECT t0.*\nFROM t0\nJOIN t1\nON t1.f1 = t0.f0\nLEFT JOIN t2\nON t0.f0 = t2.f2\nLEFT JOIN t3\nON t0.f0 = t3.f3\nLEFT JOIN t4\nON t0.f0 = t4.f4\nLEFT JOIN t5\nON t4.f4 = t5.f5\nLEFT JOIN t6\nON t0.f0 = t6."..., length=2007, parser_state=0x7fa115930650) at /data/src/5.5/sql/sql_parse.cc:5934
#12 0x00000000006004c3 in dispatch_command (command=COM_QUERY, thd=0x7fa10f674060, packet=0x7fa11034e061 "", packet_length=2008) at /data/src/5.5/sql/sql_parse.cc:1079
#13 0x00000000005ff67d in do_command (thd=0x7fa10f674060) at /data/src/5.5/sql/sql_parse.cc:793
#14 0x0000000000701889 in do_handle_one_connection (thd_arg=0x7fa10f674060) at /data/src/5.5/sql/sql_connect.cc:1270
#15 0x0000000000701616 in handle_one_connection (arg=0x7fa10f674060) at /data/src/5.5/sql/sql_connect.cc:1186
#16 0x0000000000943ae5 in pfs_spawn_thread (arg=0x7fa11037a300) at /data/src/5.5/storage/perfschema/pfs.cc:1015
#17 0x00007fa11556d0a4 in start_thread (arg=0x7fa115931700) at pthread_create.c:309
#18 0x00007fa11399387d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

Test case

CREATE TABLE IF NOT EXISTS t0 (f0 INT);
CREATE TABLE IF NOT EXISTS t1 (f1 INT);
CREATE TABLE IF NOT EXISTS t2 (f2 INT);
CREATE TABLE IF NOT EXISTS t3 (f3 INT);
CREATE TABLE IF NOT EXISTS t4 (f4 INT);
CREATE TABLE IF NOT EXISTS t5 (f5 INT);
CREATE TABLE IF NOT EXISTS t6 (f6 INT);
CREATE TABLE IF NOT EXISTS t7 (f7 INT);
CREATE TABLE IF NOT EXISTS t8 (f8 INT);
CREATE TABLE IF NOT EXISTS t9 (f9 INT);
CREATE TABLE IF NOT EXISTS t10 (f10 INT);
CREATE TABLE IF NOT EXISTS t11 (f11 INT);
CREATE TABLE IF NOT EXISTS t12 (f12 INT);
CREATE TABLE IF NOT EXISTS t13 (f13 INT);
CREATE TABLE IF NOT EXISTS t14 (f14 INT);
CREATE TABLE IF NOT EXISTS t15 (f15 INT);
CREATE TABLE IF NOT EXISTS t16 (f16 INT);
CREATE TABLE IF NOT EXISTS t17 (f17 INT);
CREATE TABLE IF NOT EXISTS t18 (f18 INT);
CREATE TABLE IF NOT EXISTS t19 (f19 INT);
CREATE TABLE IF NOT EXISTS t20 (f20 INT);
CREATE TABLE IF NOT EXISTS t21 (f21 INT);
CREATE TABLE IF NOT EXISTS t22 (f22 INT);
CREATE TABLE IF NOT EXISTS t23 (f23 INT);
CREATE TABLE IF NOT EXISTS t24 (f24 INT);
CREATE TABLE IF NOT EXISTS t25 (f25 INT);
CREATE TABLE IF NOT EXISTS t26 (f26 INT);
CREATE TABLE IF NOT EXISTS t27 (f27 INT);
CREATE TABLE IF NOT EXISTS t28 (f28 INT);
CREATE TABLE IF NOT EXISTS t29 (f29 INT);
CREATE TABLE IF NOT EXISTS t30 (f30 INT);
CREATE TABLE IF NOT EXISTS t31 (f31 INT);
CREATE TABLE IF NOT EXISTS t32 (f32 INT);
CREATE TABLE IF NOT EXISTS t33 (f33 INT);
CREATE TABLE IF NOT EXISTS t34 (f34 INT);
CREATE TABLE IF NOT EXISTS t35 (f35 INT);
CREATE TABLE IF NOT EXISTS t36 (f36 INT);
CREATE TABLE IF NOT EXISTS t37 (f37 INT);
CREATE TABLE IF NOT EXISTS t38 (f38 INT);
CREATE TABLE IF NOT EXISTS t39 (f39 INT);
CREATE TABLE IF NOT EXISTS t40 (f40 INT);
CREATE TABLE IF NOT EXISTS t41 (f41 INT);
CREATE TABLE IF NOT EXISTS t42 (f42 INT);
CREATE TABLE IF NOT EXISTS t43 (f43 INT);
CREATE TABLE IF NOT EXISTS t44 (f44 INT);
CREATE TABLE IF NOT EXISTS t45 (f45 INT);
CREATE TABLE IF NOT EXISTS t46 (f46 INT);
CREATE TABLE IF NOT EXISTS t47 (f47 INT);
CREATE TABLE IF NOT EXISTS t48 (f48 INT);
CREATE TABLE IF NOT EXISTS t49 (f49 INT);
CREATE TABLE IF NOT EXISTS t50 (f50 INT);
CREATE TABLE IF NOT EXISTS t51 (f51 INT);
CREATE TABLE IF NOT EXISTS t52 (f52 INT);
CREATE TABLE IF NOT EXISTS t53 (f53 INT);
CREATE TABLE IF NOT EXISTS t54 (f54 INT);
CREATE TABLE IF NOT EXISTS t55 (f55 INT);
CREATE TABLE IF NOT EXISTS t56 (f56 INT);
CREATE TABLE IF NOT EXISTS t57 (f57 INT);
CREATE TABLE IF NOT EXISTS t58 (f58 INT);
CREATE TABLE IF NOT EXISTS t59 (f59 INT);
CREATE TABLE IF NOT EXISTS t60 (f60 INT);
CREATE OR REPLACE VIEW v60 AS SELECT * FROM t60;
 
EXPLAIN
 SELECT t0.*
FROM t0
JOIN t1
    ON t1.f1 = t0.f0
LEFT JOIN t2
    ON t0.f0 = t2.f2
LEFT JOIN t3
    ON t0.f0 = t3.f3
LEFT JOIN t4
    ON t0.f0 = t4.f4
LEFT JOIN t5
    ON t4.f4 = t5.f5
LEFT JOIN t6
    ON t0.f0 = t6.f6
LEFT JOIN t7
    ON t0.f0 = t7.f7
LEFT JOIN t8
    ON t0.f0 = t8.f8
LEFT JOIN t9
    ON t0.f0 = t9.f9
LEFT JOIN t10
    ON t0.f0 = t10.f10
LEFT JOIN t11
    ON t0.f0 = t11.f11
LEFT JOIN t12
    ON t0.f0 = t12.f12
LEFT JOIN t13
    ON t0.f0 = t13.f13
LEFT JOIN t14
    ON t0.f0 = t14.f14
LEFT JOIN t15
    ON t0.f0 = t15.f15
LEFT JOIN t16
    ON t0.f0 = t16.f16
LEFT JOIN t17
    ON t0.f0 = t17.f17
LEFT JOIN t18
    ON t0.f0 = t18.f18
LEFT JOIN t19
    ON t18.f18 = t19.f19
LEFT JOIN t20
    ON t20.f20 = t19.f19
LEFT JOIN t21
    ON t20.f20 = t21.f21
LEFT JOIN t22
    ON t19.f19 = t22.f22
LEFT JOIN t23
    ON t23.f23 = t0.f0
LEFT JOIN t24
    ON t24.f24 = t23.f23
LEFT JOIN t25
    ON t0.f0 = t25.f25
LEFT JOIN t26
    ON t26.f26 = t0.f0
LEFT JOIN t27
    ON t27.f27 = t0.f0
LEFT JOIN t28
    ON t0.f0 = t28.f28
LEFT JOIN t29
    ON t0.f0 = t29.f29
LEFT JOIN t30
    ON t30.f30 = t0.f0
LEFT JOIN t31
    ON t0.f0 = t31.f31
LEFT JOIN t32
    ON t32.f32 = t31.f31
LEFT JOIN t33
    ON t33.f33 = t0.f0
LEFT JOIN t34
    ON t33.f33 = t34.f34
LEFT JOIN t35
    ON t33.f33 = t35.f35
LEFT JOIN t36
    ON t36.f36 = t0.f0
LEFT JOIN t37
    ON t32.f32 = t37.f37
LEFT JOIN t38
    ON t31.f31 = t38.f38
LEFT JOIN t39
    ON t39.f39 = t0.f0
LEFT JOIN t40
    ON t40.f40 = t39.f39
LEFT JOIN t41
    ON t41.f41 = t0.f0
LEFT JOIN t42
    ON t42.f42 = t41.f41
LEFT JOIN t43
    ON t43.f43 = t41.f41
LEFT JOIN t44
    ON t44.f44 = t0.f0
LEFT JOIN t45
    ON t45.f45 = t0.f0
LEFT JOIN t46
    ON t46.f46 = t0.f0
LEFT JOIN t47
    ON t47.f47 = t0.f0
LEFT JOIN t48
    ON t48.f48 = t0.f0
LEFT JOIN t49
    ON t0.f0 = t49.f49
LEFT JOIN t50
    ON t0.f0 = t50.f50
LEFT JOIN t51
    ON t0.f0 = t51.f51
LEFT JOIN t52
    ON t52.f52 = t0.f0
LEFT JOIN t53
    ON t53.f53 = t0.f0
LEFT JOIN t54
    ON t54.f54 = t0.f0
LEFT JOIN t55
    ON t55.f55 = t0.f0
LEFT JOIN t56
    ON t56.f56 = t0.f0
LEFT JOIN t57
    ON t57.f57 = t0.f0
LEFT JOIN t58
    ON t58.f58 = t57.f57
LEFT JOIN t59
    ON t36.f36 = t59.f59
LEFT JOIN v60
    ON t36.f36 = v60.f60
;

Comment by Christophe Deprez [ 2017-04-04 ]

I am affected by this bug as well.

170404 10:58:20 [ERROR] 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.
 
To report this bug, see https://mariadb.com/kb/en/reporting-bugs
 
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.
 
Server version: 10.1.22-MariaDB
key_buffer_size=536870912
read_buffer_size=2097152
max_used_connections=1
max_threads=752
thread_count=1
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 3619904 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.
 
Thread pointer: 0x7fb2e720d008
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 = 0x7fb3297020b0 thread_stack 0x48400
/usr/sbin/mysqld(my_print_stacktrace+0x2e)[0x7fb32a2d410e]
/usr/sbin/mysqld(handle_fatal_signal+0x305)[0x7fb329df79d5]
/lib64/libpthread.so.0(+0xf370)[0x7fb329412370]
/usr/sbin/mysqld(_ZN10TABLE_LIST20fetch_number_of_rowsEv+0x30)[0x7fb329d24740]
/usr/sbin/mysqld(+0x47f215)[0x7fb329cc0215]
/usr/sbin/mysqld(_ZN4JOIN14optimize_innerEv+0x72f)[0x7fb329cc89ff]
/usr/sbin/mysqld(_ZN4JOIN8optimizeEv+0x2f)[0x7fb329ccb2bf]
/usr/sbin/mysqld(_Z12mysql_selectP3THDPPP4ItemP10TABLE_LISTjR4ListIS1_ES2_jP8st_orderSB_S2_SB_yP13select_resultP18st_select_lex_unitP13st_select_lex+0x8f)[0x7fb329ccb3ff]
/usr/sbin/mysqld(_Z19mysql_explain_unionP3THDP18st_select_lex_unitP13select_result+0x120)[0x7fb329ccc0e0]
mysys/stacktrace.c:268(my_print_stacktrace)[0x7fb329c6b4cb]
sql/table.cc:7299(TABLE_LIST::fetch_number_of_rows())[0x7fb329c776cb]
/usr/sbin/mysqld(_Z11mysql_parseP3THDPcjP12Parser_state+0x332)[0x7fb329c7aca2]
sql/sql_select.cc:3580(make_join_statistics(JOIN*, List<TABLE_LIST>&, st_dynamic_array*))[0x7fb329c7e17a]
sql/sql_parse.cc:5862(execute_sqlcom_select(THD*, TABLE_LIST*))[0x7fb329c7e9da]
sql/sql_connect.cc:1349(do_handle_one_connection(THD*))[0x7fb329d4662a]
sql/sql_connect.cc:1263(handle_one_connection)[0x7fb329d467d0]
/lib64/libpthread.so.0(+0x7dc5)[0x7fb32940adc5]
/lib64/libc.so.6(clone+0x6d)[0x7fb32782973d]

Comment by Christophe Deprez [ 2017-04-05 ]

The issue is reproducible in MariaDB 10.2.5.
The query fails with

ERROR 2013 (HY000): Lost connection to MySQL server during query

Comment by Sergei Petrunia [ 2018-03-21 ]

Review feedback provided over email
https://lists.launchpad.net/maria-developers/msg11144.html

Comment by Varun Gupta (Inactive) [ 2018-03-23 ]

Patch addressing the review comments
http://lists.askmonty.org/pipermail/commits/2018-March/012128.html

Comment by Varun Gupta (Inactive) [ 2018-03-27 ]

Pushed to 5.5

Generated at Thu Feb 08 07:48:40 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.