[MDEV-22444] SIGSEGV's in __strlen_avx2, __GI___dl_iterate_phdr, decimal2string, Field_iterator_table::create_item, Item::operator new, Item::real_type (__cxa_pure_virtual) | Assertion `0' failed | UBSAN: execution reached an unreachable program point Created: 2020-05-04  Updated: 2023-11-28

Status: Confirmed
Project: MariaDB Server
Component/s: JSON, Optimizer
Affects Version/s: 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11, 11.0
Fix Version/s: 10.4, 10.5, 10.6, 10.11

Type: Bug Priority: Major
Reporter: Roel Van de Paar Assignee: Igor Babaev
Resolution: Unresolved Votes: 1
Labels: UBSAN, affects-tests, not-10.1, not-10.2, regression

Issue Links:
Relates
relates to MDEV-22716 Assertion `0' failed in Type_handler_... Confirmed

 Description   

USE test;
SET @@SESSION.optimizer_trace=1;
SET in_predicate_conversion_threshold=2;
CREATE TABLE t1(c1 YEAR);
SELECT * FROM t1 WHERE c1 IN(NOW(),NOW());

Leads to:

10.5.3 f544a712c8a2ef3f3ecba80cb2782b1839fb36ab

Core was generated by `/test/MD010520-mariadb-10.5.3-linux-x86_64-opt/bin/mysqld --no-defaults --core-'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=11)
    at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
[Current thread is 1 (Thread 0x7f3014945700 (LWP 2651979))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=11) at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
#1  0x000056440c77eac7 in my_write_core (sig=sig@entry=11) at /test/10.5_opt/mysys/stacktrace.c:518
#2  0x000056440c1407ca in handle_fatal_signal (sig=11) at /test/10.5_opt/sql/signal_handler.cc:329
#3  <signal handler called>
#4  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:62
#5  0x000056440c0819bf in Json_writer::add_str (this=this@entry=0x7f2fe24cc180, str=str@entry=0x0) at /test/10.5_opt/sql/my_json_writer.cc:230
#6  0x000056440bfe5c33 in Json_value_helper::add_str (val=0x0, this=<synthetic pointer>) at /test/10.5_opt/sql/my_json_writer.h:259
#7  Json_writer_object::add (value=0x0, name=0x56440c8ee205 "field", this=<synthetic pointer>) at /test/10.5_opt/sql/my_json_writer.h:428
#8  print_keyuse_array_for_trace (thd=thd@entry=0x7f2fe2412018, keyuse_array=keyuse_array@entry=0x7f2fe2448f48) at /test/10.5_opt/sql/sql_test.cc:669
#9  0x000056440bfa6d0b in make_join_statistics (keyuse_array=0x7f2fe2448f48, tables_list=..., join=0x7f2fe2448c58) at /test/10.5_opt/sql/sql_select.cc:5065
#10 JOIN::optimize_inner (this=this@entry=0x7f2fe2448c58) at /test/10.5_opt/sql/sql_select.cc:2260
#11 0x000056440bfa7a7b in JOIN::optimize (this=this@entry=0x7f2fe2448c58) at /test/10.5_opt/sql/sql_select.cc:1606
#12 0x000056440bfa7b81 in mysql_select (thd=thd@entry=0x7f2fe2412018, tables=0x7f2fe24476e0, fields=..., conds=0x7f2fe2448148, og_num=<optimized out>, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7f2fe2448c30, unit=0x7f2fe2415e68, select_lex=0x7f2fe24470e8) at /test/10.5_opt/sql/sql_select.cc:4655
#13 0x000056440bfa8591 in handle_select (thd=thd@entry=0x7f2fe2412018, lex=lex@entry=0x7f2fe2415da0, result=result@entry=0x7f2fe2448c30, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.5_opt/sql/sql_select.cc:417
#14 0x000056440bf4f171 in execute_sqlcom_select (thd=thd@entry=0x7f2fe2412018, all_tables=0x7f2fe24476e0) at /test/10.5_opt/sql/sql_parse.cc:6172
#15 0x000056440bf4b092 in mysql_execute_command (thd=thd@entry=0x7f2fe2412018) at /test/10.5_opt/sql/sql_parse.cc:3901
#16 0x000056440bf5222c in mysql_parse (thd=0x7f2fe2412018, rawbuf=<optimized out>, length=41, parser_state=0x7f30149444d0, is_com_multi=<optimized out>, is_next_command=<optimized out>) at /test/10.5_opt/sql/sql_parse.cc:7957
#17 0x000056440bf47855 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x7f2fe2412018, packet=packet@entry=0x7f2fe243a019 "SELECT * FROM t1 WHERE c1 IN(NOW(),NOW())", packet_length=packet_length@entry=41, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /test/10.5_opt/sql/sql_parse.cc:1839
#18 0x000056440bf45ae6 in do_command (thd=0x7f2fe2412018) at /test/10.5_opt/sql/sql_parse.cc:1358
#19 0x000056440c03a29e in do_handle_one_connection (connect=<optimized out>, connect@entry=0x7f30124329b8, put_in_cache=put_in_cache@entry=true) at /test/10.5_opt/sql/sql_connect.cc:1422
#20 0x000056440c03a444 in handle_one_connection (arg=arg@entry=0x7f30124329b8) at /test/10.5_opt/sql/sql_connect.cc:1319
#21 0x000056440c3a653a in pfs_spawn_thread (arg=0x7f301244b018) at /test/10.5_opt/storage/perfschema/pfs.cc:2201
#22 0x00007f3013d6c6db in start_thread (arg=0x7f3014945700) at pthread_create.c:463
#23 0x00007f301316a88f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.3.23 (dbg), 10.3.23 (opt), 10.4.13 (dbg), 10.4.13 (opt), 10.5.2 (dbg), 10.5.2 (opt), 10.5.3 (dbg), 10.5.3 (opt)

Bug confirmed not present in:
MariaDB: 10.1.45 (dbg), 10.1.45 (opt), 10.2.32 (dbg), 10.2.32 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.47 (dbg), 5.6.47 (opt), 5.7.29 (dbg), 5.7.29 (opt), 8.0.19 (dbg), 8.0.19 (opt)

Both optimizer_trace and in_predicate_conversion_threshold are unknown variables in 10.2.32, so the testcase does not work there.



 Comments   
Comment by Varun Gupta (Inactive) [ 2020-05-25 ]

The query fails without even enabling the optimizer trace.

SET in_predicate_conversion_threshold=2;
CREATE TABLE t1(c1 YEAR);
SELECT * FROM t1 WHERE c1 IN(NOW(),NOW());
drop table t1;

Comment by Varun Gupta (Inactive) [ 2020-07-07 ]

The stack trace on debug build looks like with ASAN

