[MDEV-29017] SIGSEGV in Bitmap<64u>::merge on SELECT Created: 2022-07-03  Updated: 2023-11-28

Status: Confirmed
Project: MariaDB Server
Component/s: Optimizer, Optimizer - Window functions
Affects Version/s: 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11
Fix Version/s: 10.4, 10.5, 10.6

Type: Bug Priority: Major
Reporter: Roel Van de Paar Assignee: Sergei Petrunia
Resolution: Unresolved Votes: 0
Labels: not-10.3, regression-10.4

Issue Links:
Relates
relates to MDEV-22498 SIGSEGV in Bitmap<64u>::merge on SELECT Closed
relates to MDEV-22825 Server crashes in Bitmap<64u>::merge ... Confirmed
relates to MDEV-28509 Server crash via Item_func_ne::add_ke... In Review
relates to MDEV-32085 Server crash in add_key_field Closed

 Description   

Very similar to MDEV-28509, however in this case only 10.4+ crashes, and the stack is a bit different.

CREATE TABLE c(c INT) ENGINE=InnoDB;
SELECT * FROM c AS c WHERE c=c + 0 / 0 WINDOW c AS(ORDER BY (SELECT * FROM c GROUP BY c HAVING c=- 0 OR c>0 AND NOT c<c WINDOW c AS(PARTITION BY c)));

Leads to:

10.10.0 081a284712bb661349e2e3802077b12211cede3e (Debug)

