[MDEV-15178] Filesort::make_sortorder: Assertion `pos->field != __null || pos->item != __null' failed | SIGSEGV in sortlength (on optimized builds) Created: 2018-02-02  Updated: 2023-12-27  Resolved: 2023-01-23

Status: Closed
Project: MariaDB Server
Component/s: Optimizer - Window functions
Affects Version/s: 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10
Fix Version/s: 10.11.2, 10.3.38, 10.4.28, 10.5.19, 10.6.12, 10.7.8, 10.8.7, 10.9.5, 10.10.3

Type: Bug Priority: Blocker
Reporter: Alice Sherepa Assignee: Sergei Petrunia
Resolution: Fixed Votes: 4
Labels: None

Issue Links:
Duplicate
is duplicated by MDEV-17014 Crash server using ROW_NUMBER() OVER ... Closed
is duplicated by MDEV-19945 Crash on Filesort Closed
is duplicated by MDEV-20187 MariaDB cashed on WindowFunction Closed
is duplicated by MDEV-21059 Running Query lost connection and the... Closed
is duplicated by MDEV-24028 Server crash after running a query Closed
is duplicated by MDEV-24276 mariadb crash Closed
is duplicated by MDEV-30039 Crash when using count (distinct) com... Closed
Relates
relates to MDEV-22852 SIGSEGV in sortlength (optimized builds) Closed
relates to MDEV-15757 MariaDB frequent crash on Signal 11 Closed
relates to MDEV-33121 Assertion Failed at /mariadb-11.3.0/s... Confirmed

 Description   

testcase:

 
CREATE TABLE t1 (i1 int, a int);
INSERT INTO t1 VALUES (1, 1), (2, 2),(3, 3);
 
CREATE TABLE t2 (i2 int);
INSERT INTO t2 VALUES (1),(2),(5),(1),(7),(4),(3);
 
SELECT  a, RANK() OVER (ORDER BY SUM(DISTINCT i1))
     FROM t1, t2 WHERE t2.i2 = t1.i1 GROUP BY a;
 
DROP TABLE t1, t2;

10.2 00572a0b0cc81c38f198ad

/10.2/sql/filesort.cc:493: uint Filesort::make_sortorder(THD*, JOIN*, table_map): Assertion `pos->field != __null || pos->item != __null' failed.
 
assert/assert.c:92(__assert_fail_base)[0x7fcdf5102bd7]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dc82)[0x7fcdf5102c82]
sql/filesort.cc:455(Filesort::make_sortorder(THD*, JOIN*, unsigned long long))[0x56419343528e]
sql/filesort.cc:159(filesort(THD*, TABLE*, Filesort*, Filesort_tracker*, JOIN*, unsigned long long))[0x564193432c9d]
sql/sql_select.cc:21908(create_sort_index(THD*, JOIN*, st_join_table*, Filesort*))[0x564192fa0569]
sql/sql_window.cc:2761(Window_funcs_sort::exec(JOIN*, bool))[0x5641932acac9]
sql/sql_window.cc:2893(Window_funcs_computation::exec(JOIN*, bool))[0x5641932ad821]
sql/sql_select.cc:26671(AGGR_OP::end_send())[0x564192fc1e4e]
sql/sql_select.cc:18473(sub_select_postjoin_aggr(JOIN*, st_join_table*, bool))[0x564192f8a3a5]
sql/sql_select.cc:18709(sub_select(JOIN*, st_join_table*, bool))[0x564192f8ab24]
sql/sql_select.cc:18540(sub_select_cache(JOIN*, st_join_table*, bool))[0x564192f8a656]
sql/sql_select.cc:18709(sub_select(JOIN*, st_join_table*, bool))[0x564192f8ab24]
sql/sql_select.cc:18304(do_select(JOIN*, Procedure*))[0x564192f897b9]
sql/sql_select.cc:3623(JOIN::exec_inner())[0x564192f2bfcc]
sql/sql_select.cc:3419(JOIN::exec())[0x564192f29cd2]
sql/sql_select.cc:3820(mysql_select(THD*, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*))[0x564192f2d01f]
sql/sql_select.cc:376(handle_select(THD*, LEX*, select_result*, unsigned long))[0x564192f0c7e5]
sql/sql_parse.cc:6477(execute_sqlcom_select(THD*, TABLE_LIST*))[0x564192e94155]
sql/sql_parse.cc:3535(mysql_execute_command(THD*))[0x564192e8161b]
sql/sql_parse.cc:8011(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x564192e9c8b9]
sql/sql_parse.cc:1834(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x564192e77f6e]
sql/sql_parse.cc:1386(do_command(THD*))[0x564192e750ed]
sql/sql_connect.cc:1335(do_handle_one_connection(CONNECT*))[0x56419319cd62]
sql/sql_connect.cc:1242(handle_one_connection)[0x56419319c76a]
perfschema/pfs.cc:1864(pfs_spawn_thread)[0x56419434dfda]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba)[0x7fcdf5d476ba]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7fcdf51dc41d]



 Comments   
Comment by Varun Gupta (Inactive) [ 2019-08-11 ]

Patch
http://lists.askmonty.org/pipermail/commits/2019-August/013927.html

Comment by Alice Sherepa [ 2019-11-18 ]

on non-debug version (adding it here to make it searchable):

10.3 409ed60bb844252d46127c5

191118 11:46:33 [ERROR] mysqld got signal 11 ;
Server version: 10.3.21-MariaDB-log
 