ASAN:SIGSEGV
=================================================================
==10954==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7efdf2324746 bp 0x7efde85d0e90 sp 0x7efde85d0618 T5)
    #0 0x7efdf2324745 in strlen (/lib/x86_64-linux-gnu/libc.so.6+0x8b745)
    #1 0x7efdf44af1a5 in __interceptor_strlen (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x701a5)
    #2 0x9802c8 in Field_iterator_table::create_item(THD*) /home/varun/MariaDB/10.3/sql/table.cc:6024
    #3 0x589a7c in Field_iterator_table_ref::create_item(THD*) /home/varun/MariaDB/10.3/sql/table.h:2884
    #4 0x5802ac in insert_fields(THD*, Name_resolution_context*, char const*, char const*, List_iterator<Item>*, bool, unsigned int*) /home/varun/MariaDB/10.3/sql/sql_base.cc:7977
    #5 0x57c710 in setup_wild(THD*, TABLE_LIST*, List<Item>&, List<Item>*, unsigned int, unsigned int*) /home/varun/MariaDB/10.3/sql/sql_base.cc:7397
    #6 0x755ddb in JOIN::prepare(TABLE_LIST*, unsigned int, Item*, unsigned int, st_order*, bool, st_order*, Item*, st_order*, st_select_lex*, st_select_lex_unit*) /home/varun/MariaDB/10.3/sql/sql_select.cc:1136
    #7 0x1000d73 in subselect_single_select_engine::prepare(THD*) /home/varun/MariaDB/10.3/sql/item_subselect.cc:3686
    #8 0xfddea2 in Item_subselect::fix_fields(THD*, Item**) /home/varun/MariaDB/10.3/sql/item_subselect.cc:276
    #9 0xffddf3 in Item_in_subselect::fix_fields(THD*, Item**) /home/varun/MariaDB/10.3/sql/item_subselect.cc:3349
    #10 0xba018d in Item_func_in::in_predicate_to_in_subs_transformer(THD*, unsigned char*) /home/varun/MariaDB/10.3/sql/sql_tvc.cc:988

Comment by Varun Gupta (Inactive) [ 2020-07-07 ]

Trying another simple case with views

SET in_predicate_conversion_threshold=2;
CREATE TABLE t1(a INT);
INSERT INTO t1 VALUES (1),(2);
 
CREATE VIEW v1 as SELECT a, 1 as b from t1;
SELECT * from v1 where a IN (b,2);

Comment by Varun Gupta (Inactive) [ 2020-07-07 ]

Debugging the case with views

We see in the function

     if (i == 1)
      {
        sprintf(col_name, "_col_%i", 1);
        args[i]->set_name(thd, col_name, strlen(col_name), thd->charset());
      }
      if (tvc_value->push_back(args[i]->real_item()))
        return true;

For the first argument in the IN predicate we assign the name _col_1. This name is assigned to args[i] but we push the
args[i]->real_item() in the value list. This looks odd.

Debugging further, checking when we create the items for the derived table with tvc
The stacktrace is

(lldb) bt
* thread #2, stop reason = step over
  * frame #0: 0x00000001011924b4 mysqld`Field_iterator_table::create_item(this=0x000070000afcf800, thd=0x000062a00005a270) at table.cc:6023:26
    frame #1: 0x0000000100a6d9ee mysqld`Field_iterator_table_ref::create_item(this=0x000070000afcf7e0, thd=0x000062a00005a270) at table.h:2884:50
    frame #2: 0x0000000100a64d5e mysqld`insert_fields(thd=0x000062a00005a270, context=0x000062b000005000, db_name=0x0000000000000000, table_name=0x0000000000000000, it=0x000070000afd0420, any_privileges=false, hidden_bit_fields=0x000062b000005298) at sql_base.cc:7977:34
    frame #3: 0x0000000100a635cf mysqld`setup_wild(thd=0x000062a00005a270, tables=0x0000629000064a20, fields=0x000062b0000050e0, sum_func_list=0x00006290000655c8, wild_num=1, hidden_bit_fields=0x000062b000005298) at sql_base.cc:7397:16
    frame #4: 0x0000000100df31ce mysqld`JOIN::prepare(this=0x00006290000652a8, tables_init=0x0000629000064a20, wild_num=1, conds_init=0x0000000000000000, og_num=0, order_init=0x0000000000000000, skip_order_by=false, group_init=0x0000000000000000, having_init=0x0000000000000000, proc_param_init=0x0000000000000000, select_lex_arg=0x000062b000004fb8, unit_arg=0x000062b0000053e0) at sql_select.cc:1136:7

I see that we create the item with the name b instead of _col_1

(lldb) p item->name.str
(const char *) $7 = 0x00006290000fe018 "b"
(lldb) p ptr[0]->field_name
(LEX_CSTRING) $8 = (str = "b", length = 1)

Looks like we need to set the name for the real_item() instead of the ref item in
Item_func_in::create_value_list_for_tv

Comment by Varun Gupta (Inactive) [ 2020-07-07 ]

Also the optimizer trace shows

{
    "expanded_query": "/* select#3 */ select tvc_0.b from (values (1),(2)) tvc_0"
}

Comment by Varun Gupta (Inactive) [ 2020-07-07 ]

Have made a small patch based on my observations

http://lists.askmonty.org/pipermail/commits/2020-July/014280.html

Comment by Roel Van de Paar [ 2020-07-20 ]

igor varun Reduced another testcase leading to a different stack:

USE test;
SET IN_PREDICATE_CONVERSION_THRESHOLD=2;
CREATE TABLE t(c BIGINT NOT NULL);
SELECT * FROM t WHERE c IN (CURDATE(),ADDDATE(CURDATE(),'a')) ORDER BY c;

Leads to:

10.5.5 30e7a0a866dce530d8328c6d614e48d39a264f9b (Debug)