Core was generated by `/test/MD310522-mariadb-10.10.0-linux-x86_64-dbg/bin/mysqld --no-defaults --core'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  Bitmap<64u>::merge (map2=..., this=<optimized out>)
    at /test/10.10_dbg/sql/sql_bitmap.h:210
[Current thread is 1 (Thread 0x153cf77fb700 (LWP 3568523))]
(gdb) bt
#0  Bitmap<64u>::merge (map2=<optimized out>, this=<optimized out>) at /test/10.10_dbg/sql/sql_bitmap.h:210
#1  add_key_field (join=join@entry=0x153cdc0255a0, key_fields=key_fields@entry=0x153cf77f9408, and_level=1, cond=cond@entry=0x153cdc026860, field=0x153cdc029d48, eq_func=eq_func@entry=true, value=0x153cf77f92e0, num_values=1, usable_tables=18446744073709551615, sargables=0x153cf77f9528, row_col_no=0) at /test/10.10_dbg/sql/sql_select.cc:6304
#2  0x00005558293a2ed9 in Item_equal::add_key_fields (this=0x153cdc026860, join=0x153cdc0255a0, key_fields=0x153cf77f9408, and_level=0x153cf77f9404, usable_tables=18446744073709551615, sargables=0x153cf77f9528) at /test/10.10_dbg/sql/sql_select.cc:6749
#3  0x00005558293a2354 in Item_cond::add_key_fields (this=<optimized out>, join=0x153cdc0255a0, key_fields=0x153cf77f9408, and_level=0x153cf77f9404, usable_tables=18446744073709551615, sargables=0x153cf77f9528) at /test/10.10_dbg/sql/sql_list.h:443
#4  0x00005558293a32a8 in update_ref_and_keys (thd=thd@entry=0x153cdc000db8, keyuse=keyuse@entry=0x153cdc0258c0, join_tab=0x153cdc0269c8, tables=1, cond=0x153cdc016e98, normal_tables=normal_tables@entry=18446744073709551615, select_lex=0x153cdc015188, sargables=0x153cf77f9528) at /test/10.10_dbg/sql/sql_select.cc:7178
#5  0x00005558293d9668 in make_join_statistics (join=join@entry=0x153cdc0255a0, tables_list=@0x153cdc0153a0: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x153cdc025b58, last = 0x153cdc025b58, elements = 1}, <No data fields>}, keyuse_array=keyuse_array@entry=0x153cdc0258c0) at /test/10.10_dbg/sql/sql_select.cc:5430
#6  0x00005558293e2012 in JOIN::optimize_inner (this=this@entry=0x153cdc0255a0) at /test/10.10_dbg/sql/sql_select.cc:2503
#7  0x00005558293e2452 in JOIN::optimize (this=this@entry=0x153cdc0255a0) at /test/10.10_dbg/sql/sql_select.cc:1845
#8  0x0000555829326a24 in st_select_lex::optimize_unflattened_subqueries (this=0x153cdc013db8, const_only=const_only@entry=true) at /test/10.10_dbg/sql/sql_lex.cc:4916
#9  0x00005558295156a1 in JOIN::optimize_constant_subqueries (this=this@entry=0x153cdc024ad8) at /test/10.10_dbg/sql/opt_subselect.cc:5622
#10 0x00005558293e0f76 in JOIN::optimize_inner (this=this@entry=0x153cdc024ad8) at /test/10.10_dbg/sql/sql_select.cc:2165
#11 0x00005558293e2452 in JOIN::optimize (this=this@entry=0x153cdc024ad8) at /test/10.10_dbg/sql/sql_select.cc:1845
#12 0x00005558293e2545 in mysql_select (thd=thd@entry=0x153cdc000db8, tables=0x153cdc0143a0, fields=@0x153cdc014058: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x153cdc014348, last = 0x153cdc014348, elements = 1}, <No data fields>}, conds=0x153cdc014f48, og_num=1, order=0x0, group=0x153cdc015f80, having=0x0, proc_param=0x0, select_options=2147748608, result=0x153cdc024ab0, unit=0x153cdc004fd8, select_lex=0x153cdc013db8) at /test/10.10_dbg/sql/sql_select.cc:5030
#13 0x00005558293e2d8e in handle_select (thd=thd@entry=0x153cdc000db8, lex=lex@entry=0x153cdc004f00, result=result@entry=0x153cdc024ab0, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.10_dbg/sql/sql_select.cc:578
#14 0x000055582934eb5e in execute_sqlcom_select (thd=thd@entry=0x153cdc000db8, all_tables=0x153cdc0143a0) at /test/10.10_dbg/sql/sql_parse.cc:6260
#15 0x000055582935ae70 in mysql_execute_command (thd=thd@entry=0x153cdc000db8, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/10.10_dbg/sql/sql_parse.cc:3944
#16 0x0000555829348e3a in mysql_parse (thd=thd@entry=0x153cdc000db8, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x153cf77fa470) at /test/10.10_dbg/sql/sql_parse.cc:8036
#17 0x0000555829356422 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x153cdc000db8, packet=packet@entry=0x153cdc00b6d9 "SELECT * FROM c AS c WHERE c=c + 0 / 0 WINDOW c AS(ORDER BY (SELECT * FROM c GROUP BY c HAVING c=- 0 OR c>0 AND NOT c<c WINDOW c AS(PARTITION BY c)))", packet_length=packet_length@entry=149, blocking=blocking@entry=true) at /test/10.10_dbg/sql/sql_class.h:1364
#18 0x0000555829358b2c in do_command (thd=0x153cdc000db8, blocking=blocking@entry=true) at /test/10.10_dbg/sql/sql_parse.cc:1407
#19 0x00005558294b83c0 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x55582c89dfb8, put_in_cache=put_in_cache@entry=true) at /test/10.10_dbg/sql/sql_connect.cc:1418
#20 0x00005558294b88c9 in handle_one_connection (arg=0x55582c89dfb8) at /test/10.10_dbg/sql/sql_connect.cc:1312
#21 0x0000153d30286609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#22 0x0000153d2fe72133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.4.26 (dbg), 10.4.26 (opt), 10.5.17 (dbg), 10.5.17 (opt), 10.6.9 (dbg), 10.6.9 (opt), 10.7.5 (dbg), 10.7.5 (opt), 10.8.4 (dbg), 10.8.4 (opt), 10.9.2 (dbg), 10.9.2 (opt), 10.10.0 (dbg), 10.10.0 (opt)

Bug (or feature/syntax) confirmed not present in:
MariaDB: 10.3.36 (dbg), 10.3.36 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.51 (dbg), 5.6.51 (opt), 5.7.38 (dbg), 5.7.38 (opt), 8.0.29 (dbg), 8.0.29 (opt)



 Comments   
Comment by Roel Van de Paar [ 2022-07-14 ]

Secondary testcase with slightly different stack

CREATE TABLE c(c DEC) ENGINE=InnoDB;
SELECT * FROM c AS c WHERE c IS NULL OR c<0 / TRUE * 0 WINDOW c AS(PARTITION BY c AND -0 BETWEEN(SELECT * FROM c GROUP BY c HAVING ((c=c AND c BETWEEN 0 AND 0)) WINDOW c AS(PARTITION BY c)) AND -0);

Leads to:

10.10.0 081a284712bb661349e2e3802077b12211cede3e (Debug)

Core was generated by `/test/MD310522-mariadb-10.10.0-linux-x86_64-dbg/bin/mysqld --no-defaults --core'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  Bitmap<64u>::merge (map2=..., this=<optimized out>)
    at /test/10.10_dbg/sql/sql_bitmap.h:210