sql/signal_handler.cc:209(handle_fatal_signal)[0x55c9eef07b17]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7fae19254390]
sql/filesort.cc:1951(sortlength)[0x55c9eef05da4]
sql/sql_select.cc:22739(create_sort_index(THD*, JOIN*, st_join_table*, Filesort*))[0x55c9eed818ae]
sql/sql_window.cc:2994(Window_funcs_sort::exec(JOIN*, bool))[0x55c9eee6c389]
sql/sql_window.cc:3126(Window_funcs_computation::exec(JOIN*, bool))[0x55c9eee6cc6b]
sql/sql_select.cc:27600(AGGR_OP::end_send())[0x55c9eed9164b]
sql/sql_select.cc:19243(sub_select_postjoin_aggr(JOIN*, st_join_table*, bool))[0x55c9eed917fd]
sql/sql_select.cc:19068(do_select)[0x55c9eed924fa]
sql/sql_select.cc:3835(JOIN::exec())[0x55c9eed925b9]
sql/sql_select.cc:4241(mysql_select(THD*, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*))[0x55c9eed92702]
sql/sql_select.cc:382(handle_select(THD*, LEX*, select_result*, unsigned long))[0x55c9eed93037]
sql/sql_parse.cc:6293(execute_sqlcom_select(THD*, TABLE_LIST*) [clone .constprop.242])[0x55c9eec66d7b]
sql/sql_parse.cc:3821(mysql_execute_command(THD*))[0x55c9eed44c04]
sql/sql_parse.cc:7815(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x55c9eed46889]
sql/sql_parse.cc:1856(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x55c9eed490f4]
sql/sql_parse.cc:1404(do_command(THD*))[0x55c9eed49ba0]
sql/sql_connect.cc:1403(do_handle_one_connection(CONNECT*))[0x55c9eee10ed4]
sql/sql_connect.cc:1310(handle_one_connection)[0x55c9eee10f84]
perfschema/pfs.cc:1865(pfs_spawn_thread)[0x55c9ef37ca64]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba)[0x7fae1924a6ba]
x86_64/clone.S:111(clone)[0x7fae186df41d]

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

Related to MDEV-22852 ?

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

10.5.5 Affected also (original testcase)

10.5.5 e1013725ce0f3f947e728491eef75d9985e8db2f (Debug)