Core was generated by `/test/MD140720-mariadb-10.5.5-linux-x86_64-dbg/bin/mysqld --no-defaults --core-'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=11)
    at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
[Current thread is 1 (Thread 0x145728d9a700 (LWP 284201))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=11) at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
#1  0x000055787658c4d7 in my_write_core (sig=sig@entry=11) at /test/10.5_dbg/mysys/stacktrace.c:518
#2  0x0000557875d469ba in handle_fatal_signal (sig=11) at /test/10.5_dbg/sql/signal_handler.cc:330
#3  <signal handler called>
#4  0x0000557875b9aab8 in Field_iterator_table::create_item (this=0x145728d97940, thd=0x145704015088) at /test/10.5_dbg/sql/table.cc:6673
#5  0x0000557875a2093a in Field_iterator_table_ref::create_item (thd=0x145704015088, this=0x145728d97920) at /test/10.5_dbg/sql/table.h:2937
#6  insert_fields (thd=thd@entry=0x145704015088, context=<optimized out>, db_name=0x0, table_name=0x0, it=it@entry=0x145728d97d00, any_privileges=any_privileges@entry=false, hidden_bit_fields=0x145704076d40) at /test/10.5_dbg/sql/sql_base.cc:8063
#7  0x0000557875a211de in setup_wild (thd=0x145704015088, tables=<optimized out>, fields=@0x145704076b80: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x1457040777d0, last = 0x1457040777d0, elements = 1}, <No data fields>}, sum_func_list=sum_func_list@entry=0x1457040791b8, select_lex=0x145704076a30) at /test/10.5_dbg/sql/sql_base.cc:7478
#8  0x0000557875b0b397 in JOIN::prepare (this=0x145704078e90, tables_init=<optimized out>, conds_init=<optimized out>, og_num=<optimized out>, order_init=<optimized out>, skip_order_by=skip_order_by@entry=false, group_init=0x0, having_init=0x0, proc_param_init=0x0, select_lex_arg=0x145704076a30, unit_arg=0x145704076e90) at /test/10.5_dbg/sql/sql_select.cc:1240
#9  0x0000557875e38191 in subselect_single_select_engine::prepare (this=0x145704078e50, thd=0x145704015088) at /test/10.5_dbg/sql/item_subselect.cc:3759
#10 0x0000557875e372e5 in Item_subselect::fix_fields (this=this@entry=0x145704078c10, thd_param=thd_param@entry=0x145704015088, ref=ref@entry=0x145728d98068) at /test/10.5_dbg/sql/item_subselect.cc:285
#11 0x0000557875e37989 in Item_in_subselect::fix_fields (this=0x145704078c10, thd_arg=0x145704015088, ref=0x145728d98068) at /test/10.5_dbg/sql/item_subselect.cc:3421
#12 0x0000557875ca1cde in Item_func_in::in_predicate_to_in_subs_transformer (this=0x145704075370, thd=thd@entry=0x145704015088, arg=arg@entry=0x0) at /test/10.5_dbg/sql/sql_tvc.cc:1019
#13 0x0000557875dd19d5 in Item_func::transform (this=0x145704075370, thd=0x145704015088, transformer=NULL, argument=0x0) at /test/10.5_dbg/sql/item_func.cc:519
#14 0x0000557875ca1dfe in JOIN::transform_in_predicates_into_in_subq (this=this@entry=0x145704076068, thd=0x145704015088) at /test/10.5_dbg/sql/sql_tvc.cc:1104
#15 0x0000557875b141bb in JOIN::optimize_inner (this=this@entry=0x145704076068) at /test/10.5_dbg/sql/sql_select.cc:1811
#16 0x0000557875b18222 in JOIN::optimize (this=this@entry=0x145704076068) at /test/10.5_dbg/sql/sql_select.cc:1618
#17 0x0000557875b18bac in mysql_select (thd=thd@entry=0x145704015088, tables=<optimized out>, fields=@0x1457040742e8: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x145704074748, last = 0x145704074748, elements = 1}, <No data fields>}, conds=0x145704075370, og_num=1, order=<optimized out>, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x145704076040, unit=0x1457040190a0, select_lex=0x145704074198) at /test/10.5_dbg/sql/sql_select.cc:4641
#18 0x0000557875b18f28 in handle_select (thd=thd@entry=0x145704015088, lex=lex@entry=0x145704018fd8, result=result@entry=0x145704076040, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.5_dbg/sql/sql_select.cc:417
#19 0x0000557875aa17e2 in execute_sqlcom_select (thd=thd@entry=0x145704015088, all_tables=0x145704074790) at /test/10.5_dbg/sql/sql_parse.cc:6209
#20 0x0000557875a9a8b6 in mysql_execute_command (thd=thd@entry=0x145704015088) at /test/10.5_dbg/sql/sql_parse.cc:3931
#21 0x0000557875aa7752 in mysql_parse (thd=thd@entry=0x145704015088, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x145728d99350, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /test/10.5_dbg/sql/sql_parse.cc:7993
#22 0x0000557875a94204 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x145704015088, packet=packet@entry=0x145704067089 "SELECT * FROM t WHERE c IN (CURDATE(),ADDDATE(CURDATE(),'a')) ORDER BY c", packet_length=packet_length@entry=72, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /test/10.5_dbg/sql/sql_parse.cc:1866
#23 0x0000557875a929de in do_command (thd=0x145704015088) at /test/10.5_dbg/sql/sql_parse.cc:1347
#24 0x0000557875beec3b in do_handle_one_connection (connect=<optimized out>, connect@entry=0x145707cc7808, put_in_cache=put_in_cache@entry=true) at /test/10.5_dbg/sql/sql_connect.cc:1411
#25 0x0000557875bef357 in handle_one_connection (arg=arg@entry=0x145707cc7808) at /test/10.5_dbg/sql/sql_connect.cc:1313
#26 0x0000557876052ca8 in pfs_spawn_thread (arg=0x145725c46508) at /test/10.5_dbg/storage/perfschema/pfs.cc:2201
#27 0x0000145727d136db in start_thread (arg=0x145728d9a700) at pthread_create.c:463
#28 0x0000145727111a3f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

10.5.5 30e7a0a866dce530d8328c6d614e48d39a264f9b (Optimized)

Core was generated by `/test/MD140720-mariadb-10.5.5-linux-x86_64-opt/bin/mysqld --no-defaults --core-'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=11)
    at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
[Current thread is 1 (Thread 0x1513e5861700 (LWP 286862))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=11) at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
#1  0x0000559a1d069bd7 in my_write_core (sig=sig@entry=11) at /test/10.5_opt/mysys/stacktrace.c:518
#2  0x0000559a1ca3401a in handle_fatal_signal (sig=11) at /test/10.5_opt/sql/signal_handler.cc:330
#3  <signal handler called>
#4  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:62
#5  0x0000559a1c94daa2 in String_list::append_str (this=this@entry=0x1513c1cc1cc0, mem_root=mem_root@entry=0x1513c1c17920, str=0x0) at /test/10.5_opt/sql/sql_explain.cc:1491
#6  0x0000559a1c94db7f in Explain_index_use::set (this=this@entry=0x1513c1cc1ca0, mem_root=0x1513c1c17920, key=0x1513c1c61130, key_len_arg=4) at /test/10.5_opt/sql/sql_explain.cc:1215
#7  0x0000559a1c88fc6d in st_join_table::save_explain_data (this=this@entry=0x1513c1cc0820, eta=eta@entry=0x1513c1cc1b58, prefix_tables=prefix_tables@entry=1, distinct_arg=distinct_arg@entry=false, first_top_tab=first_top_tab@entry=0x1513c1cc0478) at /test/10.5_opt/sql/sql_select.cc:26567
#8  0x0000559a1c8917e5 in JOIN::save_explain_data_intern (this=this@entry=0x1513c1c48ff8, output=0x1513c1cbe890, need_tmp_table_arg=<optimized out>, need_order_arg=<optimized out>, distinct_arg=distinct_arg@entry=false, message=<optimized out>) at /test/10.5_opt/sql/sql_select.cc:27091
#9  0x0000559a1c891b8a in JOIN::save_explain_data (this=this@entry=0x1513c1c48ff8, output=0x1513c1cbe890, can_overwrite=can_overwrite@entry=false, need_tmp_table=<optimized out>, need_order=<optimized out>, distinct=<optimized out>) at /test/10.5_opt/sql/sql_select.cc:4190
#10 0x0000559a1c891c63 in JOIN::build_explain (this=this@entry=0x1513c1c48ff8) at /test/10.5_opt/sql/sql_select.cc:1568
#11 0x0000559a1c899e2e in JOIN::optimize (this=this@entry=0x1513c1c48ff8) at /test/10.5_opt/sql/sql_select.cc:1624
#12 0x0000559a1c899f81 in mysql_select (thd=thd@entry=0x1513c1c12018, tables=0x1513c1c47720, fields=@0x1513c1c47278: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x1513c1c476d8, last = 0x1513c1c476d8, elements = 1}, <No data fields>}, conds=0x1513c1c48300, og_num=<optimized out>, order=0x1513c1c48df0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x1513c1c48fd0, unit=0x1513c1c15e70, select_lex=0x1513c1c47128) at /test/10.5_opt/sql/sql_select.cc:4641
#13 0x0000559a1c89a991 in handle_select (thd=thd@entry=0x1513c1c12018, lex=lex@entry=0x1513c1c15da8, result=result@entry=0x1513c1c48fd0, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.5_opt/sql/sql_select.cc:417
#14 0x0000559a1c841351 in execute_sqlcom_select (thd=thd@entry=0x1513c1c12018, all_tables=0x1513c1c47720) at /test/10.5_opt/sql/sql_parse.cc:6209
#15 0x0000559a1c83da21 in mysql_execute_command (thd=thd@entry=0x1513c1c12018) at /test/10.5_opt/sql/sql_parse.cc:3931
#16 0x0000559a1c84446c in mysql_parse (thd=0x1513c1c12018, rawbuf=<optimized out>, length=72, parser_state=0x1513e5860430, is_com_multi=<optimized out>, is_next_command=<optimized out>) at /test/10.5_opt/sql/sql_parse.cc:7993
#17 0x0000559a1c839755 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x1513c1c12018, packet=packet@entry=0x1513c1c3a019 "SELECT * FROM t WHERE c IN (CURDATE(),ADDDATE(CURDATE(),'a')) ORDER BY c", packet_length=packet_length@entry=72, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /test/10.5_opt/sql/sql_parse.cc:1866
#18 0x0000559a1c837a94 in do_command (thd=0x1513c1c12018) at /test/10.5_opt/sql/sql_parse.cc:1347
#19 0x0000559a1c92d191 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x1513e24338f8, put_in_cache=put_in_cache@entry=true) at /test/10.5_opt/sql/sql_connect.cc:1411
#20 0x0000559a1c92d4f4 in handle_one_connection (arg=arg@entry=0x1513e24338f8) at /test/10.5_opt/sql/sql_connect.cc:1313
#21 0x0000559a1cc9ddea in pfs_spawn_thread (arg=0x1513e244f218) at /test/10.5_opt/storage/perfschema/pfs.cc:2201
#22 0x00001513e47da6db in start_thread (arg=0x1513e5861700) at pthread_create.c:463
#23 0x00001513e3bd8a3f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.3.24 (dbg), 10.3.24 (opt), 10.4.14 (dbg), 10.4.14 (opt), 10.5.5 (dbg), 10.5.5 (opt)

