[MDEV-28320] Assertion `0' in QUICK_ROR_UNION_SELECT::need_sorted_output Created: 2022-04-14  Updated: 2023-03-03

Status: Open
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.5, 10.6, 10.7, 10.8
Fix Version/s: 10.5, 10.6

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Sergei Petrunia
Resolution: Unresolved Votes: 0
Labels: None


 Description   

Run with --mysqld=--innodb-page-size=4K

--source include/have_innodb.inc
--source include/have_innodb_4k.inc
 
SET @stats= @@innodb_stats_persistent;
SET GLOBAL innodb_stats_persistent= ON;
 
CREATE TABLE t (a INT, b CHAR(202), c INT, PRIMARY KEY (a,c,b)) ENGINE=InnoDB;
INSERT INTO t (b,c,a) VALUES
  ('a',8,3),('b',9,3),('c',0,3),('d',3,4),('e',1,4),('f',6,3),('g',9,4),
  ('h',0,3),('i',7,3),('j',2,3),('k',1,4),('l',6,4),('m',7,4),('n',3,3),
  ('o',5,4),('p',4,3),('q',3,4),('r',5,4),('s',7,4),('t',9,4),('u',8,4),
  ('v',3,4),('w',0,4),('x',5,4),('y',1,3),('z',5,4),('a',7,4),('b',8,3),
  ('c',9,3),('d',5,4),('e',6,4),('f',8,3),('g',6,4),('h',3,4),('i',2,4),
  ('j',0,4),('k',2,4),('l',1,3),('m',5,3),('n',7,4),('o',3,3),('p',6,3),
  ('q',1,4),('r',8,3),('s',2,3),('t',7,4),('u',7,3),('v',4,4),('w',7,3),
  ('x',6,3),('y',4,3),('z',6,4),('a',6,8),('b',6,3),('c',2,2),('d',1,1);
 
SELECT DISTINCT a FROM t WHERE (a IN (1, 255) OR c IN (-1, 255)) AND a NOT IN (1) AND a IN (10, 1, 255, 3, 4);
 
# Cleanup
DROP TABLE t;
SET GLOBAL innodb_stats_persistent= @stats;

10.5 e41500e4

mariadbd: /data/src/10.5/sql/opt_range.h:1503: virtual void QUICK_ROR_UNION_SELECT::need_sorted_output(): Assertion `0' failed.
220415  2:45:45 [ERROR] mysqld got signal 6 ;
 