mysqld: /test/10.5_dbg/sql/filesort.cc:597: Sort_keys* Filesort::make_sortorder(THD*, JOIN*, table_map): Assertion `pos->field != __null || pos->item != __null' failed.

10.5.5 e1013725ce0f3f947e728491eef75d9985e8db2f (Debug)

Core was generated by `/ram/MD250620-mariadb-10.5.5-linux-x86_64-dbg/bin/mysqld --no-defaults --core-f'.
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 0x14c307dec700 (LWP 898943))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
#1  0x00005565683897d0 in my_write_core (sig=sig@entry=6) at /test/10.5_dbg/mysys/stacktrace.c:518
#2  0x0000556567b4247a 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  0x000014c3060828b1 in __GI_abort () at abort.c:79
#6  0x000014c30607242a in __assert_fail_base (fmt=0x14c3061f9a38 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x556568698878 "pos->field != __null || pos->item != __null", file=file@entry=0x5565686986f0 "/test/10.5_dbg/sql/filesort.cc", line=line@entry=597, function=function@entry=0x556568699500 <Filesort::make_sortorder(THD*, JOIN*, unsigned long long)::__PRETTY_FUNCTION__> "Sort_keys* Filesort::make_sortorder(THD*, JOIN*, table_map)") at assert.c:92
#7  0x000014c3060724a2 in __GI___assert_fail (assertion=assertion@entry=0x556568698878 "pos->field != __null || pos->item != __null", file=file@entry=0x5565686986f0 "/test/10.5_dbg/sql/filesort.cc", line=line@entry=597, function=function@entry=0x556568699500 <Filesort::make_sortorder(THD*, JOIN*, unsigned long long)::__PRETTY_FUNCTION__> "Sort_keys* Filesort::make_sortorder(THD*, JOIN*, table_map)") at assert.c:101
#8  0x0000556567b3a7ed in Filesort::make_sortorder (this=this@entry=0x14c2e3180e60, thd=thd@entry=0x14c2e3015088, join=join@entry=0x14c2e3076c40, first_table_bit=first_table_bit@entry=1) at /test/10.5_dbg/sql/filesort.cc:597
#9  0x0000556567b3e797 in filesort (thd=thd@entry=0x14c2e3015088, table=table@entry=0x14c2e31820a0, filesort=filesort@entry=0x14c2e3180e60, tracker=0x14c2e3195d60, join=join@entry=0x14c2e3076c40, first_table_bit=1) at /test/10.5_dbg/sql/filesort.cc:211
#10 0x00005565678ed422 in create_sort_index (thd=thd@entry=0x14c2e3015088, join=join@entry=0x14c2e3076c40, tab=tab@entry=0x14c2e30798e0, fsort=0x14c2e3180e60) at /test/10.5_dbg/sql/sql_select.cc:23834
#11 0x0000556567a8ed80 in Window_funcs_sort::exec (this=0x14c2e3180d58, join=join@entry=0x14c2e3076c40, keep_filesort_result=<optimized out>) at /test/10.5_dbg/sql/sql_window.cc:2998
#12 0x0000556567a8f4a1 in Window_funcs_computation::exec (this=0x14c2e3180d38, join=join@entry=0x14c2e3076c40, keep_last_filesort_result=keep_last_filesort_result@entry=false) at /test/10.5_dbg/sql/sql_window.cc:3131
#13 0x00005565678f4d52 in AGGR_OP::end_send (this=this@entry=0x14c2e307a060) at /test/10.5_dbg/sql/sql_select.cc:28842
#14 0x00005565678f5299 in sub_select_postjoin_aggr (join=0x14c2e3076c40, join_tab=0x14c2e30798e0, end_of_records=<optimized out>) at /test/10.5_dbg/sql/sql_select.cc:20310
#15 0x00005565678dd065 in sub_select (join=join@entry=0x14c2e3076c40, join_tab=join_tab@entry=0x14c2e3079538, end_of_records=end_of_records@entry=true) at /test/10.5_dbg/sql/sql_select.cc:20545
#16 0x00005565678dd656 in sub_select_cache (join=0x14c2e3076c40, join_tab=0x14c2e3079538, end_of_records=<optimized out>) at /test/10.5_dbg/sql/sql_select.cc:20377
#17 0x00005565678dd065 in sub_select (join=0x14c2e3076c40, join_tab=0x14c2e3079190, end_of_records=<optimized out>) at /test/10.5_dbg/sql/sql_select.cc:20545
#18 0x0000556567916402 in do_select (procedure=<optimized out>, join=0x14c2e3076c40) at /test/10.5_dbg/sql/sql_select.cc:20136
#19 JOIN::exec_inner (this=this@entry=0x14c2e3076c40) at /test/10.5_dbg/sql/sql_select.cc:4444
#20 0x000055656791676b in JOIN::exec (this=this@entry=0x14c2e3076c40) at /test/10.5_dbg/sql/sql_select.cc:4225
#21 0x0000556567914a80 in mysql_select (thd=thd@entry=0x14c2e3015088, tables=<optimized out>, fields=@0x14c2e3074320: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14c2e3074788, last = 0x14c2e3074e20, elements = 2}, <No data fields>}, conds=0x14c2e3075f38, og_num=1, order=<optimized out>, group=0x14c2e30762c8, having=0x0, proc_param=0x0, select_options=2147748608, result=0x14c2e3076c18, unit=0x14c2e30190a0, select_lex=0x14c2e30741d0) at /test/10.5_dbg/sql/sql_select.cc:4649
#22 0x0000556567914daf in handle_select (thd=thd@entry=0x14c2e3015088, lex=lex@entry=0x14c2e3018fd8, result=result@entry=0x14c2e3076c18, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.5_dbg/sql/sql_select.cc:417
#23 0x000055656789e6c9 in execute_sqlcom_select (thd=thd@entry=0x14c2e3015088, all_tables=0x14c2e3074e90) at /test/10.5_dbg/sql/sql_parse.cc:6211
#24 0x00005565678977c2 in mysql_execute_command (thd=thd@entry=0x14c2e3015088) at /test/10.5_dbg/sql/sql_parse.cc:3939
#25 0x00005565678a4638 in mysql_parse (thd=thd@entry=0x14c2e3015088, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x14c307deb350, 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:7995
#26 0x0000556567891110 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x14c2e3015088, packet=packet@entry=0x14c2e3067089 "", packet_length=packet_length@entry=98, 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
#27 0x000055656788f8ea in do_command (thd=0x14c2e3015088) at /test/10.5_dbg/sql/sql_parse.cc:1355
#28 0x00005565679eb15f in do_handle_one_connection (connect=<optimized out>, connect@entry=0x14c2e6cd2808, put_in_cache=put_in_cache@entry=true) at /test/10.5_dbg/sql/sql_connect.cc:1411
#29 0x00005565679eb87b in handle_one_connection (arg=arg@entry=0x14c2e6cd2808) at /test/10.5_dbg/sql/sql_connect.cc:1313
#30 0x0000556567e4e11c in pfs_spawn_thread (arg=0x14c304c46508) at /test/10.5_dbg/storage/perfschema/pfs.cc:2201
#31 0x000014c306d656db in start_thread (arg=0x14c307dec700) at pthread_create.c:463
#32 0x000014c306163a3f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

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

psergei is the patch still applicable?

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

USE test;
SET SESSION SQL_BUFFER_RESULT=1;
CREATE TABLE t (a INT);
SELECT (SELECT 1 FROM t AS t_inner GROUP BY t_inner.a ORDER BY MAX(t_outer.a)) FROM t AS t_outer;

Leads to:

10.5.5 e1013725ce0f3f947e728491eef75d9985e8db2f