Bug confirmed not present in:
MariaDB: 10.1.46 (dbg), 10.1.46 (opt), 10.2.33 (dbg), 10.2.33 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.47 (dbg), 5.6.47 (opt), 5.7.29 (dbg), 5.7.29 (opt), 8.0.19 (dbg), 8.0.19 (opt)

Comment by Roel Van de Paar [ 2020-07-20 ]

Unique ID's seen so far

SIGSEGV|__strlen_avx2|Json_writer::add_str|Json_value_helper::add_str|Json_writer_object::add
SIGSEGV|__strlen_avx2|String_list::append_str|Explain_index_use::set|st_join_table::save_explain_data
SIGSEGV|Field_iterator_table::create_item|Field_iterator_table_ref::create_item|insert_fields|setup_wild
SIGSEGV|Item::operator new|Type_handler_json_common::make_json_valid_expr|JOIN::transform_in_predicates_into_in_subq|JOIN::optimize_inner
SIGABRT|__cxa_pure_virtual|Item::real_type|Value_source::Context::Context|Item_func_in::propagate_equal_fields
0|SIGABRT|Type_handler_row::subquery_type_allows_materialization|cmp_row_types|Item_func_in::in_predicate_to_in_subs_transformer|Item_func::transform

Comment by Roel Van de Paar [ 2020-07-20 ]

The testcase given here does not crash for me on 10.5.5 debug+opt 30e7a0a866dce530d8328c6d614e48d39a264f9b

Comment by Roel Van de Paar [ 2022-10-25 ]

SET @@in_predicate_conversion_threshold=2;
CREATE TABLE t (a INT KEY) ENGINE=InnoDB;
SELECT 1 FROM t WHERE ROW(a, (a,a)) IN ((1, (1,1)),(2, (2,2)));

Leads to:

10.11.1 50c5743adc87e1cdec1431a02558f6540fe5a6d5 (Optimized)