[Current thread is 1 (Thread 0x15203d110700 (LWP 3408256))]
(gdb) bt
#0  Bitmap<64u>::merge (map2=<optimized out>, this=<optimized out>) at /test/10.10_dbg/sql/sql_bitmap.h:210
#1  add_key_field (join=join@entry=0x152008025860, key_fields=key_fields@entry=0x15203d10e408, and_level=and_level@entry=0, cond=cond@entry=0x152008016a28, field=field@entry=0x152008029d48, eq_func=eq_func@entry=true, value=0x152008016b60, num_values=1, usable_tables=18446744073709551615, sargables=0x15203d10e528, row_col_no=0) at /test/10.10_dbg/sql/sql_select.cc:6304
#2  0x00005576cfbe80ca in add_key_equal_fields (join=join@entry=0x152008025860, key_fields=key_fields@entry=0x15203d10e408, and_level=0, cond=cond@entry=0x152008016a28, field_item=0x152008025060, eq_func=eq_func@entry=true, val=0x152008016b60, num_values=1, usable_tables=18446744073709551615, sargables=0x15203d10e528, row_col_no=0) at /test/10.10_dbg/sql/sql_select.cc:6421
#3  0x00005576cfbf17a7 in Item_func_between::add_key_fields (this=0x152008016a28, join=0x152008025860, key_fields=0x15203d10e408, and_level=0x15203d10e404, usable_tables=18446744073709551615, sargables=0x15203d10e528) at /test/10.10_dbg/sql/sql_select.cc:6587
#4  0x00005576cfbf12da in Item_cond_and::add_key_fields (this=<optimized out>, join=0x152008025860, key_fields=0x15203d10e408, and_level=0x15203d10e404, usable_tables=18446744073709551615, sargables=0x15203d10e528) at /test/10.10_dbg/sql/sql_select.cc:6496
#5  0x00005576cfbf22a8 in update_ref_and_keys (thd=thd@entry=0x152008000db8, keyuse=keyuse@entry=0x152008025b80, join_tab=0x152008026728, tables=1, cond=0x152008026610, normal_tables=normal_tables@entry=18446744073709551615, select_lex=0x152008015598, sargables=0x15203d10e528) at /test/10.10_dbg/sql/sql_select.cc:7178
#6  0x00005576cfc28668 in make_join_statistics (join=join@entry=0x152008025860, tables_list=@0x1520080157b0: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x152008025e18, last = 0x152008025e18, elements = 1}, <No data fields>}, keyuse_array=keyuse_array@entry=0x152008025b80) at /test/10.10_dbg/sql/sql_select.cc:5430
#7  0x00005576cfc31012 in JOIN::optimize_inner (this=this@entry=0x152008025860) at /test/10.10_dbg/sql/sql_select.cc:2503
#8  0x00005576cfc31452 in JOIN::optimize (this=this@entry=0x152008025860) at /test/10.10_dbg/sql/sql_select.cc:1845
#9  0x00005576cfb75a24 in st_select_lex::optimize_unflattened_subqueries (this=0x152008013e18, const_only=const_only@entry=true) at /test/10.10_dbg/sql/sql_lex.cc:4916
#10 0x00005576cfd646a1 in JOIN::optimize_constant_subqueries (this=this@entry=0x152008024a98) at /test/10.10_dbg/sql/opt_subselect.cc:5622
#11 0x00005576cfc2ff76 in JOIN::optimize_inner (this=this@entry=0x152008024a98) at /test/10.10_dbg/sql/sql_select.cc:2165
#12 0x00005576cfc31452 in JOIN::optimize (this=this@entry=0x152008024a98) at /test/10.10_dbg/sql/sql_select.cc:1845
#13 0x00005576cfc31545 in mysql_select (thd=thd@entry=0x152008000db8, tables=0x152008014400, fields=@0x1520080140b8: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x1520080143a8, last = 0x1520080143a8, elements = 1}, <No data fields>}, conds=0x1520080152f0, og_num=1, order=0x0, group=0x152008016390, having=0x0, proc_param=0x0, select_options=2147748608, result=0x152008024a70, unit=0x152008004fd8, select_lex=0x152008013e18) at /test/10.10_dbg/sql/sql_select.cc:5030
#14 0x00005576cfc31d8e in handle_select (thd=thd@entry=0x152008000db8, lex=lex@entry=0x152008004f00, result=result@entry=0x152008024a70, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.10_dbg/sql/sql_select.cc:578
#15 0x00005576cfb9db5e in execute_sqlcom_select (thd=thd@entry=0x152008000db8, all_tables=0x152008014400) at /test/10.10_dbg/sql/sql_parse.cc:6260
#16 0x00005576cfba9e70 in mysql_execute_command (thd=thd@entry=0x152008000db8, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/10.10_dbg/sql/sql_parse.cc:3944
#17 0x00005576cfb97e3a in mysql_parse (thd=thd@entry=0x152008000db8, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x15203d10f470) at /test/10.10_dbg/sql/sql_parse.cc:8036
#18 0x00005576cfba5422 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x152008000db8, packet=packet@entry=0x15200800b6d9 "SELECT * FROM c AS c WHERE c IS NULL OR c<0 / TRUE * 0 WINDOW c AS(PARTITION BY c AND -0 BETWEEN(SELECT * FROM c GROUP BY c HAVING ((c=c AND c BETWEEN 0 AND 0)) WINDOW c AS(PARTITION BY c)) AND -0)", packet_length=packet_length@entry=197, blocking=blocking@entry=true) at /test/10.10_dbg/sql/sql_class.h:1364
#19 0x00005576cfba7b2c in do_command (thd=0x152008000db8, blocking=blocking@entry=true) at /test/10.10_dbg/sql/sql_parse.cc:1407
#20 0x00005576cfd073c0 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x5576d2fc9ef8, put_in_cache=put_in_cache@entry=true) at /test/10.10_dbg/sql/sql_connect.cc:1418
#21 0x00005576cfd078c9 in handle_one_connection (arg=0x5576d2fc9ef8) at /test/10.10_dbg/sql/sql_connect.cc:1312
#22 0x0000152055fb5609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#23 0x0000152055ba1133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.4.26 (dbg), 10.4.26 (opt), 10.5.17 (dbg), 10.5.17 (opt), 10.6.9 (dbg), 10.6.9 (opt), 10.7.5 (dbg), 10.7.5 (opt), 10.8.4 (dbg), 10.8.4 (opt), 10.9.2 (dbg), 10.9.2 (opt), 10.10.0 (dbg), 10.10.0 (opt)