#7  0x00007f7e8f60a662 in __GI___assert_fail (assertion=0x564e4f701d68 "0", file=0x564e4f7024b8 "/data/src/10.5/sql/opt_range.h", line=1503, function=0x564e4f702620 "virtual void QUICK_ROR_UNION_SELECT::need_sorted_output()") at assert.c:101
#8  0x0000564e4ec8b362 in QUICK_ROR_UNION_SELECT::need_sorted_output (this=0x7f7e4c03fe10) at /data/src/10.5/sql/opt_range.h:1503
#9  0x0000564e4e7f392a in test_if_skip_sort_order (tab=0x7f7e4c01a1b8, order=0x7f7e4c01b148, select_limit=56, no_changes=false, map=0x7f7e4c102308) at /data/src/10.5/sql/sql_select.cc:24056
#10 0x0000564e4e7b8388 in JOIN::optimize_stage2 (this=0x7f7e4c018078) at /data/src/10.5/sql/sql_select.cc:2990
#11 0x0000564e4e7b5e03 in JOIN::optimize_inner (this=0x7f7e4c018078) at /data/src/10.5/sql/sql_select.cc:2337
#12 0x0000564e4e7b3777 in JOIN::optimize (this=0x7f7e4c018078) at /data/src/10.5/sql/sql_select.cc:1669
#13 0x0000564e4e7bebba in mysql_select (thd=0x7f7e4c000db8, tables=0x7f7e4c015a60, fields=..., conds=0x7f7e4c016f30, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748609, result=0x7f7e4c018050, unit=0x7f7e4c004f60, select_lex=0x7f7e4c015448) at /data/src/10.5/sql/sql_select.cc:4781
#14 0x0000564e4e7ae60b in handle_select (thd=0x7f7e4c000db8, lex=0x7f7e4c004e98, result=0x7f7e4c018050, setup_tables_done_option=0) at /data/src/10.5/sql/sql_select.cc:444
#15 0x0000564e4e7714ce in execute_sqlcom_select (thd=0x7f7e4c000db8, all_tables=0x7f7e4c015a60) at /data/src/10.5/sql/sql_parse.cc:6330
#16 0x0000564e4e7687ed in mysql_execute_command (thd=0x7f7e4c000db8) at /data/src/10.5/sql/sql_parse.cc:4021
#17 0x0000564e4e7762af in mysql_parse (thd=0x7f7e4c000db8, rawbuf=0x7f7e4c015310 "SELECT DISTINCT a FROM t WHERE (a IN (1, 255) OR c IN (-1, 255)) AND a NOT IN (1) AND a IN (10, 1, 255, 3, 4)", length=109, parser_state=0x7f7e889b4510, is_com_multi=false, is_next_command=false) at /data/src/10.5/sql/sql_parse.cc:8116
#18 0x0000564e4e7623c0 in dispatch_command (command=COM_QUERY, thd=0x7f7e4c000db8, packet=0x7f7e4c00b5c9 "SELECT DISTINCT a FROM t WHERE (a IN (1, 255) OR c IN (-1, 255)) AND a NOT IN (1) AND a IN (10, 1, 255, 3, 4)", packet_length=109, is_com_multi=false, is_next_command=false) at /data/src/10.5/sql/sql_parse.cc:1907
#19 0x0000564e4e760b4c in do_command (thd=0x7f7e4c000db8) at /data/src/10.5/sql/sql_parse.cc:1375
#20 0x0000564e4e90d779 in do_handle_one_connection (connect=0x564e52963ee8, put_in_cache=true) at /data/src/10.5/sql/sql_connect.cc:1418
#21 0x0000564e4e90d43b in handle_one_connection (arg=0x564e5298c618) at /data/src/10.5/sql/sql_connect.cc:1312
#22 0x0000564e4ee1d148 in pfs_spawn_thread (arg=0x564e529c92f8) at /data/src/10.5/storage/perfschema/pfs.cc:2201
#23 0x00007f7e8fad6ea7 in start_thread (arg=<optimized out>) at pthread_create.c:477
#24 0x00007f7e8f6d3def in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Not reproducible on 10.4.
No obvious problem on a non-debug build.

EXPLAIN fails on the debug build as well, here is the plan from a non-debug build:

EXPLAIN
{
  "query_block": {
    "select_id": 1,
    "table": {
      "table_name": "t",
      "access_type": "index_merge",
      "possible_keys": ["PRIMARY"],
      "key_length": "4,8",
      "index_merge": {
        "union": {
          "range": {
            "key": "PRIMARY",
            "used_key_parts": ["a"]
          },
          "range": {
            "key": "PRIMARY",
            "used_key_parts": ["a", "c"]
          }
        }
      },
      "rows": 9,
      "filtered": 98.2142868,
      "attached_condition": "(t.a in (1,255) or t.c in (-1,255)) and t.a <> 1 and t.a in (10,1,255,3,4)"
    }
  }
}

The failure started happening on 10.5 branch after this commit

commit eb483c5181ab430877c135c16224284cfc517b3d
Author: Monty
Date:   Fri Feb 28 12:59:30 2020 +0200
 
    Updated optimizer costs in multi_range_read_info_const() and sql_select.cc

but it's probably just because the plan changed after that.



 Comments   
Comment by Elena Stepanova [ 2022-10-31 ]

Got a similar assertion failure on 10.4, so it must be possible even if the provided test case does not reproduce it there.

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