Core was generated by `/test/MD221022-mariadb-10.11.1-linux-x86_64-opt/bin/mysqld --no-defaults --core'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x000055f716e38304 in uw_update_context_1 ()
[Current thread is 1 (Thread 0x14adec06b700 (LWP 3218352))]
(gdb) bt
#0  0x000055f716e38304 in uw_update_context_1 ()
#1  0x000055f716e387f6 in uw_init_context_1 ()
#2  0x000055f716e3927b in _Unwind_Resume ()
#3  0x000055f716409ecb in Item::operator new (mem_root=<optimized out>, size=208)
#4  Type_handler_json_common::make_json_valid_expr (thd=0x1, field_name=<optimized out>) at /test/10.11_opt/sql/sql_type_json.cc:137
#5  0x000055f71675dfde in JOIN::transform_in_predicates_into_in_subq (this=0x14ada8010938, this@entry=0x14ada8012c80, thd=0x14ada8012c80) at /test/10.11_opt/sql/sql_tvc.cc:1175
#6  0x000055f71661244e in JOIN::optimize_inner (this=0x14ada8012c80) at /test/10.11_opt/sql/sql_select.cc:2063
#7  0x000055f716615e93 in JOIN::optimize (this=this@entry=0x14ada8012c80) at /test/10.11_opt/sql/sql_select.cc:1864
#8  0x000055f716615f7e in mysql_select (thd=0x14ada8000c58, tables=0x14ada8010e78, fields=@0x14ada8010bd8: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14ada8010e30, last = 0x14ada8010e30, elements = 1}, <No data fields>}, conds=0x14ada8012188, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=<optimized out>, result=0x14ada8012c58, unit=0x14ada8004cd8, select_lex=0x14ada8010938) at /test/10.11_opt/sql/sql_select.cc:5057
#9  0x000055f716616717 in handle_select (thd=thd@entry=0x14ada8000c58, lex=lex@entry=0x14ada8004c00, result=result@entry=0x14ada8012c58, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.11_opt/sql/sql_select.cc:582
#10 0x000055f7165982e1 in execute_sqlcom_select (thd=0x14ada8000c58, all_tables=0x14ada8010e78) at /test/10.11_opt/sql/sql_parse.cc:6261
#11 0x000055f7165a5e6b in mysql_execute_command (thd=0x14ada8000c58, is_called_from_prepared_stmt=<optimized out>) at /test/10.11_opt/sql/sql_parse.cc:3945
#12 0x000055f716593335 in mysql_parse (rawbuf=<optimized out>, length=<optimized out>, parser_state=<optimized out>, thd=0x14ada8000c58) at /test/10.11_opt/sql/sql_parse.cc:8023
#13 mysql_parse (thd=0x14ada8000c58, rawbuf=<optimized out>, length=<optimized out>, parser_state=<optimized out>) at /test/10.11_opt/sql/sql_parse.cc:7945
#14 0x000055f71659f0ea in dispatch_command (command=COM_QUERY, thd=0x14ada8000c58, packet=<optimized out>, packet_length=<optimized out>, blocking=<optimized out>) at /test/10.11_opt/sql/sql_class.h:1346
#15 0x000055f7165a0ee2 in do_command (thd=0x14ada8000c58, blocking=blocking@entry=true) at /test/10.11_opt/sql/sql_parse.cc:1407
#16 0x000055f7166bafbf in do_handle_one_connection (connect=<optimized out>, connect@entry=0x55f719d76758, put_in_cache=put_in_cache@entry=true) at /test/10.11_opt/sql/sql_connect.cc:1416
#17 0x000055f7166bb29d in handle_one_connection (arg=0x55f719d76758) at /test/10.11_opt/sql/sql_connect.cc:1318
#18 0x000014ae042c9609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#19 0x000014ae03eb5133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

10.11.1 50c5743adc87e1cdec1431a02558f6540fe5a6d5 (Debug)

Core was generated by `/test/MD221022-mariadb-10.11.1-linux-x86_64-dbg/bin/mysqld --no-defaults --core'.
Program terminated with signal SIGABRT, Aborted.
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
[Current thread is 1 (Thread 0x14bdd4051700 (LWP 3232767))]
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x000014bdec5f0859 in __GI_abort () at abort.c:79
#2  0x000014bdec9af911 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x000014bdec9bb38c in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x000014bdec9bb3f7 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x000014bdec9bc155 in __cxa_pure_virtual () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00005562ac7f73f9 in Item::real_type (this=<optimized out>) at /test/10.11_dbg/sql/item.h:1366
#7  0x00005562ac824806 in Value_source::Context::Context (cs=<optimized out>, h=0x5562adecb840 <type_handler_row>, subst=Value_source::ANY_SUBST, this=0x14bdd404f440) at /test/10.11_dbg/sql/field.h:432
#8  Item_func_in::propagate_equal_fields (this=0x14bd90014b58, thd=0x14bd90000d48, ctx=<optimized out>, cond=0x0) at /test/10.11_dbg/sql/item_cmpfunc.h:2579
#9  0x00005562ac95834e in Item_func::build_equal_items (this=0x14bd90014b58, thd=0x14bd90000d48, inherited=0x0, link_item_fields=<optimized out>, cond_equal_ref=0x14bd90015b00) at /test/10.11_dbg/sql/field.h:432
#10 0x00005562ac956fc4 in build_equal_items (join=join@entry=0x14bd90015650, cond=cond@entry=0x14bd90014b58, inherited=inherited@entry=0x0, join_list=join_list@entry=0x14bd900134c0, ignore_on_conds=ignore_on_conds@entry=false, cond_equal_ref=cond_equal_ref@entry=0x14bd90015b00, link_equal_fields=true) at /test/10.11_dbg/sql/sql_select.cc:16356
#11 0x00005562ac9597a7 in optimize_cond (join=join@entry=0x14bd90015650, conds=0x14bd90014b58, join_list=0x14bd900134c0, ignore_on_conds=ignore_on_conds@entry=false, cond_value=cond_value@entry=0x14bd900159d8, cond_equal=cond_equal@entry=0x14bd90015b00, flags=1) at /test/10.11_dbg/sql/sql_select.cc:18140
#12 0x00005562ac9a17f9 in JOIN::optimize_inner (this=this@entry=0x14bd90015650) at /test/10.11_dbg/sql/sql_select.cc:2252
#13 0x00005562ac9a250c in JOIN::optimize (this=this@entry=0x14bd90015650) at /test/10.11_dbg/sql/sql_select.cc:1864
#14 0x00005562ac9a25ff in mysql_select (thd=thd@entry=0x14bd90000d48, tables=0x14bd90013848, fields=@0x14bd900135a8: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14bd90013800, last = 0x14bd90013800, elements = 1}, <No data fields>}, conds=0x14bd90014b58, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2164525824, result=0x14bd90015628, unit=0x14bd90004f88, select_lex=0x14bd90013308) at /test/10.11_dbg/sql/sql_select.cc:5057
#15 0x00005562ac9a2dc5 in handle_select (thd=thd@entry=0x14bd90000d48, lex=lex@entry=0x14bd90004eb0, result=result@entry=0x14bd90015628, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.11_dbg/sql/sql_select.cc:582
#16 0x00005562ac910ad5 in execute_sqlcom_select (thd=thd@entry=0x14bd90000d48, all_tables=0x14bd90013848) at /test/10.11_dbg/sql/sql_parse.cc:6261
#17 0x00005562ac91cbd2 in mysql_execute_command (thd=thd@entry=0x14bd90000d48, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/10.11_dbg/sql/sql_parse.cc:3945
#18 0x00005562ac90af90 in mysql_parse (thd=thd@entry=0x14bd90000d48, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x14bdd4050300) at /test/10.11_dbg/sql/sql_parse.cc:8023
#19 0x00005562ac9184ac in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x14bd90000d48, packet=packet@entry=0x14bd9000af09 "SELECT 1 FROM t WHERE ROW(a, (a,a)) IN ((1, (1,1)),(2, (2,2)))", packet_length=packet_length@entry=62, blocking=blocking@entry=true) at /test/10.11_dbg/sql/sql_class.h:1346
#20 0x00005562ac91a8f4 in do_command (thd=0x14bd90000d48, blocking=blocking@entry=true) at /test/10.11_dbg/sql/sql_parse.cc:1407
#21 0x00005562aca77067 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x5562b0727dc8, put_in_cache=put_in_cache@entry=true) at /test/10.11_dbg/sql/sql_connect.cc:1416
#22 0x00005562aca77536 in handle_one_connection (arg=0x5562b0727dc8) at /test/10.11_dbg/sql/sql_connect.cc:1318
#23 0x000014bdecb01609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#24 0x000014bdec6ed133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

10.10.2 5deccac4aaf1be948a0ae10f40bb5f668ac37a4d (Debug)

