[MDEV-19720] Server crash in st_join_table::save_explain_data or Assertion `sel->quick' failed in JOIN::make_range_rowid_filters with rowid_filter=on Created: 2019-06-08  Updated: 2023-12-05

Status: Stalled
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.4
Fix Version/s: 10.4

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Igor Babaev
Resolution: Unresolved Votes: 1
Labels: None

Issue Links:
Relates
relates to MDEV-30651 SIGSEGV in st_join_table::save_explai... Open
relates to MDEV-22160 SIGSEGV in st_join_table::save_explai... Closed
relates to MDEV-26446 Crash on st_join_table::save_explain_... Closed

 Description   

CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
 
CREATE TABLE t2 (pk INT, b INT, PRIMARY KEY(pk), KEY(b)) ENGINE=MyISAM;
INSERT INTO t2 VALUES
(1,10),(2,20),(3,30),(4,40),(5,50),(6,60),(7,70),(8,80),(9,90),(10,15),
(11,25),(12,35),(13,45),(14,55),(15,65),(16,75),(17,85),(18,95),(19,12),
(20,22),(21,32),(22,42),(23,52) ,(24,62);
 
SELECT * FROM t1 JOIN t2 ON a = b WHERE b IS NULL AND b > 6 OR pk <= 12 OR b > 2 AND pk > 3 AND pk < 12 OR pk <= 10;

10.4 debug 973b281e

mysqld: /data/src/10.4/sql/sql_select.cc:1641: bool JOIN::make_range_rowid_filters(): Assertion `sel->quick' failed.
190608 17:18:01 [ERROR] mysqld got signal 6 ;
 
#7  0x00007fe30f058f12 in __GI___assert_fail (assertion=0x560ad2370ce1 "sel->quick", file=0x560ad23708a0 "/data/src/10.4/sql/sql_select.cc", line=1641, function=0x560ad2374500 <JOIN::make_range_rowid_filters()::__PRETTY_FUNCTION__> "bool JOIN::make_range_rowid_filters()") at assert.c:101
#8  0x0000560ad17a80ea in JOIN::make_range_rowid_filters (this=0x7fe2f80177f8) at /data/src/10.4/sql/sql_select.cc:1641
#9  0x0000560ad17aa488 in JOIN::optimize_stage2 (this=0x7fe2f80177f8) at /data/src/10.4/sql/sql_select.cc:2242
#10 0x0000560ad17aa2d4 in JOIN::optimize_inner (this=0x7fe2f80177f8) at /data/src/10.4/sql/sql_select.cc:2218
#11 0x0000560ad17a7e4c in JOIN::optimize (this=0x7fe2f80177f8) at /data/src/10.4/sql/sql_select.cc:1562
#12 0x0000560ad17b2c42 in mysql_select (thd=0x7fe2f8000b00, tables=0x7fe2f8013818, wild_num=1, fields=..., conds=0x7fe2f8015cc8, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7fe2f80177d0, unit=0x7fe2f8004a28, select_lex=0x7fe2f8013258) at /data/src/10.4/sql/sql_select.cc:4590
#13 0x0000560ad17a32ca in handle_select (thd=0x7fe2f8000b00, lex=0x7fe2f8004960, result=0x7fe2f80177d0, setup_tables_done_option=0) at /data/src/10.4/sql/sql_select.cc:424
#14 0x0000560ad176cc72 in execute_sqlcom_select (thd=0x7fe2f8000b00, all_tables=0x7fe2f8013818) at /data/src/10.4/sql/sql_parse.cc:6612
#15 0x0000560ad1761eec in mysql_execute_command (thd=0x7fe2f8000b00) at /data/src/10.4/sql/sql_parse.cc:3884
#16 0x0000560ad1770a07 in mysql_parse (thd=0x7fe2f8000b00, rawbuf=0x7fe2f8013108 "SELECT * FROM t1 JOIN t2 ON a = b WHERE b IS NULL AND b > 6 OR pk <= 12 OR b > 2 AND pk > 3 AND pk < 12 OR pk <= 10", length=115, parser_state=0x7fe30922a180, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:8164
#17 0x0000560ad175c0e3 in dispatch_command (command=COM_QUERY, thd=0x7fe2f8000b00, packet=0x7fe2f8008311 "SELECT * FROM t1 JOIN t2 ON a = b WHERE b IS NULL AND b > 6 OR pk <= 12 OR b > 2 AND pk > 3 AND pk < 12 OR pk <= 10", packet_length=115, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:1829
#18 0x0000560ad175a8a1 in do_command (thd=0x7fe2f8000b00) at /data/src/10.4/sql/sql_parse.cc:1362
#19 0x0000560ad18d3225 in do_handle_one_connection (connect=0x560ad4ba4eb0) at /data/src/10.4/sql/sql_connect.cc:1403
#20 0x0000560ad18d2f89 in handle_one_connection (arg=0x560ad4ba4eb0) at /data/src/10.4/sql/sql_connect.cc:1306
#21 0x0000560ad21fcfbd in pfs_spawn_thread (arg=0x560ad4ac9170) at /data/src/10.4/storage/perfschema/pfs.cc:1862
#22 0x00007fe310bcd4a4 in start_thread (arg=0x7fe30922b700) at pthread_create.c:456
#23 0x00007fe30f115d0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97