Bug (or feature/syntax) confirmed not present in:
MariaDB: 10.3.36 (dbg), 10.3.36 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.51 (dbg), 5.6.51 (opt), 5.7.38 (dbg), 5.7.38 (opt), 8.0.29 (dbg), 8.0.29 (opt)

Comment by Roel Van de Paar [ 2022-08-24 ]

Additional stack with this testcase

CREATE TABLE c (c DEC) ENGINE=InnoDB;
SELECT * FROM c AS c WHERE c=1 WINDOW c AS (ORDER BY (SELECT * FROM c GROUP BY c HAVING c=1 WINDOW c AS (PARTITION BY c)));

Leads to:

10.11.0 bc563f1a4b0b38de3b41fd0f0d3d8b7f1aacbd8b (Debug)

Core was generated by `/test/MD190822-mariadb-10.11.0-linux-x86_64-dbg/bin/mysqld --no-defaults --core'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  Bitmap<64u>::merge (map2=..., this=<optimized out>)
    at /test/10.11_dbg/sql/sql_bitmap.h:210
[Current thread is 1 (Thread 0x14b35405a700 (LWP 2059048))]
(gdb) bt
#0  Bitmap<64u>::merge (map2=<optimized out>, this=<optimized out>) at /test/10.11_dbg/sql/sql_bitmap.h:210
#1  add_key_field (join=join@entry=0x14b2f406ed18, key_fields=key_fields@entry=0x14b3540582d8, and_level=and_level@entry=0, cond=cond@entry=0x14b2f4015e38, field=field@entry=0x14b2f40258a8, eq_func=eq_func@entry=true, value=0x14b2f4015eb8, num_values=1, usable_tables=18446744073709551615, sargables=0x14b3540583f8, row_col_no=0) at /test/10.11_dbg/sql/sql_select.cc:6352
#2  0x0000558bf8692133 in add_key_equal_fields (join=join@entry=0x14b2f406ed18, key_fields=key_fields@entry=0x14b3540582d8, and_level=0, cond=cond@entry=0x14b2f4015e38, field_item=0x14b2f40176f8, eq_func=eq_func@entry=true, val=0x14b2f4015eb8, num_values=1, usable_tables=18446744073709551615, sargables=0x14b3540583f8, row_col_no=0) at /test/10.11_dbg/sql/sql_select.cc:6473
#3  0x0000558bf869bc95 in Item_bool_func2::add_key_fields_optimize_op (this=0x14b2f4015e38, join=0x14b2f406ed18, key_fields=0x14b3540582d8, and_level=0x14b3540582d4, usable_tables=18446744073709551615, sargables=0x14b3540583f8, equal_func=true) at /test/10.11_dbg/sql/sql_select.cc:6750
#4  0x0000558bf899dd5d in Item_func_eq::add_key_fields (this=<optimized out>, join=<optimized out>, key_fields=<optimized out>, and_level=<optimized out>, usable_tables=<optimized out>, sargables=<optimized out>) at /test/10.11_dbg/sql/item_cmpfunc.h:775
#5  0x0000558bf869c2d0 in update_ref_and_keys (thd=thd@entry=0x14b2f4000db8, keyuse=keyuse@entry=0x14b2f406f068, join_tab=0x14b2f406fa38, tables=1, cond=0x14b2f4015e38, normal_tables=normal_tables@entry=18446744073709551615, select_lex=0x14b2f4014e60, sargables=0x14b3540583f8) at /test/10.11_dbg/sql/sql_select.cc:7230
#6  0x0000558bf86d3c93 in make_join_statistics (join=join@entry=0x14b2f406ed18, tables_list=@0x14b2f4015078: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14b2f4017b48, last = 0x14b2f4017b48, elements = 1}, <No data fields>}, keyuse_array=keyuse_array@entry=0x14b2f406f068) at /test/10.11_dbg/sql/sql_select.cc:5478
#7  0x0000558bf86dc626 in JOIN::optimize_inner (this=this@entry=0x14b2f406ed18) at /test/10.11_dbg/sql/sql_select.cc:2524
#8  0x0000558bf86dca66 in JOIN::optimize (this=this@entry=0x14b2f406ed18) at /test/10.11_dbg/sql/sql_select.cc:1863
#9  0x0000558bf861f3f0 in st_select_lex::optimize_unflattened_subqueries (this=0x14b2f4013d98, const_only=const_only@entry=true) at /test/10.11_dbg/sql/sql_lex.cc:4915
#10 0x0000558bf88109c1 in JOIN::optimize_constant_subqueries (this=this@entry=0x14b2f406e730) at /test/10.11_dbg/sql/opt_subselect.cc:5689
#11 0x0000558bf86db58a in JOIN::optimize_inner (this=this@entry=0x14b2f406e730) at /test/10.11_dbg/sql/sql_select.cc:2186
#12 0x0000558bf86dca66 in JOIN::optimize (this=this@entry=0x14b2f406e730) at /test/10.11_dbg/sql/sql_select.cc:1863
#13 0x0000558bf86dcb59 in mysql_select (thd=thd@entry=0x14b2f4000db8, tables=0x14b2f4014380, fields=@0x14b2f4014038: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14b2f4014328, last = 0x14b2f4014328, elements = 1}, <No data fields>}, conds=0x14b2f4014c20, og_num=1, order=0x0, group=0x14b2f4015c58, having=0x0, proc_param=0x0, select_options=2164525824, result=0x14b2f40176c0, unit=0x14b2f4004ff0, select_lex=0x14b2f4013d98) at /test/10.11_dbg/sql/sql_select.cc:5056
#14 0x0000558bf86dd3a2 in handle_select (thd=thd@entry=0x14b2f4000db8, lex=lex@entry=0x14b2f4004f18, result=result@entry=0x14b2f40176c0, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.11_dbg/sql/sql_select.cc:581
#15 0x0000558bf86475a6 in execute_sqlcom_select (thd=thd@entry=0x14b2f4000db8, all_tables=0x14b2f4014380) at /test/10.11_dbg/sql/sql_parse.cc:6261
#16 0x0000558bf86538c7 in mysql_execute_command (thd=thd@entry=0x14b2f4000db8, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/10.11_dbg/sql/sql_parse.cc:3945
#17 0x0000558bf8641882 in mysql_parse (thd=thd@entry=0x14b2f4000db8, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x14b354059330) at /test/10.11_dbg/sql/sql_parse.cc:8035
#18 0x0000558bf864ee6a in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x14b2f4000db8, packet=packet@entry=0x14b2f400b6e9 "SELECT * FROM c AS c WHERE c=1 WINDOW c AS (ORDER BY (SELECT * FROM c GROUP BY c HAVING c=1 WINDOW c AS (PARTITION BY c)))", packet_length=packet_length@entry=122, blocking=blocking@entry=true) at /test/10.11_dbg/sql/sql_class.h:1339
#19 0x0000558bf8651574 in do_command (thd=0x14b2f4000db8, blocking=blocking@entry=true) at /test/10.11_dbg/sql/sql_parse.cc:1407
#20 0x0000558bf87b31da in do_handle_one_connection (connect=<optimized out>, connect@entry=0x558bfb169118, put_in_cache=put_in_cache@entry=true) at /test/10.11_dbg/sql/sql_connect.cc:1418
#21 0x0000558bf87b36e3 in handle_one_connection (arg=0x558bfb169118) at /test/10.11_dbg/sql/sql_connect.cc:1312
#22 0x000014b36b4e6609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#23 0x000014b36b0d2133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.4.27 (dbg), 10.5.18 (dbg), 10.5.18 (opt), 10.6.10 (dbg), 10.6.10 (opt), 10.7.6 (dbg), 10.7.6 (opt), 10.8.5 (dbg), 10.8.5 (opt), 10.9.2 (dbg), 10.9.2 (opt), 10.10.2 (dbg), 10.10.2 (opt), 10.11.0 (dbg), 10.11.0 (opt)

Bug (or feature/syntax) confirmed not present in:
MariaDB: 10.3.37 (dbg), 10.3.37 (opt), 10.4.27 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.51 (dbg), 5.6.51 (opt), 5.7.38 (dbg), 5.7.38 (opt), 8.0.29 (dbg), 8.0.29 (opt)

Comment by Roel Van de Paar [ 2022-12-19 ]

Additional testcase. Crashes irrespective of InnoDB or MyISAM being used. Produces slightly different stack.

CREATE TABLE c (c INT);
SELECT * FROM c AS c WHERE c=1 WINDOW c AS (ORDER BY (SELECT * FROM c GROUP BY c HAVING c=1 WINDOW c AS (PARTITION BY c)));

Leads to:

10.11.2 c194db34d93d8d94bd52b17349063fa401e3f942 (Debug)

Core was generated by `/test/MD171222-mariadb-10.11.2-linux-x86_64-dbg/bin/mysqld --no-defaults --core'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  Bitmap<64u>::merge (map2=..., this=<optimized out>)
    at /test/10.11_dbg/sql/sql_bitmap.h:210
