[MDEV-30039] Crash when using count (distinct) combined with rank() Created: 2022-11-18  Updated: 2022-11-21  Resolved: 2022-11-21

Status: Closed
Project: MariaDB Server
Component/s: Optimizer - Window functions
Affects Version/s: 10.6.7
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: Christopher Zissis Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Environment:

Ubuntu 22.04.1 LTS


Attachments: File create-query.sql    
Issue Links:
Duplicate
duplicates MDEV-15178 Filesort::make_sortorder: Assertion `... Closed

 Description   

MariaDB service crashes when using Count() on distinct values in a column when also using Rank(). The specific query causing issues is:

{{select d.department_name , d.department_id , count (DISTINCT employee_id) as employees,
sum(salary) as total_salary,
RANK() over (order by sum(salary) DESC) as rank_sal
from employees e left join departments d
on e.department_id = d.department_id
group by d.department_name , d.department_id
LIMIT 0, 200}}

The error message is as follows:

{{[ERROR] mysqld got signal 11 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
To report this bug, see https://mariadb.com/kb/en/reporting-bugs
We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed,
something is definitely wrong and this may fail.
Server version: 10.6.7-MariaDB-2ubuntu1.1
key_buffer_size=20971520
read_buffer_size=131072
max_used_connections=1
max_threads=153
thread_count=1
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 357365 K bytes of memory
Hope that's ok; if not, decrease some variables in the equation.
Thread pointer: 0x7f75c0000c68
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0x7f7601cf4c78 thread_stack 0x49000
??:0(my_print_stacktrace)[0x562d3da11702]
??:0(handle_fatal_signal)[0x562d3d54c4d8]
??:0(__sigaction)[0x7f7612542520]
??:0(filesort(THD*, TABLE*, Filesort*, Filesort_tracker*, JOIN*, unsigned long long))[0x562d3d549b09]
??:0(create_sort_index(THD*, JOIN*, st_join_table*, Filesort*))[0x562d3d381562]
??:0(Window_funcs_sort::exec(JOIN*, bool))[0x562d3d4c1393]
??:0(Window_funcs_computation::exec(JOIN*, bool))[0x562d3d4c1d7b]
??:0(AGGR_OP::end_send())[0x562d3d38ea2e]
??:0(sub_select_postjoin_aggr(JOIN*, st_join_table*, bool))[0x562d3d38ed70]
??:0(JOIN::exec_inner())[0x562d3d398616]
??:0(JOIN::exec())[0x562d3d398b69]
??:0(mysql_select(THD*, TABLE_LIST*, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_ord>
??:0(handle_select(THD*, LEX*, select_result*, unsigned long))[0x562d3d3971a7]
??:0(comp_ne_creator(bool))[0x562d3d326d9c]
??:0(mysql_execute_command(THD*, bool))[0x562d3d333754]
??:0(mysql_parse(THD*, char*, unsigned int, Parser_state*))[0x562d3d334ba8]
??:0(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool))[0x562d3d336815]
??:0(do_command(THD*, bool))[0x562d3d3381b7]
??:0(do_handle_one_connection(CONNECT*, bool))[0x562d3d437e5f]
??:0(handle_one_connection)[0x562d3d4381dd]
??:0(MyCTX_nopad::finish(unsigned char*, unsigned int*))[0x562d3d776386]
??:0(pthread_condattr_setpshared)[0x7f7612594b43]
??:0(__xmknodat)[0x7f7612626a00]
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (0x7f75c0012560): select d.department_name , d.department_id , count (distinct employee_id) as emplo>
sum(salary) as total_salary,
rank() over (order by sum(salary) DESC) as rank_sal
from employees e left join departments d
on e.department_id = d.department_id
group by d.department_name , d.department_id
LIMIT 0, 200
Connection ID (thread ID): 5
Status: NOT_KILLED}}

If we remove the DISTINCT or the RANK() function, the query runs successfully. Additionally, modifying the left join to be an inner join also allows the query to run.

I have also tested this on a brand new MariaDB 10.10.2 install on a Docker Debian container with the same failure.

I have attached the sample data we are running this query against.



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

Thanks for the report!
I repeated as described on current 10.3-10.11, this is the same bug as MDEV-15178

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