10.2 non-debug 973b281e

#3  <signal handler called>
#4  0x000055f870a7338e in st_join_table::save_explain_data (this=this@entry=0x7f10d8048c38, eta=eta@entry=0x7f10d804abf0, prefix_tables=prefix_tables@entry=1, distinct_arg=distinct_arg@entry=false, first_top_tab=first_top_tab@entry=0x7f10d8048888) at /data/src/10.4/sql/sql_select.cc:25908
#5  0x000055f870a74ee6 in JOIN::save_explain_data_intern (this=this@entry=0x7f10d8014410, output=0x7f10d8014fa8, need_tmp_table_arg=<optimized out>, need_order_arg=<optimized out>, distinct_arg=distinct_arg@entry=false, message=<optimized out>) at /data/src/10.4/sql/sql_select.cc:26463
#6  0x000055f870a75048 in JOIN::save_explain_data (this=this@entry=0x7f10d8014410, output=0x7f10d8014fa8, can_overwrite=can_overwrite@entry=false, need_tmp_table=<optimized out>, need_order=<optimized out>, distinct=<optimized out>) at /data/src/10.4/sql/sql_select.cc:4131
#7  0x000055f870a75278 in JOIN::build_explain (this=this@entry=0x7f10d8014410) at /data/src/10.4/sql/sql_select.cc:1515
#8  0x000055f870a7c5ae in JOIN::optimize (this=this@entry=0x7f10d8014410) at /data/src/10.4/sql/sql_select.cc:1568
#9  0x000055f870a7d0de in mysql_select (thd=thd@entry=0x7f10d80009a8, tables=0x7f10d8010430, wild_num=1, fields=..., conds=<optimized out>, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7f10d80143e8, unit=0x7f10d8004710, select_lex=0x7f10d800fe70) at /data/src/10.4/sql/sql_select.cc:4590
#10 0x000055f870a7db0e in handle_select (thd=thd@entry=0x7f10d80009a8, lex=lex@entry=0x7f10d8004648, result=result@entry=0x7f10d80143e8, setup_tables_done_option=setup_tables_done_option@entry=0) at /data/src/10.4/sql/sql_select.cc:424
#11 0x000055f87094152b in execute_sqlcom_select (thd=thd@entry=0x7f10d80009a8, all_tables=0x7f10d8010430) at /data/src/10.4/sql/sql_parse.cc:6612
#12 0x000055f870a28634 in mysql_execute_command (thd=thd@entry=0x7f10d80009a8) at /data/src/10.4/sql/sql_parse.cc:3884
#13 0x000055f870a2f2e9 in mysql_parse (thd=thd@entry=0x7f10d80009a8, rawbuf=<optimized out>, length=115, parser_state=parser_state@entry=0x7f10ea4951c0, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /data/src/10.4/sql/sql_parse.cc:8164
#14 0x000055f870a3166e in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x7f10d80009a8, packet=packet@entry=0x7f10d8007979 "SELECT * FROM t1 JOIN t2 ON a = b WHERE b IS NULL AND b > 6 OR pk <= 12 OR b > 2 AND pk > 3 AND pk < 12 OR pk <= 10", packet_length=packet_length@entry=115, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /data/src/10.4/sql/sql_parse.cc:1829
#15 0x000055f870a32c19 in do_command (thd=0x7f10d80009a8) at /data/src/10.4/sql/sql_parse.cc:1362
#16 0x000055f870b005d4 in do_handle_one_connection (connect=connect@entry=0x55f872789b68) at /data/src/10.4/sql/sql_connect.cc:1403
#17 0x000055f870b006f4 in handle_one_connection (arg=arg@entry=0x55f872789b68) at /data/src/10.4/sql/sql_connect.cc:1306
#18 0x000055f8710a6e94 in pfs_spawn_thread (arg=0x55f872734d78) at /data/src/10.4/storage/perfschema/pfs.cc:1862
#19 0x00007f10f1e3a4a4 in start_thread (arg=0x7f10ea496700) at pthread_create.c:456
#20 0x00007f10f0382d0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97

Reproducible with MyISAM for t2 and any of MyISAM, InnoDB, Aria for t1.



 Comments   
Comment by Igor Babaev [ 2020-04-12 ]

Some observations:
The following modification of the reported query still fails with the same assertion:

SELECT * FROM t1 JOIN t2 ON a = b WHERE pk <= 4 OR b > 2 AND pk > 3 AND pk < 4 OR pk <= 3 OR b < 2 AND b > 2;

When I remove any of the 4 disjuncts from the where clause the failure disappears.
If I put the first disjunct after the second or after the third the failure disappears.
If I put the third disjunct before the first or before the second the failure disappears.
If I remove any of conjuncts from the second disjunct the failure disappears.
If I make the constant in pk <= 3 less than 3 the failure disappears, but if I make it greater than 3 the failure remains
If I make the constant in pk <= 4 less than 4 the failure disappears, but if I make it greater than 4 the failure remains
The failure remains with the following modification:

SELECT * FROM t1 JOIN t2 ON a = b WHERE  pk <= 6 OR b > 2 AND pk > 3 AND pk < 5 OR pk <= 4 OR b < 2 AND b > 2;

When I move ON condition to WHERE

SELECT * FROM t1, t2 WHERE ( pk <= 6 OR b > 2 AND pk > 3 AND pk < 5 OR pk <= 4 OR b < 2 AND b > 2) AND a = b ;

the failure remains.
The analysis will be performed with this modification.

Comment by Alice Sherepa [ 2023-01-13 ]

There is no assertion after this query now(10.4 71e8e4934db06c02db1b51716 ).
But the query plan changed and now it does not use rowid filter (probably after MDEV-28846 ):

10.4.26

MariaDB [test]> explain extended 
    -> SELECT * FROM t1 JOIN t2 ON a = b WHERE b IS NULL AND b > 6 OR pk <= 12 OR b > 2 AND pk > 3 AND pk < 12 OR pk <= 10;
+------+-------------+-------+------------+---------------+-----------+---------+-----------+---------+----------+---------------------------------+
| id   | select_type | table | type       | possible_keys | key       | key_len | ref       | rows    | filtered | Extra                           |
+------+-------------+-------+------------+---------------+-----------+---------+-----------+---------+----------+---------------------------------+
|    1 | SIMPLE      | t1    | ALL        | NULL          | NULL      | NULL    | NULL      | 2       |   100.00 | Using where                     |
|    1 | SIMPLE      | t2    | ref|filter | PRIMARY,b     | b|PRIMARY | 5|4     | test.t1.a | 2 (50%) |    50.00 | Using where; Using rowid filter |
+------+-------------+-------+------------+---------------+-----------+---------+-----------+---------+----------+---------------------------------+
2 rows in set, 1 warning (0,001 sec)
 
Note (Code 1003): select `test`.`t1`.`a` AS `a`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`b` = `test`.`t1`.`a` and (`test`.`t2`.`pk` <= 12 or `test`.`t1`.`a` > 2 and `test`.`t2`.`pk` > 3 and `test`.`t2`.`pk` < 12 or `test`.`t2`.`pk` <= 10)

10.4 71e8e4934db06c02db1b51716, 10.4.27

MariaDB [test]> explain extended  SELECT * FROM t1 JOIN t2 ON a = b WHERE b IS NULL AND b > 6 OR pk <= 12 OR b > 2 AND pk > 3 AND pk < 12 OR pk <= 10;
+------+-------------+-------+------+---------------+------+---------+-----------+------+----------+-------------+
| id   | select_type | table | type | possible_keys | key  | key_len | ref       | rows | filtered | Extra       |
+------+-------------+-------+------+---------------+------+---------+-----------+------+----------+-------------+
|    1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL      | 2    |   100.00 | Using where |
|    1 | SIMPLE      | t2    | ref  | PRIMARY,b     | b    | 5       | test.t1.a | 1    |    50.00 | Using where |
+------+-------------+-------+------+---------------+------+---------+-----------+------+----------+-------------+
2 rows in set, 1 warning (0,004 sec)
 
Note (Code 1003): select `test`.`t1`.`a` AS `a`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`b` = `test`.`t1`.`a` and (`test`.`t2`.`pk` <= 12 or `test`.`t1`.`a` > 2 and `test`.`t2`.`pk` > 3 and `test`.`t2`.`pk` < 12 or `test`.`t2`.`pk` <= 10)

Comment by Roel Van de Paar [ 2023-02-14 ]

Confirmed no more crashes, nor any UBSAN or ASAN errors. However, I did see this same assert in 10.5+ ref MDEV-30651

Comment by Julien Fritsch [ 2023-12-05 ]

Automated message:
----------------------------
Since this issue has not been updated since 6 weeks, it's time to move it back to Stalled.

Comment by JiraAutomate [ 2023-12-05 ]

Automated message:
----------------------------
Since this issue has not been updated since 6 weeks, it's time to move it back to Stalled.

Generated at Thu Feb 08 08:53:50 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.