210	    for (size_t i= 0; i < ARRAY_ELEMENTS; i++)
[Current thread is 1 (Thread 0x151e170fc700 (LWP 3685023))]
(gdb) bt
#0  Bitmap<64u>::merge (map2=<optimized out>, this=<optimized out>) at /test/10.11_dbg/sql/sql_bitmap.h:210
#1  add_key_field (join=join@entry=0x151de0067e08, key_fields=key_fields@entry=0x151e170fa2a8, and_level=0, cond=cond@entry=0x151de0068ce8, field=0x151de0023a28, eq_func=eq_func@entry=true, value=0x151e170fa210, num_values=1, usable_tables=18446744073709551615, sargables=0x151e170fa3c8, row_col_no=0) at /test/10.11_dbg/sql/sql_select.cc:6362
#2  0x000055aeb10befb3 in Item_equal::add_key_fields (this=0x151de0068ce8, join=0x151de0067e08, key_fields=0x151e170fa2a8, and_level=0x151e170fa2a4, usable_tables=18446744073709551615, sargables=0x151e170fa3c8) at /test/10.11_dbg/sql/sql_select.cc:6811
#3  0x000055aeb10bf352 in update_ref_and_keys (thd=thd@entry=0x151de0000d48, keyuse=keyuse@entry=0x151de0068158, join_tab=0x151de0068e68, tables=1, cond=0x151de0068ce8, normal_tables=normal_tables@entry=18446744073709551615, select_lex=0x151de0014378, sargables=0x151e170fa3c8) at /test/10.11_dbg/sql/sql_select.cc:7240
#4  0x000055aeb10f5a4d in make_join_statistics (join=join@entry=0x151de0067e08, tables_list=@0x151de0014590: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x151de0016fb0, last = 0x151de0016fb0, elements = 1}, <No data fields>}, keyuse_array=keyuse_array@entry=0x151de0068158) at /test/10.11_dbg/sql/sql_select.cc:5488
#5  0x000055aeb10fe155 in JOIN::optimize_inner (this=this@entry=0x151de0067e08) at /test/10.11_dbg/sql/sql_select.cc:2534
#6  0x000055aeb10fe577 in JOIN::optimize (this=this@entry=0x151de0067e08) at /test/10.11_dbg/sql/sql_select.cc:1870
#7  0x000055aeb1045ec0 in st_select_lex::optimize_unflattened_subqueries (this=0x151de0013278, const_only=const_only@entry=true) at /test/10.11_dbg/sql/sql_lex.cc:4907
#8  0x000055aeb122d50f in JOIN::optimize_constant_subqueries (this=this@entry=0x151de00675f0) at /test/10.11_dbg/sql/opt_subselect.cc:5689
#9  0x000055aeb10fd1fa in JOIN::optimize_inner (this=this@entry=0x151de00675f0) at /test/10.11_dbg/sql/sql_select.cc:2193
#10 0x000055aeb10fe577 in JOIN::optimize (this=this@entry=0x151de00675f0) at /test/10.11_dbg/sql/sql_select.cc:1870
#11 0x000055aeb10fe667 in mysql_select (thd=thd@entry=0x151de0000d48, tables=0x151de0013868, fields=@0x151de0013518: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x151de0013810, last = 0x151de0013810, elements = 1}, <No data fields>}, conds=0x151de0014138, og_num=1, order=0x0, group=0x151de00151a8, having=0x0, proc_param=0x0, select_options=2164525824, result=0x151de0016c70, unit=0x151de0004f88, select_lex=0x151de0013278) at /test/10.11_dbg/sql/sql_select.cc:5066
#12 0x000055aeb10fee2d in handle_select (thd=thd@entry=0x151de0000d48, lex=lex@entry=0x151de0004eb0, result=result@entry=0x151de0016c70, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.11_dbg/sql/sql_select.cc:581
#13 0x000055aeb106c36d in execute_sqlcom_select (thd=thd@entry=0x151de0000d48, all_tables=0x151de0013868) at /test/10.11_dbg/sql/sql_parse.cc:6265
#14 0x000055aeb10784a2 in mysql_execute_command (thd=thd@entry=0x151de0000d48, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/10.11_dbg/sql/sql_parse.cc:3949
#15 0x000055aeb10667f4 in mysql_parse (thd=thd@entry=0x151de0000d48, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x151e170fb300) at /test/10.11_dbg/sql/sql_parse.cc:8000
#16 0x000055aeb1073d2f in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x151de0000d48, packet=packet@entry=0x151de000adf9 "SELECT * FROM c AS c WHERE c=1 WINDOW c AS (ORDER BY (SELECT * FROM c GROUP BY c HAVING c=1 WINDOW c AS (PARTITION BY c)))", packet_length=packet_length@entry=122, blocking=blocking@entry=true) at /test/10.11_dbg/sql/sql_class.h:1346
#17 0x000055aeb107616d in do_command (thd=0x151de0000d48, blocking=blocking@entry=true) at /test/10.11_dbg/sql/sql_parse.cc:1407
#18 0x000055aeb11d1013 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x55aeb477b618, put_in_cache=put_in_cache@entry=true) at /test/10.11_dbg/sql/sql_connect.cc:1416
#19 0x000055aeb11d14e2 in handle_one_connection (arg=0x55aeb477b618) at /test/10.11_dbg/sql/sql_connect.cc:1318
#20 0x0000151e3c592609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#21 0x0000151e3c17e133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

10.4-10.11 dbg+opt affected.

Generated at Thu Feb 08 10:05:15 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.