mysqld: /test/10.5_dbg/sql/filesort.cc:597: Sort_keys* Filesort::make_sortorder(THD*, JOIN*, table_map): Assertion `pos->field != __null || pos->item != __null' failed.

10.5.5 e1013725ce0f3f947e728491eef75d9985e8db2f

Core was generated by `/test/MD250620-mariadb-10.5.5-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 0x14b397ab0700 (LWP 1126309))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
#1  0x00005597fced27d0 in my_write_core (sig=sig@entry=6) at /test/10.5_dbg/mysys/stacktrace.c:518
#2  0x00005597fc68b47a 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  0x000014b395d468b1 in __GI_abort () at abort.c:79
#6  0x000014b395d3642a in __assert_fail_base (fmt=0x14b395ebda38 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x5597fd1e1878 "pos->field != __null || pos->item != __null", file=file@entry=0x5597fd1e16f0 "/test/10.5_dbg/sql/filesort.cc", line=line@entry=597, function=function@entry=0x5597fd1e2500 <Filesort::make_sortorder(THD*, JOIN*, unsigned long long)::__PRETTY_FUNCTION__> "Sort_keys* Filesort::make_sortorder(THD*, JOIN*, table_map)") at assert.c:92
#7  0x000014b395d364a2 in __GI___assert_fail (assertion=assertion@entry=0x5597fd1e1878 "pos->field != __null || pos->item != __null", file=file@entry=0x5597fd1e16f0 "/test/10.5_dbg/sql/filesort.cc", line=line@entry=597, function=function@entry=0x5597fd1e2500 <Filesort::make_sortorder(THD*, JOIN*, unsigned long long)::__PRETTY_FUNCTION__> "Sort_keys* Filesort::make_sortorder(THD*, JOIN*, table_map)") at assert.c:101
#8  0x00005597fc6837ed in Filesort::make_sortorder (this=this@entry=0x14b373976950, thd=thd@entry=0x14b373815088, join=join@entry=0x14b373877900, first_table_bit=first_table_bit@entry=1) at /test/10.5_dbg/sql/filesort.cc:597
#9  0x00005597fc687797 in filesort (thd=thd@entry=0x14b373815088, table=table@entry=0x14b37397a0a0, filesort=filesort@entry=0x14b373976950, tracker=0x14b373976b00, join=join@entry=0x14b373877900, first_table_bit=1) at /test/10.5_dbg/sql/filesort.cc:211
#10 0x00005597fc436422 in create_sort_index (thd=0x14b373815088, join=0x14b373877900, tab=tab@entry=0x14b373975eb8, fsort=0x14b373976950, fsort@entry=0x0) at /test/10.5_dbg/sql/sql_select.cc:23834
#11 0x00005597fc436750 in st_join_table::sort_table (this=this@entry=0x14b373975eb8) at /test/10.5_dbg/sql/sql_select.cc:21584
#12 0x00005597fc436884 in join_init_read_record (tab=0x14b373975eb8) at /test/10.5_dbg/sql/sql_select.cc:21523
#13 0x00005597fc43df2e in AGGR_OP::end_send (this=this@entry=0x14b37387a050) at /test/10.5_dbg/sql/sql_select.cc:28855
#14 0x00005597fc43e299 in sub_select_postjoin_aggr (join=0x14b373877900, join_tab=0x14b373975eb8, end_of_records=<optimized out>) at /test/10.5_dbg/sql/sql_select.cc:20310
#15 0x00005597fc426065 in sub_select (join=0x14b373877900, join_tab=0x14b373975b10, end_of_records=<optimized out>) at /test/10.5_dbg/sql/sql_select.cc:20545
#16 0x00005597fc45f402 in do_select (procedure=<optimized out>, join=0x14b373877900) at /test/10.5_dbg/sql/sql_select.cc:20136
#17 JOIN::exec_inner (this=this@entry=0x14b373877900) at /test/10.5_dbg/sql/sql_select.cc:4444
#18 0x00005597fc45f76b in JOIN::exec (this=0x14b373877900) at /test/10.5_dbg/sql/sql_select.cc:4225
#19 0x00005597fc777f8c in subselect_single_select_engine::exec (this=0x14b373876138) at /test/10.5_dbg/sql/item_subselect.cc:3973
#20 0x00005597fc777307 in Item_subselect::exec (this=0x14b373875f90) at /test/10.5_dbg/sql/item_subselect.cc:782
#21 0x00005597fc775850 in Item_singlerow_subselect::val_int (this=0x14b373875f90) at /test/10.5_dbg/sql/item_subselect.cc:1375
#22 0x00005597fc2f2b0f in Item::val_int_result (this=<optimized out>) at /test/10.5_dbg/sql/item.h:1562
#23 0x00005597fc6aaeee in Item_cache_int::cache_value (this=0x14b3739771a0) at /test/10.5_dbg/sql/item.cc:9843
#24 0x00005597fc6ce777 in Item_cache_wrapper::cache (this=this@entry=0x14b3739770d8) at /test/10.5_dbg/sql/item.cc:8681
#25 0x00005597fc6c14e8 in Item_cache_wrapper::val_int (this=0x14b3739770d8) at /test/10.5_dbg/sql/item.cc:8735
#26 0x00005597fc5c7b59 in Type_handler::Item_send_long (this=<optimized out>, item=0x14b3739770d8, protocol=0x14b373815650, buf=<optimized out>) at /test/10.5_dbg/sql/sql_type.cc:7170
#27 0x00005597fc5cf263 in Type_handler_long::Item_send (this=<optimized out>, item=<optimized out>, protocol=<optimized out>, buf=<optimized out>) at /test/10.5_dbg/sql/sql_type.h:5420
#28 0x00005597fc6aa925 in Item::send (buffer=0x14b397aaded0, protocol=0x14b373815650, this=0x14b3739770d8) at /test/10.5_dbg/sql/item.h:1056
#29 Item_cache_wrapper::send (this=0x14b3739770d8, protocol=0x14b373815650, buffer=0x14b397aaded0) at /test/10.5_dbg/sql/item.cc:8587
#30 0x00005597fc2f06c9 in Protocol::send_result_set_row (this=this@entry=0x14b373815650, row_items=row_items@entry=0x14b373877658) at /test/10.5_dbg/sql/protocol.cc:1082
#31 0x00005597fc382252 in select_send::send_data (this=0x14b373877278, items=@0x14b373877658: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14b373977cb0, last = 0x14b373977cb0, elements = 1}, <No data fields>}) at /test/10.5_dbg/sql/sql_class.cc:3004
#32 0x00005597fc43a72c in select_result_sink::send_data_with_check (sent=<optimized out>, u=<optimized out>, items=@0x14b373877658: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14b373977cb0, last = 0x14b373977cb0, elements = 1}, <No data fields>}, this=<optimized out>) at /test/10.5_dbg/sql/sql_class.h:5287
#33 end_send_group (join=0x14b3738772a0, join_tab=<optimized out>, end_of_records=<optimized out>) at /test/10.5_dbg/sql/sql_select.cc:21942
#34 0x00005597fc426065 in sub_select (join=join@entry=0x14b3738772a0, join_tab=join_tab@entry=0x14b373879508, end_of_records=end_of_records@entry=true) at /test/10.5_dbg/sql/sql_select.cc:20545
#35 0x00005597fc43e2c4 in sub_select_postjoin_aggr (join=0x14b3738772a0, join_tab=0x14b373879508, end_of_records=<optimized out>) at /test/10.5_dbg/sql/sql_select.cc:20312
#36 0x00005597fc426065 in sub_select (join=0x14b3738772a0, join_tab=0x14b373879160, end_of_records=<optimized out>) at /test/10.5_dbg/sql/sql_select.cc:20545
#37 0x00005597fc45f402 in do_select (procedure=<optimized out>, join=0x14b3738772a0) at /test/10.5_dbg/sql/sql_select.cc:20136
#38 JOIN::exec_inner (this=this@entry=0x14b3738772a0) at /test/10.5_dbg/sql/sql_select.cc:4444
#39 0x00005597fc45f76b in JOIN::exec (this=this@entry=0x14b3738772a0) at /test/10.5_dbg/sql/sql_select.cc:4225
#40 0x00005597fc45da80 in mysql_select (thd=thd@entry=0x14b373815088, tables=<optimized out>, fields=@0x14b373874318: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14b373876178, last = 0x14b373876178, elements = 1}, <No data fields>}, conds=0x0, og_num=0, order=<optimized out>, group=0x0, having=0x0, proc_param=0x0, select_options=2147879680, result=0x14b373877278, unit=0x14b3738190a0, select_lex=0x14b3738741c8) at /test/10.5_dbg/sql/sql_select.cc:4649
#41 0x00005597fc45ddaf in handle_select (thd=thd@entry=0x14b373815088, lex=lex@entry=0x14b373818fd8, result=result@entry=0x14b373877278, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.5_dbg/sql/sql_select.cc:417
#42 0x00005597fc3e76c9 in execute_sqlcom_select (thd=thd@entry=0x14b373815088, all_tables=0x14b373876218) at /test/10.5_dbg/sql/sql_parse.cc:6211
#43 0x00005597fc3e07c2 in mysql_execute_command (thd=thd@entry=0x14b373815088) at /test/10.5_dbg/sql/sql_parse.cc:3939
#44 0x00005597fc3ed638 in mysql_parse (thd=thd@entry=0x14b373815088, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x14b397aaf350, 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:7995
#45 0x00005597fc3da110 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x14b373815088, packet=packet@entry=0x14b373867089 "", packet_length=packet_length@entry=96, 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
#46 0x00005597fc3d88ea in do_command (thd=0x14b373815088) at /test/10.5_dbg/sql/sql_parse.cc:1355
#47 0x00005597fc53415f in do_handle_one_connection (connect=<optimized out>, connect@entry=0x14b3768d2808, put_in_cache=put_in_cache@entry=true) at /test/10.5_dbg/sql/sql_connect.cc:1411
#48 0x00005597fc53487b in handle_one_connection (arg=arg@entry=0x14b3768d2808) at /test/10.5_dbg/sql/sql_connect.cc:1313
#49 0x00005597fc99711c in pfs_spawn_thread (arg=0x14b394846508) at /test/10.5_dbg/storage/perfschema/pfs.cc:2201
#50 0x000014b396a296db in start_thread (arg=0x14b397ab0700) at pthread_create.c:463
#51 0x000014b395e27a3f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.2.33 (dbg), 10.2.33 (opt), 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)
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-14 ]