mysqld: /test/10.10_dbg/sql/sql_type.h:4395: virtual bool Type_handler_row::subquery_type_allows_materialization(const Item*, const Item*, bool) const: Assertion `0' failed.

10.10.2 5deccac4aaf1be948a0ae10f40bb5f668ac37a4d (Debug)

Core was generated by `/test/MD190922-mariadb-10.10.2-linux-x86_64-dbg/bin/mysqld --no-defaults --core'.
Program terminated with signal SIGABRT, Aborted.
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
[Current thread is 1 (Thread 0x14ef0de02700 (LWP 3063363))]
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x000014ef3bd9c859 in __GI_abort () at abort.c:79
#2  0x000014ef3bd9c729 in __assert_fail_base (fmt=0x14ef3bf32588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x56545b605e26 "0", file=0x56545b429c60 "/test/10.10_dbg/sql/sql_type.h", line=4395, function=<optimized out>) at assert.c:92
#3  0x000014ef3bdadfd6 in __GI___assert_fail (assertion=assertion@entry=0x56545b605e26 "0", file=file@entry=0x56545b429c60 "/test/10.10_dbg/sql/sql_type.h", line=line@entry=4395, function=function@entry=0x56545b4a6458 "virtual bool Type_handler_row::subquery_type_allows_materialization(const Item*, const Item*, bool) const") at assert.c:101
#4  0x000056545aa7e71f in Type_handler_row::subquery_type_allows_materialization (this=<optimized out>) at /test/10.10_dbg/sql/sql_type.h:4395
#5  0x000056545aa9e1b9 in cmp_row_types (item2=0x14eeb0014270, item1=0x14eeb00145b0) at /test/10.10_dbg/sql/sql_tvc.cc:890
#6  Item_func_in::in_predicate_to_in_subs_transformer (this=0x14eeb00149e0, thd=0x14eeb0000d48, arg=<optimized out>) at /test/10.10_dbg/sql/sql_tvc.cc:971
#7  0x000056545abe4aed in Item_func::transform (this=0x14eeb00149e0, thd=0x14eeb0000d48, transformer=&virtual table offset 1384, argument=0x0) at /test/10.10_dbg/sql/item_func.cc:511
#8  0x000056545aa9eb7b in JOIN::transform_in_predicates_into_in_subq (this=this@entry=0x14eeb00154b0, thd=0x14eeb0000d48) at /test/10.10_dbg/sql/sql_tvc.cc:1175
#9  0x000056545a8ef19e in JOIN::optimize_inner (this=this@entry=0x14eeb00154b0) at /test/10.10_dbg/sql/sql_select.cc:2062
#10 0x000056545a8f09f6 in JOIN::optimize (this=this@entry=0x14eeb00154b0) at /test/10.10_dbg/sql/sql_select.cc:1863
#11 0x000056545a8f0ae9 in mysql_select (thd=thd@entry=0x14eeb0000d48, tables=0x14eeb00136f8, fields=@0x14eeb0013458: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14eeb00136b0, last = 0x14eeb00136b0, elements = 1}, <No data fields>}, conds=0x14eeb00149e0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2164525824, result=0x14eeb0015488, unit=0x14eeb0004f80, select_lex=0x14eeb00131b8) at /test/10.10_dbg/sql/sql_select.cc:5056
#12 0x000056545a8f1332 in handle_select (thd=thd@entry=0x14eeb0000d48, lex=lex@entry=0x14eeb0004ea8, result=result@entry=0x14eeb0015488, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.10_dbg/sql/sql_select.cc:581
#13 0x000056545a85b3e7 in execute_sqlcom_select (thd=thd@entry=0x14eeb0000d48, all_tables=0x14eeb00136f8) at /test/10.10_dbg/sql/sql_parse.cc:6261
#14 0x000056545a867755 in mysql_execute_command (thd=thd@entry=0x14eeb0000d48, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/10.10_dbg/sql/sql_parse.cc:3945
#15 0x000056545a85568d in mysql_parse (thd=thd@entry=0x14eeb0000d48, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x14ef0de01330) at /test/10.10_dbg/sql/sql_parse.cc:8035
#16 0x000056545a862cbf in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x14eeb0000d48, packet=packet@entry=0x14eeb000adb9 "SELECT 1 FROM t WHERE ROW(a, (a,a)) IN ((1, (1,1)),(2, (2,2)))", packet_length=packet_length@entry=62, blocking=blocking@entry=true) at /test/10.10_dbg/sql/sql_class.h:1345
#17 0x000056545a8653e2 in do_command (thd=0x14eeb0000d48, blocking=blocking@entry=true) at /test/10.10_dbg/sql/sql_parse.cc:1407
#18 0x000056545a9c7abd in do_handle_one_connection (connect=<optimized out>, connect@entry=0x56545eaf9a78, put_in_cache=put_in_cache@entry=true) at /test/10.10_dbg/sql/sql_connect.cc:1416
#19 0x000056545a9c7fc7 in handle_one_connection (arg=0x56545eaf9a78) at /test/10.10_dbg/sql/sql_connect.cc:1318
#20 0x000014ef3c2ad609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#21 0x000014ef3be99133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.3.37 (dbg), 10.4.27 (dbg), 10.5.18 (dbg), 10.6.10 (dbg), 10.7.6 (dbg), 10.8.5 (dbg), 10.9.3 (dbg), 10.10.2 (dbg), 10.11.1 (dbg)

Bug (or feature/syntax) confirmed not present in:
MariaDB: 10.3.37 (opt), 10.4.27 (opt), 10.5.18 (opt), 10.6.10 (opt), 10.7.6 (opt), 10.8.5 (opt), 10.9.3 (opt), 10.10.2 (opt), 10.11.1 (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 [ 2023-01-13 ]

Whole new set of stacks seen (potential new regression):

SET @@in_predicate_conversion_threshold=2;
SELECT 1 FROM (SELECT 1 AS c) AS t WHERE ROW(c,(c,c)) IN ((1,(1,1)),(2,(2,1)));

Leads to:

11.0.1 b075191ba8598af6aff5549e6e19f6255aef258a (Optimized)

Core was generated by `/test/MD090123-mariadb-11.0.1-linux-x86_64-opt/bin/mysqld --no-defaults --core-'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x000014e20d725ea0 in __GI___dl_iterate_phdr (
    callback=0x557f5f737c20 <_Unwind_IteratePhdrCallback>, data=0x14e1f4ba5a48)
    at ./elf/dl-iteratephdr.c:68
[Current thread is 1 (Thread 0x14e1f4ba8640 (LWP 1183274))]
(gdb) bt
#0  0x000014e20d725ea0 in __GI___dl_iterate_phdr (callback=0x557f5f737c20 <_Unwind_IteratePhdrCallback>, data=0x14e1f4ba5a48) at ./elf/dl-iteratephdr.c:68
#1  0x0000557f5f738e11 in _Unwind_Find_FDE ()
#2  0x0000557f5f7357d8 in uw_frame_state_for ()
#3  0x0000557f5f735e30 in uw_init_context_1 ()
#4  0x0000557f5f736a4b in _Unwind_Resume ()
#5  0x0000557f5eddd38f in Item::operator new (mem_root=<optimized out>, size=208)
#6  Type_handler_json_common::make_json_valid_expr (thd=0x14e1c00125d8, field_name=<optimized out>) at /test/11.0_opt/sql/sql_type_json.cc:137
#7  0x0000557f5f13cf2e in JOIN::transform_in_predicates_into_in_subq (this=0x14e1c0000c68, this@entry=0x14e1c0013898, thd=0x0) at /test/11.0_opt/sql/sql_tvc.cc:1176
#8  0x0000557f5eff2443 in JOIN::optimize_inner (this=0x14e1c0013898) at /test/11.0_opt/sql/sql_select.cc:2070
#9  0x0000557f5eff3ada in JOIN::optimize (this=this@entry=0x14e1c0013898) at /test/11.0_opt/sql/sql_select.cc:1870
#10 0x0000557f5eff3bbe in mysql_select (thd=0x14e1c0000c68, tables=0x14e1c0011b18, fields=@0x14e1c0010b08: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14e1c0010d68, last = 0x14e1c0010d68, elements = 1}, <No data fields>}, conds=0x14e1c0012e28, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=<optimized out>, result=0x14e1c0013870, unit=0x14e1c0004ce8, select_lex=0x14e1c0010868) at /test/11.0_opt/sql/sql_select.cc:5066
#11 0x0000557f5eff4354 in handle_select (thd=thd@entry=0x14e1c0000c68, lex=lex@entry=0x14e1c0004c10, result=result@entry=0x14e1c0013870, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/11.0_opt/sql/sql_select.cc:581
#12 0x0000557f5ef6fb25 in execute_sqlcom_select (thd=0x14e1c0000c68, all_tables=0x14e1c0011b18) at /test/11.0_opt/sql/sql_parse.cc:6265
#13 0x0000557f5ef7e870 in mysql_execute_command (thd=0x14e1c0000c68, is_called_from_prepared_stmt=<optimized out>) at /test/11.0_opt/sql/sql_parse.cc:3949
#14 0x0000557f5ef80104 in mysql_parse (rawbuf=<optimized out>, length=<optimized out>, parser_state=<optimized out>, thd=0x14e1c0000c68) at /test/11.0_opt/sql/sql_parse.cc:8000
#15 mysql_parse (thd=0x14e1c0000c68, rawbuf=<optimized out>, length=<optimized out>, parser_state=<optimized out>) at /test/11.0_opt/sql/sql_parse.cc:7922
#16 0x0000557f5ef826e2 in dispatch_command (command=COM_QUERY, thd=0x14e1c0000c68, packet=<optimized out>, packet_length=<optimized out>, blocking=<optimized out>) at /test/11.0_opt/sql/sql_parse.cc:1991
#17 0x0000557f5ef83e80 in do_command (thd=0x14e1c0000c68, blocking=blocking@entry=true) at /test/11.0_opt/sql/sql_parse.cc:1407
#18 0x0000557f5f099ab7 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x557f62575028, put_in_cache=put_in_cache@entry=true) at /test/11.0_opt/sql/sql_connect.cc:1416
#19 0x0000557f5f099d8d in handle_one_connection (arg=0x557f62575028) at /test/11.0_opt/sql/sql_connect.cc:1318
#20 0x000014e20d645b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#21 0x000014e20d6d7a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

10.4.28 111a752b968561b34a88f33052519cb989a8a90f (Debug)

Core was generated by `/test/MD070123-mariadb-10.4.28-linux-x86_64-dbg/bin/mysqld --no-defaults --core'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  decimal2string (from=0x0, to=0x556eb6021af8 "", to_len=0x14589221f23c, 
    fixed_precision=0, fixed_decimals=0, filler=32 ' ')
    at /test/10.4_dbg/strings/decimal.c:338
