[MDEV-22716] Assertion `0' failed in Type_handler_row::subquery_type_allows_materialization Created: 2020-05-26  Updated: 2023-11-28

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

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

Issue Links:
Relates
relates to MDEV-22444 SIGSEGV's in __strlen_avx2, __GI___dl... Confirmed

 Description   

USE test;
CREATE TEMPORARY TABLE t(a INT,b INT);
SET SESSION in_predicate_conversion_threshold=2;
SELECT 1 FROM t WHERE ROW(a,(a,a)) IN ((1,(1,1)),(2,(2,1)));

Leads to:

10.5.4 8569dac1ec9f6853a0b2f3ea9bcbda67644ead24

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

10.5.4 8569dac1ec9f6853a0b2f3ea9bcbda67644ead24

Core was generated by `/test/MD260520-mariadb-10.5.4-linux-x86_64-dbg/bin/mysqld --no-defaults --core-'.
Program terminated with signal SIGABRT, Aborted.
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6)
    at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
[Current thread is 1 (Thread 0x14b877a9d700 (LWP 1739556))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
#1  0x00005601a6822d7a in my_write_core (sig=sig@entry=6) at /test/10.5_dbg/mysys/stacktrace.c:518
#2  0x00005601a5fc8385 in handle_fatal_signal (sig=6) at /test/10.5_dbg/sql/signal_handler.cc:330
#3  <signal handler called>
#4  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#5  0x000014b8761e1801 in __GI_abort () at abort.c:79
#6  0x000014b8761d139a in __assert_fail_base (fmt=0x14b8763587d8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x5601a6b5b2c4 "0", file=file@entry=0x5601a697a97f "/test/10.5_dbg/sql/sql_type.h", line=line@entry=4153, function=function@entry=0x5601a69fb860 <Type_handler_row::subquery_type_allows_materialization(Item const*, Item const*) const::__PRETTY_FUNCTION__> "virtual bool Type_handler_row::subquery_type_allows_materialization(const Item*, const Item*) const") at assert.c:92
#7  0x000014b8761d1412 in __GI___assert_fail (assertion=assertion@entry=0x5601a6b5b2c4 "0", file=file@entry=0x5601a697a97f "/test/10.5_dbg/sql/sql_type.h", line=line@entry=4153, function=function@entry=0x5601a69fb860 <Type_handler_row::subquery_type_allows_materialization(Item const*, Item const*) const::__PRETTY_FUNCTION__> "virtual bool Type_handler_row::subquery_type_allows_materialization(const Item*, const Item*) const") at assert.c:101
#8  0x00005601a5f07ad0 in Type_handler_row::subquery_type_allows_materialization (this=<optimized out>, inner=<optimized out>, outer=<optimized out>) at /test/10.5_dbg/sql/sql_type.h:4153
#9  0x00005601a5f237e6 in cmp_row_types (item2=0x14b8544756b0, item1=0x14b8544752d0) at /test/10.5_dbg/sql/sql_tvc.cc:832
#10 Item_func_in::in_predicate_to_in_subs_transformer (this=0x14b854475ba0, thd=thd@entry=0x14b854415088, arg=arg@entry=0x0) at /test/10.5_dbg/sql/sql_tvc.cc:899
#11 0x00005601a60520fd in Item_func::transform (this=0x14b854475ba0, thd=0x14b854415088, transformer=NULL, argument=0x0) at /test/10.5_dbg/sql/item_func.cc:519
#12 0x00005601a5f239bc in JOIN::transform_in_predicates_into_in_subq (this=this@entry=0x14b854476630, thd=0x14b854415088) at /test/10.5_dbg/sql/sql_tvc.cc:1074
#13 0x00005601a5d95bf1 in JOIN::optimize_inner (this=this@entry=0x14b854476630) at /test/10.5_dbg/sql/sql_select.cc:1829
#14 0x00005601a5d9996c in JOIN::optimize (this=this@entry=0x14b854476630) at /test/10.5_dbg/sql/sql_select.cc:1606
#15 0x00005601a5d9a2f9 in mysql_select (thd=thd@entry=0x14b854415088, tables=<optimized out>, fields=..., conds=0x14b854475ba0, og_num=0, order=<optimized out>, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x14b854476608, unit=0x14b8544190a0, select_lex=0x14b854474180) at /test/10.5_dbg/sql/sql_select.cc:4655
#16 0x00005601a5d9a675 in handle_select (thd=thd@entry=0x14b854415088, lex=lex@entry=0x14b854418fd8, result=result@entry=0x14b854476608, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.5_dbg/sql/sql_select.cc:417
#17 0x00005601a5d250bf in execute_sqlcom_select (thd=thd@entry=0x14b854415088, all_tables=0x14b8544746d8) at /test/10.5_dbg/sql/sql_parse.cc:6207
#18 0x00005601a5d1e1f4 in mysql_execute_command (thd=thd@entry=0x14b854415088) at /test/10.5_dbg/sql/sql_parse.cc:3939
#19 0x00005601a5d2b02e in mysql_parse (thd=thd@entry=0x14b854415088, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x14b877a9c3d0, 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:7991
#20 0x00005601a5d17b42 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x14b854415088, packet=packet@entry=0x14b854467089 "SELECT 1 FROM t WHERE ROW(a,(a,a)) IN ((1,(1,1)),(2,(2,1)))", packet_length=packet_length@entry=59, 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:1874
#21 0x00005601a5d1631c in do_command (thd=0x14b854415088) at /test/10.5_dbg/sql/sql_parse.cc:1355
#22 0x00005601a5e7073f in do_handle_one_connection (connect=<optimized out>, connect@entry=0x14b8568453a8, put_in_cache=put_in_cache@entry=true) at /test/10.5_dbg/sql/sql_connect.cc:1411
#23 0x00005601a5e70e5b in handle_one_connection (arg=arg@entry=0x14b8568453a8) at /test/10.5_dbg/sql/sql_connect.cc:1313
#24 0x00005601a62d014e in pfs_spawn_thread (arg=0x14b875445888) at /test/10.5_dbg/storage/perfschema/pfs.cc:2201
#25 0x000014b876ec46db in start_thread (arg=0x14b877a9d700) at pthread_create.c:463
#26 0x000014b8762c288f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

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

Bug confirmed not present in:
MariaDB: 10.1.46 (dbg), 10.1.46 (opt), 10.2.33 (dbg), 10.2.33 (opt), 10.3.24 (opt), 10.4.14 (opt), 10.5.4 (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)

Not a regression:

10.2.33 (dbg)

10.2.33>SET SESSION in_predicate_conversion_threshold=2;
ERROR 1193 (HY000): Unknown system variable 'in_predicate_conversion_threshold'



 Comments   
Comment by Roel Van de Paar [ 2023-08-11 ]

In newer versions, this crashes without the 0 assert:

11.2.0 e81fa345020ec6a067583db6a7019d6404b26f93 (Debug)

Core was generated by `/test/MD010823-mariadb-11.2.0-linux-x86_64-dbg/bin/mariadbd --no-defaults --cor'.
Program terminated with signal SIGABRT, Aborted.
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=22560188479040)
    at ./nptl/pthread_kill.c:44
[Current thread is 1 (Thread 0x1484b4053640 (LWP 2609694))]
(gdb) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=22560188479040) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=22560188479040) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=22560188479040, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00001484c9a42476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00001484c9a287f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x000056331149d10b in Type_handler_row::subquery_type_allows_materialization (this=<optimized out>) at /test/11.2_dbg/sql/sql_type.h:4411
#6  0x00005633114b938b in cmp_row_types (item2=0x1484580144b0, item1=0x148458014818) at /test/11.2_dbg/sql/sql_tvc.cc:891
#7  Item_func_in::in_predicate_to_in_subs_transformer (this=0x148458014c78, thd=0x148458000d58, arg=<optimized out>) at /test/11.2_dbg/sql/sql_tvc.cc:976
#8  0x00005633115eb9af in Item_func::transform (this=0x148458014c78, thd=0x148458000d58, transformer=<optimized out>, argument=0x0) at /test/11.2_dbg/sql/item_func.cc:511
#9  0x0000563311161c0f in Item::top_level_transform (this=<optimized out>, thd=<optimized out>, transformer=<optimized out>, arg=<optimized out>) at /test/11.2_dbg/sql/item.h:2135
#10 0x00005633114b9d91 in JOIN::transform_in_predicates_into_in_subq (this=this@entry=0x148458015790, thd=0x148458000d58) at /test/11.2_dbg/sql/sql_tvc.cc:1187
#11 0x0000563311302d7c in JOIN::optimize_inner (this=this@entry=0x148458015790) at /test/11.2_dbg/sql/sql_select.cc:2151
#12 0x000056331130460a in JOIN::optimize (this=this@entry=0x148458015790) at /test/11.2_dbg/sql/sql_select.cc:1944
#13 0x000056331130472a in mysql_select (thd=thd@entry=0x148458000d58, tables=0x1484580138f0, fields=@0x148458013620: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x1484580138a8, last = 0x1484580138a8, elements = 1}, <No data fields>}, conds=0x148458014c78, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2164525824, result=0x148458015768, unit=0x148458005068, select_lex=0x148458013368) at /test/11.2_dbg/sql/sql_select.cc:5229
#14 0x0000563311304f29 in handle_select (thd=thd@entry=0x148458000d58, lex=lex@entry=0x148458004f88, result=result@entry=0x148458015768, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/11.2_dbg/sql/sql_select.cc:628
#15 0x0000563311268ab1 in execute_sqlcom_select (thd=thd@entry=0x148458000d58, all_tables=0x1484580138f0) at /test/11.2_dbg/sql/sql_parse.cc:6056
#16 0x0000563311273ee3 in mysql_execute_command (thd=thd@entry=0x148458000d58, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/11.2_dbg/sql/sql_parse.cc:3944
#17 0x000056331127a4c0 in mysql_parse (thd=thd@entry=0x148458000d58, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x1484b4052200) at /test/11.2_dbg/sql/sql_parse.cc:7800
#18 0x000056331127c654 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x148458000d58, packet=packet@entry=0x14845800af59 "SELECT 1 FROM t WHERE ROW(a, (a,a)) IN ((1, (1,1)),(2, (2,1)))", packet_length=packet_length@entry=62, blocking=blocking@entry=true) at /test/11.2_dbg/sql/sql_class.h:244
#19 0x000056331127e52f in do_command (thd=0x148458000d58, blocking=blocking@entry=true) at /test/11.2_dbg/sql/sql_parse.cc:1405
#20 0x00005633113d30d0 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x563313805be8, put_in_cache=put_in_cache@entry=true) at /test/11.2_dbg/sql/sql_connect.cc:1445
#21 0x00005633113d332f in handle_one_connection (arg=0x563313805be8) at /test/11.2_dbg/sql/sql_connect.cc:1347
#22 0x00001484c9a94b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#23 0x00001484c9b26a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

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