[MDEV-21579] Assertion `ordered_index_usage == ordered_index_order_by' failed in JOIN::optimize_distinct Created: 2020-01-27  Updated: 2023-11-28

Status: Confirmed
Project: MariaDB Server
Component/s: None
Affects Version/s: 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9
Fix Version/s: 10.4, 10.5, 10.6

Type: Bug Priority: Major
Reporter: Alice Sherepa Assignee: Igor Babaev
Resolution: Unresolved Votes: 0
Labels: None


 Description   

--source include/have_innodb.inc
 
CREATE TABLE t1 (i1 int , pk int NOT NULL PRIMARY KEY, KEY i1 (i1)) engine=innodb;
INSERT INTO t1 VALUES (100,1),(100,2),(100,3),(100,4),(100,5),(100,6),(100,7),(100,8),(100,9),(100,10);
 
SELECT DISTINCT i1 FROM t1 WHERE i1>"" ORDER BY pk LIMIT 5;

10.2 0a891ad6a6ba698484ba

#6  0x00007f61e4c93bd7 in __assert_fail_base (fmt=<optimized out>, assertion=assertion@entry=0x5556cbfe4f30 "ordered_index_usage == ordered_index_order_by", file=file@entry=0x5556cbfe48c8 "/10.2/sql/sql_select.cc", line=line@entry=3056, function=function@entry=0x5556cbfe74c0 <JOIN::optimize_distinct()::__PRETTY_FUNCTION__> "void JOIN::optimize_distinct()") at assert.c:92
#7  0x00007f61e4c93c82 in __GI___assert_fail (assertion=0x5556cbfe4f30 "ordered_index_usage == ordered_index_order_by", file=0x5556cbfe48c8 "/10.2/sql/sql_select.cc", line=3056, function=0x5556cbfe74c0 <JOIN::optimize_distinct()::__PRETTY_FUNCTION__> "void JOIN::optimize_distinct()") at assert.c:101
#8  0x00005556cb541811 in JOIN::optimize_distinct (this=0x7f618c0131f0) at /10.2/sql/sql_select.cc:3056
#9  0x00005556cb53fa03 in JOIN::make_aggr_tables_info (this=0x7f618c0131f0) at /10.2/sql/sql_select.cc:2574
#10 0x00005556cb53e577 in JOIN::optimize_inner (this=0x7f618c0131f0) at /10.2/sql/sql_select.cc:2237
#11 0x00005556cb53a671 in JOIN::optimize (this=0x7f618c0131f0) at /10.2/sql/sql_select.cc:1113
#12 0x00005556cb543b98 in mysql_select (thd=0x7f618c000af0, tables=0x7f618c012688, wild_num=0, fields=..., conds=0x7f618c012e50, og_num=1, order=0x7f618c0130b8, group=0x0, having=0x0, proc_param=0x0, select_options=2147748609, result=0x7f618c0131d0, unit=0x7f618c0046e8, select_lex=0x7f618c004e28) at /10.2/sql/sql_select.cc:3810
#13 0x00005556cb537e1e in handle_select (thd=0x7f618c000af0, lex=0x7f618c004628, result=0x7f618c0131d0, setup_tables_done_option=0) at /10.2/sql/sql_select.cc:373
#14 0x00005556cb503347 in execute_sqlcom_select (thd=0x7f618c000af0, all_tables=0x7f618c012688) at /10.2/sql/sql_parse.cc:6225
#15 0x00005556cb4f9d5a in mysql_execute_command (thd=0x7f618c000af0) at /10.2/sql/sql_parse.cc:3532
#16 0x00005556cb5071c1 in mysql_parse (thd=0x7f618c000af0, rawbuf=0x7f618c012448 "SELECT DISTINCT i1 FROM t1 WHERE i1>\"\" ORDER BY pk LIMIT 5", length=58, parser_state=0x7f61dc30e080, is_com_multi=false, is_next_command=false) at /10.2/sql/sql_parse.cc:7740
#17 0x00005556cb4f54be in dispatch_command (command=COM_QUERY, thd=0x7f618c000af0, packet=0x7f618c0963f1 "SELECT DISTINCT i1 FROM t1 WHERE i1>\"\" ORDER BY pk LIMIT 5", packet_length=58, is_com_multi=false, is_next_command=false) at /10.2/sql/sql_parse.cc:1831
#18 0x00005556cb4f3dd2 in do_command (thd=0x7f618c000af0) at /10.2/sql/sql_parse.cc:1385
#19 0x00005556cb649db7 in do_handle_one_connection (connect=0x5556ced40090) at /10.2/sql/sql_connect.cc:1336
#20 0x00005556cb649b22 in handle_one_connection (arg=0x5556ced40090) at /10.2/sql/sql_connect.cc:1241
#21 0x00005556cbe62d9e in pfs_spawn_thread (arg=0x5556ced4ae80) at /10.2/storage/perfschema/pfs.cc:1869
#22 0x00007f61e58d86ba in start_thread (arg=0x7f61dc30f700) at pthread_create.c:333
#23 0x00007f61e4d6d41d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109



 Comments   
Comment by Alice Sherepa [ 2022-06-21 ]

Currently, it is reproducible on 10.3,10.4 (c89e3b70a740f486db2c602) with the provided test case, and not on 10.5+, but I see the same assertion in tests on 10.10:

bb-10.10-MDEV-28881 812f8cbfb3a7a02705f65d8bb7e3

/10.10/sql/sql_select.cc:4165: void JOIN::optimize_distinct(): Assertion `ordered_index_usage == ordered_index_order_by' failed.
220621 13:53:48 [ERROR] mysqld got signal 6 ;
 
Server version: 10.10.0-MariaDB-debug-log
 
sql/sql_select.cc:4166(JOIN::optimize_distinct())[0x55879197fa44]
sql/sql_select.cc:3661(JOIN::make_aggr_tables_info())[0x558791979e00]
sql/sql_select.cc:3278(JOIN::optimize_stage2())[0x558791975709]
sql/sql_select.cc:2537(JOIN::optimize_inner())[0x55879196dd16]
sql/sql_select.cc:1850(JOIN::optimize())[0x558791966904]
sql/sql_select.cc:5038(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*))[0x558791987d28]
sql/sql_select.cc:583(handle_select(THD*, LEX*, select_result*, unsigned long))[0x5587919587ef]
sql/sql_parse.cc:6260(execute_sqlcom_select(THD*, TABLE_LIST*))[0x558791882f8e]
sql/sql_parse.cc:3944(mysql_execute_command(THD*, bool))[0x55879187193f]
sql/sql_parse.cc:8036(mysql_parse(THD*, char*, unsigned int, Parser_state*))[0x55879188dd8b]
sql/sql_parse.cc:1896(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool))[0x558791864437]
sql/sql_parse.cc:1407(do_command(THD*, bool))[0x55879186116d]
sql/sql_connect.cc:1418(do_handle_one_connection(CONNECT*, bool))[0x558791cffa77]
sql/sql_connect.cc:1314(handle_one_connection)[0x558791cff2fc]
perfschema/pfs.cc:2203(pfs_spawn_thread)[0x55879299d741]
nptl/pthread_create.c:487(start_thread)[0x7ff525542fa3]
x86_64/clone.S:97(clone)[0x7ff52514beff]

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