[Current thread is 1 (Thread 0x145892222640 (LWP 1183784))]
(gdb) bt
#0  decimal2string (from=0x0, to=0x556eb6021af8 "", to_len=0x14589221f23c, fixed_precision=0, fixed_decimals=0, filler=32 ' ') at /test/10.4_dbg/strings/decimal.c:338
#1  0x0000556eb4eaf15f in ErrBuff::set_decimal (d=<optimized out>, this=0x556eb6021af8) at /test/10.4_dbg/sql/sql_error.h:847
#2  ErrConvDecimal::ptr (this=0x556eb6021af0 <type_handler_row>) at /test/10.4_dbg/sql/sql_error.h:929
#3  0x0000556eb4ec6808 in cmp_row_types (item2=0x145850014410, item1=0x1458500147c8) at /test/10.4_dbg/sql/sql_tvc.cc:859
#4  Item_func_in::in_predicate_to_in_subs_transformer (this=<optimized out>, thd=0x145850000d38, arg=<optimized out>) at /test/10.4_dbg/sql/sql_tvc.cc:925
#5  0x0000556eb4ffb470 in Item_func::transform (this=0x145850014c88, thd=0x145850000d38, transformer=<optimized out>, argument=0x0) at /test/10.4_dbg/sql/item_func.cc:503
#6  0x0000556eb4ec6ac1 in JOIN::transform_in_predicates_into_in_subq (this=this@entry=0x145850015728, thd=0x145850000d38) at /test/10.4_dbg/sql/sql_tvc.cc:1124
#7  0x0000556eb4d79149 in JOIN::optimize_inner (this=this@entry=0x145850015728) at /test/10.4_dbg/sql/sql_select.cc:1910
#8  0x0000556eb4d7a885 in JOIN::optimize (this=this@entry=0x145850015728) at /test/10.4_dbg/sql/sql_select.cc:1685
#9  0x0000556eb4d7b1ad in mysql_select (thd=thd@entry=0x145850000d38, tables=0x145850013898, wild_num=0, fields=@0x1458500126f0: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x145850012ac8, last = 0x145850012ac8, elements = 1}, <No data fields>}, conds=0x145850014c88, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=<optimized out>, result=0x145850015700, unit=0x145850004ad8, select_lex=0x1458500125a8) at /test/10.4_dbg/sql/sql_select.cc:4781
#10 0x0000556eb4d7b4a3 in handle_select (thd=thd@entry=0x145850000d38, lex=lex@entry=0x145850004a18, result=result@entry=0x145850015700, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.4_dbg/sql/sql_select.cc:437
#11 0x0000556eb4cff7cf in execute_sqlcom_select (thd=thd@entry=0x145850000d38, all_tables=0x145850013898) at /test/10.4_dbg/sql/sql_parse.cc:6452
#12 0x0000556eb4d08e3a in mysql_execute_command (thd=thd@entry=0x145850000d38) at /test/10.4_dbg/sql/sql_parse.cc:3966
#13 0x0000556eb4d121c6 in mysql_parse (thd=thd@entry=0x145850000d38, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x145892221350, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /test/10.4_dbg/sql/sql_parse.cc:7984
#14 0x0000556eb4d14419 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x145850000d38, packet=packet@entry=0x1458500194f9 "SELECT 1 FROM (SELECT 1 AS c) AS t WHERE ROW(c,(c,c)) IN ((1,(1,1)),(2,(2,1)))", packet_length=packet_length@entry=78, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /test/10.4_dbg/sql/sql_class.h:227
#15 0x0000556eb4d16772 in do_command (thd=0x145850000d38) at /test/10.4_dbg/sql/sql_parse.cc:1378
#16 0x0000556eb4e28aaa in do_handle_one_connection (connect=<optimized out>) at /test/10.4_dbg/sql/sql_connect.cc:1420
#17 0x0000556eb4e28b73 in handle_one_connection (arg=<optimized out>) at /test/10.4_dbg/sql/sql_connect.cc:1324
#18 0x00001458b8e78b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#19 0x00001458b8f0aa00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

All UniqueID's seen accross all versions (10.3 to 10.11):

SIGSEGV|__GI___dl_iterate_phdr|_Unwind_Find_FDE|uw_frame_state_for|Item::operator new
SIGSEGV|__GI___dl_iterate_phdr|_Unwind_Find_FDE|uw_frame_state_for|Sql_alloc::operator new
SIGSEGV|__GI___dl_iterate_phdr|_Unwind_Find_FDE|uw_frame_state_for|Type_all_attributes::~Type_all_attributes
SIGSEGV|decimal2string|ErrBuff::set_decimal|ErrConvDecimal::ptr|cmp_row_types

And UBSAN reports an execution reached an unreachable program point runtime error:

10.11.2 70be59913c90e93fe5136d6f6df03c4254aa515d (Optimized, UBASAN)