Interestingly, that last testcase seems fixed in latest 10.5.5, perhaps as part of MDEV-22852?

10.5.5 30e7a0a866dce530d8328c6d614e48d39a264f9b (opt+dbg)

10.5.5>SELECT (SELECT 1 FROM t AS t_inner GROUP BY t_inner.a ORDER BY MAX(t_outer.a)) FROM t AS t_outer;
+-------------------------------------------------------------------------+
| (SELECT 1 FROM t AS t_inner GROUP BY t_inner.a ORDER BY MAX(t_outer.a)) |
+-------------------------------------------------------------------------+
|                                                                    NULL |
+-------------------------------------------------------------------------+
1 row in set (0.008 sec)

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

Original testcase still crashes latest 10.5.5 (optimized+debug)

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 0x14d66bab7700 (LWP 1255655))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=11) at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
#1  0x00005632ce06bbd7 in my_write_core (sig=sig@entry=11) at /test/10.5_opt/mysys/stacktrace.c:518
#2  0x00005632cda3601a in handle_fatal_signal (sig=11) at /test/10.5_opt/sql/signal_handler.cc:330
#3  <signal handler called>
#4  0x00005632cda3368c in sortlength (allow_packing_for_sortkeys=<synthetic pointer>, sort_keys=0x14d6478d2da0, thd=0x14d647812018) at /test/10.5_opt/sql/filesort.cc:2237
#5  filesort (thd=thd@entry=0x14d647812018, table=table@entry=0x14d64794dc30, filesort=filesort@entry=0x14d6478d20c8, tracker=0x14d6478d2350, join=join@entry=0x14d647849bb8, first_table_bit=<optimized out>) at /test/10.5_opt/sql/filesort.cc:250
#6  0x00005632cd889e55 in create_sort_index (thd=thd@entry=0x14d647812018, join=join@entry=0x14d647849bb8, tab=tab@entry=0x14d64784c858, fsort=0x14d6478d20c8) at /test/10.5_opt/sql/sql_select.cc:23875
#7  0x00005632cd9a7187 in Window_funcs_sort::exec (this=0x14d6478d1fc8, join=join@entry=0x14d647849bb8, keep_filesort_result=keep_filesort_result@entry=false) at /test/10.5_opt/sql/sql_window.cc:2998
#8  0x00005632cd9a7a7a in Window_funcs_computation::exec (this=<optimized out>, join=join@entry=0x14d647849bb8, keep_last_filesort_result=<optimized out>) at /test/10.5_opt/sql/sql_window.cc:3131
#9  0x00005632cd895ce3 in AGGR_OP::end_send (this=0x14d64784cfd8) at /test/10.5_opt/sql/sql_select.cc:28896
#10 0x00005632cd895ece in sub_select_postjoin_aggr (join=0x14d647849bb8, join_tab=0x14d64784c858, end_of_records=<optimized out>) at /test/10.5_opt/sql/sql_select.cc:20351
#11 0x00005632cd89d89d in do_select (procedure=<optimized out>, join=0x14d647849bb8) at /test/10.5_opt/sql/sql_select.cc:20177
#12 JOIN::exec_inner (this=this@entry=0x14d647849bb8) at /test/10.5_opt/sql/sql_select.cc:4450
#13 0x00005632cd89dca7 in JOIN::exec (this=this@entry=0x14d647849bb8) at /test/10.5_opt/sql/sql_select.cc:4231
#14 0x00005632cd89bfd2 in mysql_select (thd=thd@entry=0x14d647812018, tables=0x14d647847e08, fields=@0x14d6478472b0: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14d647847718, last = 0x14d647847d98, elements = 2}, <No data fields>}, conds=0x14d647848eb0, og_num=<optimized out>, order=0x0, group=0x14d647849240, having=0x0, proc_param=0x0, select_options=2147748608, result=0x14d647849b90, unit=0x14d647815e70, select_lex=0x14d647847160) at /test/10.5_opt/sql/sql_select.cc:4655
#15 0x00005632cd89c991 in handle_select (thd=thd@entry=0x14d647812018, lex=lex@entry=0x14d647815da8, result=result@entry=0x14d647849b90, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.5_opt/sql/sql_select.cc:417
#16 0x00005632cd843351 in execute_sqlcom_select (thd=thd@entry=0x14d647812018, all_tables=0x14d647847e08) at /test/10.5_opt/sql/sql_parse.cc:6209
#17 0x00005632cd83fa21 in mysql_execute_command (thd=thd@entry=0x14d647812018) at /test/10.5_opt/sql/sql_parse.cc:3931
#18 0x00005632cd84646c in mysql_parse (thd=0x14d647812018, rawbuf=<optimized out>, length=98, parser_state=0x14d66bab6430, is_com_multi=<optimized out>, is_next_command=<optimized out>) at /test/10.5_opt/sql/sql_parse.cc:7993
#19 0x00005632cd83b755 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x14d647812018, packet=packet@entry=0x14d64783a019 "", packet_length=packet_length@entry=98, 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
#20 0x00005632cd839a94 in do_command (thd=0x14d647812018) at /test/10.5_opt/sql/sql_parse.cc:1347
#21 0x00005632cd92f191 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x14d6688338f8, put_in_cache=put_in_cache@entry=true) at /test/10.5_opt/sql/sql_connect.cc:1411
#22 0x00005632cd92f4f4 in handle_one_connection (arg=arg@entry=0x14d6688338f8) at /test/10.5_opt/sql/sql_connect.cc:1313
#23 0x00005632cdc9fdea in pfs_spawn_thread (arg=0x14d66884f218) at /test/10.5_opt/storage/perfschema/pfs.cc:2201
#24 0x000014d66aa306db in start_thread (arg=0x14d66bab7700) at pthread_create.c:463
#25 0x000014d669e2ea3f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Debug:

10.5.5 30e7a0a866dce530d8328c6d614e48d39a264f9b (Debug)

mysqld: /test/10.5_dbg/sql/filesort.cc:604: Sort_keys* Filesort::make_sortorder(THD*, JOIN*, table_map): Assertion `pos->field != __null || pos->item != __null' failed.

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 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 0x145db7bd4700 (LWP 1255802))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
#1  0x000055fa8020c4d7 in my_write_core (sig=sig@entry=6) at /test/10.5_dbg/mysys/stacktrace.c:518
#2  0x000055fa7f9c69ba 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  0x0000145db5e6a8b1 in __GI_abort () at abort.c:79
#6  0x0000145db5e5a42a in __assert_fail_base (fmt=0x145db5fe1a38 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x55fa8051bcd0 "pos->field != __null || pos->item != __null", file=file@entry=0x55fa8051bab0 "/test/10.5_dbg/sql/filesort.cc", line=line@entry=604, function=function@entry=0x55fa8051c960 <Filesort::make_sortorder(THD*, JOIN*, unsigned long long)::__PRETTY_FUNCTION__> "Sort_keys* Filesort::make_sortorder(THD*, JOIN*, table_map)") at assert.c:92
#7  0x0000145db5e5a4a2 in __GI___assert_fail (assertion=assertion@entry=0x55fa8051bcd0 "pos->field != __null || pos->item != __null", file=file@entry=0x55fa8051bab0 "/test/10.5_dbg/sql/filesort.cc", line=line@entry=604, function=function@entry=0x55fa8051c960 <Filesort::make_sortorder(THD*, JOIN*, unsigned long long)::__PRETTY_FUNCTION__> "Sort_keys* Filesort::make_sortorder(THD*, JOIN*, table_map)") at assert.c:101
#8  0x000055fa7f9bed2d in Filesort::make_sortorder (this=this@entry=0x145d9397b698, thd=thd@entry=0x145d93815088, join=join@entry=0x145d93876c40, first_table_bit=first_table_bit@entry=1) at /test/10.5_dbg/sql/filesort.cc:604
#9  0x000055fa7f9c2cd7 in filesort (thd=thd@entry=0x145d93815088, table=table@entry=0x145d9396e0a0, filesort=filesort@entry=0x145d9397b698, tracker=0x145d9397b928, join=join@entry=0x145d93876c40, first_table_bit=1) at /test/10.5_dbg/sql/filesort.cc:211
#10 0x000055fa7f7715a8 in create_sort_index (thd=thd@entry=0x145d93815088, join=join@entry=0x145d93876c40, tab=tab@entry=0x145d938798e0, fsort=0x145d9397b698) at /test/10.5_dbg/sql/sql_select.cc:23875
#11 0x000055fa7f912c86 in Window_funcs_sort::exec (this=0x145d9397b590, join=join@entry=0x145d93876c40, keep_filesort_result=<optimized out>) at /test/10.5_dbg/sql/sql_window.cc:2998
#12 0x000055fa7f9133a7 in Window_funcs_computation::exec (this=0x145d9397b570, join=join@entry=0x145d93876c40, keep_last_filesort_result=keep_last_filesort_result@entry=false) at /test/10.5_dbg/sql/sql_window.cc:3131
#13 0x000055fa7f778d2c in AGGR_OP::end_send (this=this@entry=0x145d9387a060) at /test/10.5_dbg/sql/sql_select.cc:28896
#14 0x000055fa7f7791c8 in sub_select_postjoin_aggr (join=0x145d93876c40, join_tab=0x145d938798e0, end_of_records=<optimized out>) at /test/10.5_dbg/sql/sql_select.cc:20351
#15 0x000055fa7f75ffef in sub_select (join=join@entry=0x145d93876c40, join_tab=join_tab@entry=0x145d93879538, end_of_records=end_of_records@entry=true) at /test/10.5_dbg/sql/sql_select.cc:20586
#16 0x000055fa7f7605e0 in sub_select_cache (join=0x145d93876c40, join_tab=0x145d93879538, end_of_records=<optimized out>) at /test/10.5_dbg/sql/sql_select.cc:20418
#17 0x000055fa7f75ffef in sub_select (join=0x145d93876c40, join_tab=0x145d93879190, end_of_records=<optimized out>) at /test/10.5_dbg/sql/sql_select.cc:20586
#18 0x000055fa7f79a594 in do_select (procedure=<optimized out>, join=0x145d93876c40) at /test/10.5_dbg/sql/sql_select.cc:20177
#19 JOIN::exec_inner (this=this@entry=0x145d93876c40) at /test/10.5_dbg/sql/sql_select.cc:4450
#20 0x000055fa7f79a8fd in JOIN::exec (this=this@entry=0x145d93876c40) at /test/10.5_dbg/sql/sql_select.cc:4231
#21 0x000055fa7f798bf9 in mysql_select (thd=thd@entry=0x145d93815088, tables=<optimized out>, fields=@0x145d93874320: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x145d93874788, last = 0x145d93874e20, elements = 2}, <No data fields>}, conds=0x145d93875f38, og_num=1, order=<optimized out>, group=0x145d938762c8, having=0x0, proc_param=0x0, select_options=2147748608, result=0x145d93876c18, unit=0x145d938190a0, select_lex=0x145d938741d0) at /test/10.5_dbg/sql/sql_select.cc:4655
#22 0x000055fa7f798f28 in handle_select (thd=thd@entry=0x145d93815088, lex=lex@entry=0x145d93818fd8, result=result@entry=0x145d93876c18, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.5_dbg/sql/sql_select.cc:417
#23 0x000055fa7f7217e2 in execute_sqlcom_select (thd=thd@entry=0x145d93815088, all_tables=0x145d93874e90) at /test/10.5_dbg/sql/sql_parse.cc:6209
#24 0x000055fa7f71a8b6 in mysql_execute_command (thd=thd@entry=0x145d93815088) at /test/10.5_dbg/sql/sql_parse.cc:3931
#25 0x000055fa7f727752 in mysql_parse (thd=thd@entry=0x145d93815088, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x145db7bd3350, 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
#26 0x000055fa7f714204 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x145d93815088, packet=packet@entry=0x145d93867089 "", packet_length=packet_length@entry=98, 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
#27 0x000055fa7f7129de in do_command (thd=0x145d93815088) at /test/10.5_dbg/sql/sql_parse.cc:1347
#28 0x000055fa7f86ec3b in do_handle_one_connection (connect=<optimized out>, connect@entry=0x145d96cc7808, put_in_cache=put_in_cache@entry=true) at /test/10.5_dbg/sql/sql_connect.cc:1411
#29 0x000055fa7f86f357 in handle_one_connection (arg=arg@entry=0x145d96cc7808) at /test/10.5_dbg/sql/sql_connect.cc:1313
#30 0x000055fa7fcd2ca8 in pfs_spawn_thread (arg=0x145db4846508) at /test/10.5_dbg/storage/perfschema/pfs.cc:2201
#31 0x0000145db6b4d6db in start_thread (arg=0x145db7bd4700) at pthread_create.c:463
#32 0x0000145db5f4ba3f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

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

Unique bug ID's so far

SIGSEGV|sortlength|filesort|create_sort_index|Window_funcs_sort::exec  # Original testcase, optimized, 10.5.5 at 30e7a0a866dce530d8328c6d614e48d39a264f9b
SIGSEGV|sortlength|filesort|create_sort_index|st_join_table::sort_table  # Second testcase above, optimized 10.5.5 at e1013725ce0f3f947e728491eef75d9985e8db2f
SIGSEGV|sortlength|filesort|create_sort_index|st_join_table::sort_table  # MDEV-22852 testcase, optimized, 10.5.5 at e1013725ce0f3f947e728491eef75d9985e8db2f
pos->field != __null || pos->item != __null|SIGABRT|Filesort::make_sortorder|filesort|create_sort_index|Window_funcs_sort::exec  # Original testcase, debug, 10.5.5 at 30e7a0a866dce530d8328c6d614e48d39a264f9b
pos->field != __null || pos->item != __null|SIGABRT|Filesort::make_sortorder|filesort|create_sort_index|st_join_table::sort_table  # Second testcase above, debug 10.5.5 at e1013725ce0f3f947e728491eef75d9985e8db2f
pos->field != __null || pos->item != __null|SIGABRT|Filesort::make_sortorder|filesort|create_sort_index|st_join_table::sort_table  # MDEV-22852 testcase, debug, 10.5.5 at e1013725ce0f3f947e728491eef75d9985e8db2f

Based on all findings, it would seem that the second testcase would have fitted better with MDEV-22852, is now resolved, but that the original issue, for which a patch was created also, but not pushed yet, still exists.

Comment by Sergei Petrunia [ 2023-01-20 ]

SELECT  
  a, 
  RANK() OVER (ORDER BY SUM(DISTINCT i1))
FROM 
  t1, t2 WHERE t2.i2 = t1.i1 
GROUP BY a;

This query can only be executed as follows:

  join t1, t2 
  put into temp.table
  sort by the GROUP BY criteria
  read the sorted file 
    compute SUM(DISTINCT) //   this can only use one-group-after-another algorithm due to DISTINCT
    write output into temptable #2. 
 
  window function processing starts;
  sort by window-func-criteria-1;   //  WE CRASH HERE
  read the output and compute window function;

The crash happens, because the sorting code can't see where it can find the value of SUM(DISTINCT i1).

Comment by Sergei Petrunia [ 2023-01-20 ]

Note that EXPLAIN doesn't show the "sort by the GROUP BY criteria" step:
(EDIT: incorrect, it does show it but in the wrong place)

{
  "query_block": {
    "select_id": 1,
    "filesort": {
      "sort_key": "t1.a",
      "window_functions_computation": {
        "sorts": {
          "filesort": {
            "sort_key": "sum(distinct t1.i1)"
          }
        },
        "temporary_table": {
          "table": {
            "table_name": "t1",
            "access_type": "ALL",
            "rows": 3,
            "filtered": 100
          },
          "block-nl-join": {
            "table": {
              "table_name": "t2",
              "access_type": "ALL",
              "rows": 7,
              "filtered": 100
            },
            "buffer_type": "flat",
            "buffer_size": "256Kb",
            "join_type": "BNL",
            "attached_condition": "t2.i2 = t1.i1"
          }
        }
      }
    }
  }
}

Comment by Sergei Petrunia [ 2023-01-20 ]

If I modify the query slightly, it doesn't crash. But in debugger I observe that window function computation is done before GROUP BY operation is done!

explain format=json
SELECT  
  a, 
  COUNT(DISTINCT i1),
  RANK() OVER (ORDER BY a)
FROM 
  t1, t2 WHERE t2.i2 = t1.i1 
GROUP BY 
  a;

The result is incorrect:

+------+--------------------+--------------------------+
| a    | COUNT(DISTINCT i1) | RANK() OVER (ORDER BY a) |
+------+--------------------+--------------------------+
|    1 |                  1 |                        3 |
|    2 |                  1 |                        4 |
|    3 |                  1 |                        4 |
+------+--------------------+--------------------------+

RANK() should be 1, 2, 3...

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