2023-01-14 10:04:05 0 [Note] /test/UBASAN_MD070123-mariadb-10.11.2-linux-x86_64-opt/bin/mysqld: ready for connections.
Version: '10.11.2-MariaDB'  socket: '/test/UBASAN_MD070123-mariadb-10.11.2-linux-x86_64-opt/socket.sock'  port: 10238  MariaDB Server
/test/10.11_opt_san/sql/sql_type.h:4395:5: runtime error: execution reached an unreachable program point
    #0 0x557abbe7fd3d in Type_handler_row::subquery_type_allows_materialization(Item const*, Item const*, bool) const /test/10.11_opt_san/sql/sql_type.h:4395
    #1 0x557abdaa21c8 in cmp_row_types /test/10.11_opt_san/sql/sql_tvc.cc:890
    #2 0x557abdaa21c8 in Item_func_in::in_predicate_to_in_subs_transformer(THD*, unsigned char*) /test/10.11_opt_san/sql/sql_tvc.cc:971
    #3 0x557abe55375c in Item_func::transform(THD*, Item* (Item::*)(THD*, unsigned char*), unsigned char*) /test/10.11_opt_san/sql/item_func.cc:511
    #4 0x557abdaaa9f5 in JOIN::transform_in_predicates_into_in_subq(THD*) /test/10.11_opt_san/sql/sql_tvc.cc:1176
    #5 0x557abcf9f5db in JOIN::optimize_inner() /test/10.11_opt_san/sql/sql_select.cc:2070
    #6 0x557abcfac2a0 in JOIN::optimize() /test/10.11_opt_san/sql/sql_select.cc:1870
    #7 0x557abcfac936 in mysql_select(THD*, TABLE_LIST*, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) /test/10.11_opt_san/sql/sql_select.cc:5066
    #8 0x557abcfb0750 in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/10.11_opt_san/sql/sql_select.cc:581
    #9 0x557abcb5bc80 in execute_sqlcom_select /test/10.11_opt_san/sql/sql_parse.cc:6265
    #10 0x557abcbc105c in mysql_execute_command(THD*, bool) /test/10.11_opt_san/sql/sql_parse.cc:3949
    #11 0x557abcbd1d82 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/10.11_opt_san/sql/sql_parse.cc:8000
    #12 0x557abcbdf7e5 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/10.11_opt_san/sql/sql_parse.cc:1894
    #13 0x557abcbe8f40 in do_command(THD*, bool) /test/10.11_opt_san/sql/sql_parse.cc:1407
    #14 0x557abd4c571c in do_handle_one_connection(CONNECT*, bool) /test/10.11_opt_san/sql/sql_connect.cc:1416
    #15 0x557abd4c7d1c in handle_one_connection /test/10.11_opt_san/sql/sql_connect.cc:1318
    #16 0x1528ea3ceb42 in start_thread nptl/pthread_create.c:442
    #17 0x1528ea4609ff  (/lib/x86_64-linux-gnu/libc.so.6+0x1269ff)

Comment by Roel Van de Paar [ 2023-07-28 ]

Something must have changed recently as in 10.6 the following testcase:

SET SESSION in_predicate_conversion_threshold=1;
CREATE TABLE t1 (a SERIAL KEY,b INT) ENGINE=InnoDB;
SELECT 1 FROM t1 WHERE ROW(a,(a,a)) IN ((1,(1,1)),(2,(2,1)));

Now leads to:

10.6.15 b102872ad50cce5959ad95369740766d14e9e48c (Optimized)

Core was generated by `/test/MD280723-mariadb-10.6.15-linux-x86_64-opt/bin/mariadbd --no-defaults --co'.
Program terminated with signal SIGABRT, Aborted.
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=22360142341696)
    at ./nptl/pthread_kill.c:44
[Current thread is 1 (Thread 0x145620576640 (LWP 105145))]
(gdb) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=22360142341696) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=22360142341696) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=22360142341696, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x000014564cc42476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x000014564cc287f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x00005571d4b977e3 in Type_handler_row::subquery_type_allows_materialization (this=<optimized out>) at /test/10.6_opt/sql/sql_type.h:4425
#6  0x00005571d4eb1e54 in cmp_row_types (item2=0x1456000118e0, item1=0x145600011c20) at /test/10.6_opt/sql/sql_tvc.cc:890
#7  Item_func_in::in_predicate_to_in_subs_transformer (this=0x145600012050, thd=0x145600000c68, arg=<optimized out>) at /test/10.6_opt/sql/sql_tvc.cc:971
#8  0x00005571d4eb283e in JOIN::transform_in_predicates_into_in_subq (this=this@entry=0x145600012b40, thd=0x145600000c68) at /test/10.6_opt/sql/sql_tvc.cc:1176
#9  0x00005571d4d70773 in JOIN::optimize_inner (this=0x145600012b40) at /test/10.6_opt/sql/sql_select.cc:2068
#10 0x00005571d4d71dba in JOIN::optimize (this=this@entry=0x145600012b40) at /test/10.6_opt/sql/sql_select.cc:1868
#11 0x00005571d4d71e87 in mysql_select (thd=0x145600000c68, tables=0x145600010d48, fields=@0x145600010a80: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x145600010d00, last = 0x145600010d00, elements = 1}, <No data fields>}, conds=0x145600012050, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=<optimized out>, result=0x145600012b18, unit=0x145600004c50, select_lex=0x1456000107c8) at /test/10.6_opt/sql/sql_select.cc:5069
#12 0x00005571d4d72614 in handle_select (thd=thd@entry=0x145600000c68, lex=lex@entry=0x145600004b88, result=result@entry=0x145600012b18, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.6_opt/sql/sql_select.cc:559
#13 0x00005571d4cfb715 in execute_sqlcom_select (thd=0x145600000c68, all_tables=0x145600010d48) at /test/10.6_opt/sql/sql_parse.cc:6273
#14 0x00005571d4d0a64a in mysql_execute_command (thd=0x145600000c68, is_called_from_prepared_stmt=<optimized out>) at /test/10.6_opt/sql/sql_parse.cc:3949
#15 0x00005571d4d0bdd4 in mysql_parse (rawbuf=<optimized out>, length=<optimized out>, parser_state=<optimized out>, thd=0x145600000c68) at /test/10.6_opt/sql/sql_parse.cc:8041
#16 mysql_parse (thd=0x145600000c68, rawbuf=<optimized out>, length=<optimized out>, parser_state=<optimized out>) at /test/10.6_opt/sql/sql_parse.cc:7963
#17 0x00005571d4d0e422 in dispatch_command (command=COM_QUERY, thd=0x145600000c68, packet=<optimized out>, packet_length=<optimized out>, blocking=<optimized out>) at /test/10.6_opt/sql/sql_parse.cc:1993
#18 0x00005571d4d0fca0 in do_command (thd=0x145600000c68, blocking=blocking@entry=true) at /test/10.6_opt/sql/sql_parse.cc:1409
#19 0x00005571d4e15827 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x5571d71ca2e8, put_in_cache=put_in_cache@entry=true) at /test/10.6_opt/sql/sql_connect.cc:1416
#20 0x00005571d4e15afd in handle_one_connection (arg=0x5571d71ca2e8) at /test/10.6_opt/sql/sql_connect.cc:1318
#21 0x000014564cc94b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#22 0x000014564cd26a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

Generated at Thu Feb 08 09:14:46 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.