[MDEV-31241] Crashes in subselects in choose_best_splitting after upgrade to 10.6.13 Created: 2023-05-11  Updated: 2023-12-18  Resolved: 2023-05-12

Status: Closed
Project: MariaDB Server
Component/s: Optimizer, Server
Affects Version/s: 10.6.13
Fix Version/s: N/A

Type: Bug Priority: Critical
Reporter: Markus Peter Assignee: Igor Babaev
Resolution: Duplicate Votes: 1
Labels: None
Environment:

Linux nbs 5.10.0-21-amd64 #1 SMP Debian 5.10.162-1 (2023-01-21) x86_64 GNU/Linux


Attachments: PNG File Screenshot 2023-05-11 at 14.47.27.png     Text File backtrace.txt    
Issue Links:
Duplicate
is duplicated by MDEV-31240 Crash with condition pushable into de... Closed
is duplicated by MDEV-31295 Program terminated with signal SIGSEG... Closed
Problem/Incident
is caused by MDEV-26301 Split optimization refills temporary ... Closed
Relates
relates to MDEV-31403 Server crashes in st_join_table::choo... Closed

 Description   

Since upgrading from 10.6.9 to 10.6.13 we had repeated crashes causes by queries with subselects:

230511 7:00:14 [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.13-MariaDB-1:10.6.13+maria~deb11-log source revision: a24f2bb50ba4a0dd4127455f7fcdfed584937f36
key_buffer_size=16777216
read_buffer_size=16777216
max_used_connections=141
max_threads=1002
thread_count=66
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 24667679 K bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x7f120c0008e8
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 = 0x7f17142fad18 thread_stack 0x30000
/usr/sbin/mariadbd(my_print_stacktrace+0x2e)[0x5597a009c75e]
/usr/sbin/mariadbd(handle_fatal_signal+0x485)[0x55979fb654b5]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13140)[0x7f1764d21140]
/usr/sbin/mariadbd(_ZN13st_join_table21choose_best_splittingEjyPy+0x569)[0x55979fae4dd9]
/usr/sbin/mariadbd(Z16best_access_pathP4JOINP13st_join_tableyPK8POSITIONjbdPS3_S6+0x148)[0x55979f966988]
/usr/sbin/mariadbd(+0x7f571f)[0x55979f96a71f]
/usr/sbin/mariadbd(_Z11choose_planP4JOINy+0x2a4)[0x55979f96b534]
/usr/sbin/mariadbd(+0x8207b1)[0x55979f9957b1]
/usr/sbin/mariadbd(_ZN4JOIN14optimize_innerEv+0x12ec)[0x55979f99a49c]
/usr/sbin/mariadbd(_ZN4JOIN8optimizeEv+0xa0)[0x55979f99aab0]
/usr/sbin/mariadbd(_ZN13st_select_lex31optimize_unflattened_subqueriesEb+0x10d)[0x55979f90773d]
/usr/sbin/mariadbd(_ZN4JOIN15optimize_stage2Ev+0x3a)[0x55979f9961da]
/usr/sbin/mariadbd(_ZN4JOIN14optimize_innerEv+0x13fc)[0x55979f99a5ac]
/usr/sbin/mariadbd(_ZN4JOIN8optimizeEv+0xa0)[0x55979f99aab0]
/usr/sbin/mariadbd(_Z12mysql_selectP3THDP10TABLE_LISTR4ListI4ItemEPS4_jP8st_orderS9_S7_S9_yP13select_resultP18st_select_lex_unitP13st_select_lex+0xb3)[0x55979f99ab83]
/usr/sbin/mariadbd(_Z13handle_selectP3THDP3LEXP13select_resultm+0x14f)[0x55979f99b38f]
/usr/sbin/mariadbd(+0x7ac0f1)[0x55979f9210f1]
/usr/sbin/mariadbd(_Z21mysql_execute_commandP3THDb+0x4607)[0x55979f930267]
/usr/sbin/mariadbd(_Z11mysql_parseP3THDPcjP12Parser_state+0x1e7)[0x55979f931857]
/usr/sbin/mariadbd(_Z16dispatch_command19enum_server_commandP3THDPcjb+0x156d)[0x55979f93405d]
/usr/sbin/mariadbd(_Z10do_commandP3THDb+0x138)[0x55979f935bf8]
/usr/sbin/mariadbd(_Z24do_handle_one_connectionP7CONNECTb+0x3af)[0x55979fa4470f]
/usr/sbin/mariadbd(handle_one_connection+0x5d)[0x55979fa44a5d]
/usr/sbin/mariadbd(+0xc3c4c2)[0x55979fdb14c2]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x7ea7)[0x7f1764d15ea7]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7f176491ca2f]

Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (0x7f120c007c80): SELECT * FROM (SELECT CONCAT(Nachname, ', ', Vorname) AS Name , CONCAT(RIGHT(mo.month, 2), ', ', LEFT(mo.month, 4)) AS Monat , Bildungsgutscheinnummer AS Maßnahmennummer , CONCAT(DATE_FORMAT(Vertrag_Beginn,'%d.%m.%Y'), ' - ', DATE_FORMAT(Vertrag_Ende, '%d.%m.%Y')) AS Maßnahmenzeitraum , (
SELECT
SUM(Anzahl)
FROM
view_Schüler_Fehlzeit_Monat_Tag vst
WHERE
s.Id = vst.Schüler_Id AND
vst.jahr_monat BETWEEN date_format(Vertrag_Beginn, '%Y-%m') AND mo.month
) AS 'Fehltage_gesamt' , f.eins , f.zwei , f.drei , f.vier , f.fünf , f.sechs , f.sieben , f.acht , f.neun , f.zehn , f.elf , f.zwölf , f.dreizehn , f.vierzehn , f.fünfzehn , f.sechzehn , f.siebzehn , f.achtzehn , f.neunzehn , f.zwanzig , f.einundzwanzig , f.zweiundzwanzig , f.dreiundzwanzig , f.vierundzwanzig , f.fünfundzwanzig , f.sechsundzwanzig , f.siebenundzwanzig , f.achtundzwanzig , f.neunundzwanzig , f.dreißig , f.einunddreißig FROM Akademie_Schüler s JOIN const.month mo ON mo.month BETWEEN date_format(Vertrag_Beginn, '%Y-%m') AND
date_format(ifnull(Vertrag_Ende, CURRENT_DATE), '%Y-%m') LEFT JOIN view_Schüler_Fehlzeit_Monat_Tag f ON f.Schüler_Id = s.Id AND mo.month = jahr_monat WHERE 1=0 ) AS _dummy_table WHERE 1=0 LIMIT 0

Connection ID (thread ID): 30006
Status: NOT_KILLED

Optimizer switch: index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on,condition_pushdown_from_having=on,not_null_range_scan=off,hash_join_cardinality=off

----------

230511 7:30:13 [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.13-MariaDB-1:10.6.13+maria~deb11-log source revision: a24f2bb50ba4a0dd4127455f7fcdfed584937f36
key_buffer_size=16777216
read_buffer_size=16777216
max_used_connections=144
max_threads=1002
thread_count=105
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 24667679 K bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x7f0ffc0008e8
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 = 0x7f1684242d18 thread_stack 0x30000
/usr/sbin/mariadbd(my_print_stacktrace+0x2e)[0x55f596e4c75e]
/usr/sbin/mariadbd(handle_fatal_signal+0x485)[0x55f5969154b5]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13140)[0x7f16c69f0140]
/usr/sbin/mariadbd(_ZN13st_join_table21choose_best_splittingEjyPy+0x569)[0x55f596894dd9]
/usr/sbin/mariadbd(Z16best_access_pathP4JOINP13st_join_tableyPK8POSITIONjbdPS3_S6+0x148)[0x55f596716988]
/usr/sbin/mariadbd(+0x7f571f)[0x55f59671a71f]
/usr/sbin/mariadbd(_Z11choose_planP4JOINy+0x2a4)[0x55f59671b534]
/usr/sbin/mariadbd(+0x8207b1)[0x55f5967457b1]
/usr/sbin/mariadbd(_ZN4JOIN14optimize_innerEv+0x12ec)[0x55f59674a49c]
/usr/sbin/mariadbd(_ZN4JOIN8optimizeEv+0xa0)[0x55f59674aab0]
/usr/sbin/mariadbd(_ZN13st_select_lex31optimize_unflattened_subqueriesEb+0x10d)[0x55f5966b773d]
/usr/sbin/mariadbd(_ZN4JOIN15optimize_stage2Ev+0x3a)[0x55f5967461da]
/usr/sbin/mariadbd(_ZN4JOIN14optimize_innerEv+0x13fc)[0x55f59674a5ac]
/usr/sbin/mariadbd(_ZN4JOIN8optimizeEv+0xa0)[0x55f59674aab0]
/usr/sbin/mariadbd(_Z12mysql_selectP3THDP10TABLE_LISTR4ListI4ItemEPS4_jP8st_orderS9_S7_S9_yP13select_resultP18st_select_lex_unitP13st_select_lex+0xb3)[0x55f59674ab83]
/usr/sbin/mariadbd(_Z13handle_selectP3THDP3LEXP13select_resultm+0x14f)[0x55f59674b38f]
/usr/sbin/mariadbd(+0x7ac0f1)[0x55f5966d10f1]
/usr/sbin/mariadbd(_Z21mysql_execute_commandP3THDb+0x4607)[0x55f5966e0267]
/usr/sbin/mariadbd(_Z11mysql_parseP3THDPcjP12Parser_state+0x1e7)[0x55f5966e1857]
/usr/sbin/mariadbd(_Z16dispatch_command19enum_server_commandP3THDPcjb+0x156d)[0x55f5966e405d]
/usr/sbin/mariadbd(_Z10do_commandP3THDb+0x138)[0x55f5966e5bf8]
/usr/sbin/mariadbd(_Z24do_handle_one_connectionP7CONNECTb+0x3af)[0x55f5967f470f]
/usr/sbin/mariadbd(handle_one_connection+0x5d)[0x55f5967f4a5d]
/usr/sbin/mariadbd(+0xc3c4c2)[0x55f596b614c2]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x7ea7)[0x7f16c69e4ea7]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7f16c65eba2f]

Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (0x7f0ffc0109e0): SELECT * FROM (SELECT CONCAT(Nachname, ', ', Vorname) AS Name , CONCAT(RIGHT(mo.month, 2), ', ', LEFT(mo.month, 4)) AS Monat , Bildungsgutscheinnummer AS Maßnahmennummer , CONCAT(DATE_FORMAT(Vertrag_Beginn,'%d.%m.%Y'), ' - ', DATE_FORMAT(Vertrag_Ende, '%d.%m.%Y')) AS Maßnahmenzeitraum , (
SELECT
SUM(Anzahl)
FROM
view_Schüler_Fehlzeit_Monat_Tag vst
WHERE
s.Id = vst.Schüler_Id AND
vst.jahr_monat BETWEEN date_format(Vertrag_Beginn, '%Y-%m') AND mo.month
) AS 'Fehltage_gesamt' , f.eins , f.zwei , f.drei , f.vier , f.fünf , f.sechs , f.sieben , f.acht , f.neun , f.zehn , f.elf , f.zwölf , f.dreizehn , f.vierzehn , f.fünfzehn , f.sechzehn , f.siebzehn , f.achtzehn , f.neunzehn , f.zwanzig , f.einundzwanzig , f.zweiundzwanzig , f.dreiundzwanzig , f.vierundzwanzig , f.fünfundzwanzig , f.sechsundzwanzig , f.siebenundzwanzig , f.achtundzwanzig , f.neunundzwanzig , f.dreißig , f.einunddreißig FROM Akademie_Schüler s JOIN const.month mo ON mo.month BETWEEN date_format(Vertrag_Beginn, '%Y-%m') AND
date_format(ifnull(Vertrag_Ende, CURRENT_DATE), '%Y-%m') LEFT JOIN view_Schüler_Fehlzeit_Monat_Tag f ON f.Schüler_Id = s.Id AND mo.month = jahr_monat WHERE 1=0 ) AS _dummy_table WHERE 1=0 LIMIT 0

Connection ID (thread ID): 3754
Status: NOT_KILLED

Optimizer switch: index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on,condition_pushdown_from_having=on,not_null_range_scan=off,hash_join_cardinality=off
------

Please ignore there where 1=0 and LIMIT 0 stuff - this is something our software does to analyze the possible return values of a query before executing it for real. The crash will reliably also happen on the exact same query if that is left out.

After further testing: 10.6.12 did not have the crash - it is new for 10.6.13

I retried on 10.6.13 with debug symbols on a test system:

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 = 0x7f1dac3c9d18 thread_stack 0x30000
mysys/stacktrace.c:216(my_print_stacktrace)[0x5605cee2b75e]
sql/signal_handler.cc:241(handle_fatal_signal)[0x5605ce8f44b5]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13140)[0x7f1dfda59140]
sql/opt_split.cc:1047(st_join_table::choose_best_splitting(unsigned int, unsigned long long, unsigned long long*))[0x5605ce873dd9]
sql/sql_select.cc:7898(best_access_path(JOIN*, st_join_table*, unsigned long long, POSITION const*, unsigned int, bool, double, POSITION*, POSITION*))[0x5605ce6f5988]
sql/sql_select.cc:10338(best_extension_by_limited_search(JOIN*, unsigned long long, unsigned int, double, double, unsigned int, unsigned int, unsigned int))[0x5605ce6f971f]
sql/sql_select.cc:9471(choose_plan(JOIN*, unsigned long long))[0x5605ce6fa534]
sql/sql_select.cc:5963(make_join_statistics(JOIN*, List<TABLE_LIST>&, st_dynamic_array*))[0x5605ce7247b1]
sql/sql_select.cc:2510(JOIN::optimize_inner())[0x5605ce72949c]
sql/sql_select.cc:1850(JOIN::optimize())[0x5605ce729ab0]
sql/sql_lex.cc:4925(st_select_lex::optimize_unflattened_subqueries(bool))[0x5605ce69673d]
sql/sql_select.cc:3334(JOIN::optimize_stage2())[0x5605ce7251da]
sql/sql_select.cc:2535(JOIN::optimize_inner())[0x5605ce7295ac]
sql/sql_select.cc:1850(JOIN::optimize())[0x5605ce729ab0]
sql/sql_select.cc:5055(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*))[0x5605ce729b83]
sql/sql_select.cc:559(handle_select(THD*, LEX*, select_result*, unsigned long))[0x5605ce72a38f]
sql/sql_parse.cc:6273(execute_sqlcom_select(THD*, TABLE_LIST*))[0x5605ce6b00f1]
sql/sql_parse.cc:3949(mysql_execute_command(THD*, bool))[0x5605ce6bf267]
sql/sql_class.h:2806(THD::enter_stage(PSI_stage_info_v1 const*, char const*, char const*, unsigned int))[0x5605ce6c0857]
sql/sql_parse.cc:1898(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool))[0x5605ce6c305d]
sql/sql_parse.cc:1411(do_command(THD*, bool))[0x5605ce6c4bf8]
sql/sql_connect.cc:1416(do_handle_one_connection(CONNECT*, bool))[0x5605ce7d370f]
sql/sql_connect.cc:1318(handle_one_connection)[0x5605ce7d3a5d]
perfschema/pfs.cc:2204(pfs_spawn_thread)[0x5605ceb404c2]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x7ea7)[0x7f1dfda4dea7]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7f1dfd654a2f]



 Comments   
Comment by Daniel Black [ 2023-05-11 ]

Appears to have the same stack trace as MDEV-31240.

Can you show the EXPLAIN query?

Comment by Daniel Black [ 2023-05-11 ]

Since you have a test system with debug symbols installed, can you:

Use gdb to attach to mariadb

sudo -u mysql gdb -p $(pidof mariadbd)
 
(gdb) continue

Execute the crashing query.

(gdb) set print frame-arguments all
(gdb) bt full

And include that output here please.

Comment by Markus Peter [ 2023-05-11 ]

I cannot show the EXPLAIN as the EXPLAIN crashes, too.

I've run gdb on a core dump earlier and poked around a bit:

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
--Type <RET> for more, q to quit, c to continue without paging--   
Core was generated by `/usr/sbin/mariadbd'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f2ef9ce396f in __GI___poll (fds=0x55e4f5b322c8, nfds=2, timeout=timeout@entry=-1)
    at ../sysdeps/unix/sysv/linux/poll.c:29
29	../sysdeps/unix/sysv/linux/poll.c: No such file or directory.
[Current thread is 1 (Thread 0x7f2ef98fe080 (LWP 9559))]
(gdb) thread 2
[Switching to thread 2 (Thread 0x7f2ea810c700 (LWP 9698))]
#0  st_join_table::choose_best_splitting (this=this@entry=0x7f292c176888, idx=idx@entry=0, 
    remaining_tables=remaining_tables@entry=1, spl_pd_boundary=spl_pd_boundary@entry=0x7f2ea8109cd8)
    at ./sql/opt_split.cc:1047
1047	./sql/opt_split.cc: No such file or directory.
(gdb) bt
#0  st_join_table::choose_best_splitting (this=this@entry=0x7f292c176888, idx=idx@entry=0, 
    remaining_tables=remaining_tables@entry=1, spl_pd_boundary=spl_pd_boundary@entry=0x7f2ea8109cd8)
    at ./sql/opt_split.cc:1047
#1  0x000055e4f3386988 in best_access_path (join=0x7f292c1556d8, s=0x7f292c176888, remaining_tables=1, 
    join_positions=0x7f292c176e58, idx=0, disable_jbuf=true, record_count=1, pos=0x7f292c176e58, 
    loose_scan_pos=0x7f2ea8109e60) at ./sql/sql_select.cc:7898
#2  0x000055e4f338a71f in best_extension_by_limited_search (join=0x7f292c1556d8, remaining_tables=1, idx=0, 
    record_count=1, read_time=0, search_depth=62, prune_level=1, use_cond_selectivity=4) at ./sql/sql_select.cc:10334
#3  0x000055e4f338b534 in greedy_search (use_cond_selectivity=4, prune_level=1, search_depth=62, remaining_tables=1, 
    join=0x7f292c1556d8) at ./sql/sql_select.cc:9471
#4  choose_plan (join=0x7f292c1556d8, join_tables=<optimized out>) at ./sql/sql_select.cc:9031
#5  0x000055e4f33b57b1 in make_join_statistics (join=0x7f292c1556d8, tables_list=..., keyuse_array=0x7f292c1559f8)
    at ./sql/sql_select.cc:5963
#6  0x000055e4f33ba49c in JOIN::optimize_inner (this=0x7f292c1556d8) at ./sql/sql_select.cc:2509
#7  0x000055e4f33baab0 in JOIN::optimize (this=this@entry=0x7f292c1556d8) at ./sql/sql_select.cc:1848
#8  0x000055e4f332773d in st_select_lex::optimize_unflattened_subqueries (this=0x7f292c0113b0, 
    const_only=const_only@entry=false) at ./sql/sql_lex.cc:4925
#9  0x000055e4f34a608e in JOIN::optimize_unflattened_subqueries (this=this@entry=0x7f292c119820)
    at ./sql/opt_subselect.cc:5674
#10 0x000055e4f33b61da in JOIN::optimize_stage2 (this=<optimized out>) at ./sql/sql_select.cc:3334
#11 0x000055e4f33ba5ac in JOIN::optimize_inner (this=0x7f292c119820) at ./sql/sql_select.cc:2535
#12 0x000055e4f33baab0 in JOIN::optimize (this=this@entry=0x7f292c119820) at ./sql/sql_select.cc:1848
#13 0x000055e4f33bab83 in mysql_select (thd=0x7f292c000c58, tables=0x7f292c020218, fields=..., conds=0x7f292c020a30, 
    og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=<optimized out>, result=0x7f292c1197f8, 
    unit=0x7f292c004e08, select_lex=0x7f292c0113b0) at ./sql/sql_select.cc:5055
#14 0x000055e4f33bb38f in handle_select (thd=thd@entry=0x7f292c000c58, lex=lex@entry=0x7f292c004d40, 
    result=result@entry=0x7f292c1197f8, setup_tables_done_option=setup_tables_done_option@entry=0)
    at ./sql/sql_select.cc:559
#15 0x000055e4f33410f1 in execute_sqlcom_select (thd=0x7f292c000c58, all_tables=0x7f292c020218)
    at ./sql/sql_parse.cc:6273
#16 0x000055e4f3350267 in mysql_execute_command (thd=0x7f292c000c58, is_called_from_prepared_stmt=<optimized out>)
    at ./sql/sql_parse.cc:3949
#17 0x000055e4f3351857 in mysql_parse (thd=0x7f292c000c58, rawbuf=<optimized out>, length=<optimized out>, 
    parser_state=<optimized out>) at ./sql/sql_parse.cc:8036
#18 0x000055e4f335405d in dispatch_command (command=COM_QUERY, thd=0x7f292c000c58, packet=<optimized out>, 
    packet_length=<optimized out>, blocking=<optimized out>) at ./sql/sql_class.h:240
#19 0x000055e4f3355bf8 in do_command (thd=0x7f292c000c58, blocking=blocking@entry=true) at ./sql/sql_parse.cc:1409
#20 0x000055e4f346470f in do_handle_one_connection (connect=<optimized out>, put_in_cache=true)
    at ./sql/sql_connect.cc:1416
#21 0x000055e4f3464a5d in handle_one_connection (arg=arg@entry=0x55e4f5b34db8) at ./sql/sql_connect.cc:1318
#22 0x000055e4f37d14c2 in pfs_spawn_thread (arg=0x55e4f5b34e28) at ./storage/perfschema/pfs.cc:2201
#23 0x00007f2efa0e8ea7 in start_thread (arg=<optimized out>) at pthread_create.c:477
#24 0x00007f2ef9cefa2f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
(gdb) info locals
pos = 0x80712c176d10
last_found = 1
spl_opt_info = 0x7f292c1767e8
join = 0x7f292c155d68
thd = 0x7f292c000c58
tables_usable_for_splitting = 1
keyuse_ext = 0x7f292c1cae80
best_key_keyuse_ext_start = <optimized out>
best_table = <optimized out>
best_rec_per_key = <optimized out>
spl_plan = 0x0
best_key = <optimized out>
best_key_parts = <optimized out>
best_param_tables = <optimized out>
trace_obj = {<Json_writer_struct> = {_vptr.Json_writer_struct = 0x55e4f4171910 <vtable for Json_writer_object+16>, 
    my_writer = 0x0, context = {writer = 0x0}, closed = false}, <No data fields>}
trace_arr = {<Json_writer_struct> = {_vptr.Json_writer_struct = 0x55e4f4171930 <vtable for Json_writer_array+16>, 
    my_writer = 0x0, context = {writer = 0x0}, closed = true}, <No data fields>}
refills = 1.7976931348623157e+308
excluded_tables = 1
(gdb) p pos
$1 = (POSITION *) 0x80712c176d10
(gdb) p pos->table
Cannot access memory at address 0x80712c176d10
(gdb) info args
this = 0x7f292c176888
idx = 0
remaining_tables = 1
spl_pd_boundary = 0x7f2ea8109cd8

I will attach the backtrace you requested as a file - copy & paste seems to destroy indentation.

Comment by Daniel Black [ 2023-05-11 ]

Thanks. Good addition of the locals.

{noformat} can be used for getting a raw format on sections.

Comment by Daniel Black [ 2023-05-11 ]

When idx =0, accessing POSITION *pos= &this->join->positions[idx - 1] isn't a good move. (opt_split.cc:1045).

Comment by Sergei Petrunia [ 2023-05-11 ]

Pretty-printed crashing query:

SELECT * FROM 
  (SELECT 
     CONCAT(Nachname, ', ', Vorname) AS Name , 
     CONCAT(RIGHT(mo.month, 2), ', ', LEFT(mo.month, 4)) AS Monat , 
     Bildungsgutscheinnummer AS Maßnahmennummer , 
     CONCAT(DATE_FORMAT(Vertrag_Beginn,'%d.%m.%Y'), ' - ', 
     DATE_FORMAT(Vertrag_Ende, '%d.%m.%Y')) AS Maßnahmenzeitraum , 
     (
        SELECT
          SUM(Anzahl)
        FROM
          view_Schüler_Fehlzeit_Monat_Tag vst
        WHERE
          s.Id = vst.Schüler_Id AND
          vst.jahr_monat BETWEEN date_format(Vertrag_Beginn, '%Y-%m') AND mo.month
      ) AS 'Fehltage_gesamt' , 
 
      f.eins , f.zwei , f.drei , f.vier , f.fünf , f.sechs , f.sieben , f.acht , 
      f.neun , f.zehn , f.elf , f.zwölf , f.dreizehn , f.vierzehn , f.fünfzehn ,
      f.sechzehn , f.siebzehn , f.achtzehn , f.neunzehn , f.zwanzig , f.einundzwanzig ,
      f.zweiundzwanzig , f.dreiundzwanzig , f.vierundzwanzig , f.fünfundzwanzig , 
      f.sechsundzwanzig , f.siebenundzwanzig , f.achtundzwanzig , f.neunundzwanzig , 
      f.dreißig , f.einunddreißig 
   FROM 
     Akademie_Schüler s JOIN const.month mo ON mo.month BETWEEN date_format(Vertrag_Beginn, '%Y-%m') AND
        date_format(ifnull(Vertrag_Ende, CURRENT_DATE), '%Y-%m') 
     LEFT JOIN view_Schüler_Fehlzeit_Monat_Tag f ON f.Schüler_Id = s.Id AND mo.month = jahr_monat 
   WHERE 1=0 
 )
AS _dummy_table WHERE 1=0 LIMIT 0

Note: we crash when optimizing the join inside the subquery. The subquery uses view_Schüler_Fehlzeit_Monat_Tag. The text of the query we have does not seem to be important for the crash.

Comment by Sergei Petrunia [ 2023-05-11 ]

See MDEV-31240 for analysis and suggested patch.

Comment by Markus Peter [ 2023-05-11 ]

Original view definition is:

CREATE TABLE `Fehlzeit_Schüler` (
  `Id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `Datum` date NOT NULL,
  `Schüler_Id` int(11) unsigned NOT NULL,
  `Typ` enum('Ganzer Tag','Kommt Später','Geht Früher','Kommt Später und geht Früher') NOT NULL DEFAULT 'Ganzer Tag',
  `Verpasste_Zeit` int(11) DEFAULT NULL,
  `Entschuldigung` enum('Krank','Termin','Sonstiges(Angekündigt)','Sonstiges(Unangekündigt)','KEINE') DEFAULT NULL,
  `Entschuldigung_Begründung` text DEFAULT NULL,
  `Foto_Krankmeldung` text DEFAULT NULL,
  `nubis_created_by` varchar(80) DEFAULT NULL,
  `nubis_created_at` datetime DEFAULT current_timestamp(),
  `nubis_changed_by` varchar(80) DEFAULT NULL,
  `nubis_changed_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`Id`),
  UNIQUE KEY `key_schuelerid_datum` (`Schüler_Id`,`Datum`)
) ;
 
CREATE VIEW view_Schüler_Fehlzeit_Monat_Tag AS SELECT
	Schüler_Id,
	DATE_FORMAT(Datum,'%Y-%m') AS 'jahr_monat',
	Datum AS 'Datum',
	COUNT(*) AS Anzahl,
	GROUP_CONCAT(IF (Day(Datum) = 1,map_excuses(Entschuldigung),NULL)) AS eins,
	GROUP_CONCAT(IF (Day(Datum) = 2,map_excuses(Entschuldigung),NULL)) AS zwei,
	GROUP_CONCAT(IF (Day(Datum) = 3,map_excuses(Entschuldigung),NULL)) AS drei,
	GROUP_CONCAT(IF (Day(Datum) = 4,map_excuses(Entschuldigung),NULL)) AS vier,
	GROUP_CONCAT(IF (Day(Datum) = 5,map_excuses(Entschuldigung),NULL)) AS fünf,
	GROUP_CONCAT(IF (Day(Datum) = 6,map_excuses(Entschuldigung),NULL)) AS sechs,
	GROUP_CONCAT(IF (Day(Datum) = 7,map_excuses(Entschuldigung),NULL)) AS sieben,
	GROUP_CONCAT(IF (Day(Datum) = 8,map_excuses(Entschuldigung),NULL)) AS acht,
	GROUP_CONCAT(IF (Day(Datum) = 9,map_excuses(Entschuldigung),NULL)) AS neun,
	GROUP_CONCAT(IF (Day(Datum) = 10,map_excuses(Entschuldigung),NULL)) AS zehn,
	GROUP_CONCAT(IF (Day(Datum) = 11,map_excuses(Entschuldigung),NULL)) AS elf,
	GROUP_CONCAT(IF (Day(Datum) = 12,map_excuses(Entschuldigung),NULL)) AS zwölf,
	GROUP_CONCAT(IF (Day(Datum) = 13,map_excuses(Entschuldigung),NULL)) AS dreizehn,
	GROUP_CONCAT(IF (Day(Datum) = 14,map_excuses(Entschuldigung),NULL)) AS vierzehn,
	GROUP_CONCAT(IF (Day(Datum) = 15,map_excuses(Entschuldigung),NULL)) AS fünfzehn,
	GROUP_CONCAT(IF (Day(Datum) = 16,map_excuses(Entschuldigung),NULL)) AS sechzehn,
	GROUP_CONCAT(IF (Day(Datum) = 17,map_excuses(Entschuldigung),NULL)) AS siebzehn,
	GROUP_CONCAT(IF (Day(Datum) = 18,map_excuses(Entschuldigung),NULL)) AS achtzehn,
	GROUP_CONCAT(IF (Day(Datum) = 19,map_excuses(Entschuldigung),NULL)) AS neunzehn,
	GROUP_CONCAT(IF (Day(Datum) = 20,map_excuses(Entschuldigung),NULL)) AS zwanzig,
	GROUP_CONCAT(IF (Day(Datum) = 21,map_excuses(Entschuldigung),NULL)) AS einundzwanzig,
	GROUP_CONCAT(IF (Day(Datum) = 22,map_excuses(Entschuldigung),NULL)) AS zweiundzwanzig,
	GROUP_CONCAT(IF (Day(Datum) = 23,map_excuses(Entschuldigung),NULL)) AS dreiundzwanzig,
	GROUP_CONCAT(IF (Day(Datum) = 24,map_excuses(Entschuldigung),NULL)) AS vierundzwanzig,
	GROUP_CONCAT(IF (Day(Datum) = 25,map_excuses(Entschuldigung),NULL)) AS fünfundzwanzig,
	GROUP_CONCAT(IF (Day(Datum) = 26,map_excuses(Entschuldigung),NULL)) AS sechsundzwanzig,
	GROUP_CONCAT(IF (Day(Datum) = 27,map_excuses(Entschuldigung),NULL)) AS siebenundzwanzig,
	GROUP_CONCAT(IF (Day(Datum) = 28,map_excuses(Entschuldigung),NULL)) AS achtundzwanzig,
	GROUP_CONCAT(IF (Day(Datum) = 29,map_excuses(Entschuldigung),NULL)) AS neunundzwanzig,
	GROUP_CONCAT(IF (Day(Datum) = 30,map_excuses(Entschuldigung),NULL)) AS dreißig,
	GROUP_CONCAT(IF (Day(Datum) = 31,map_excuses(Entschuldigung),NULL)) AS einunddreißig
FROM 
	Fehlzeit_Schüler
GROUP BY 
	Schüler_Id, 
	DATE_FORMAT(Datum, '%Y-%m')
;

and for completeness, const.month is

CREATE TABLE `month` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `month` varchar(7) DEFAULT NULL,
  `premonth` varchar(7) DEFAULT NULL,
  `year` smallint(5) unsigned NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `month` (`month`),
  KEY `year` (`year`)
);

Comment by Markus Peter [ 2023-05-11 ]

I also attached an EXPLAIN screenshot from an older installation which is not crashing.

Comment by Daniel Black [ 2023-05-12 ]

Thanks for the info warp. Apologies for the bug introduction. Leaving resolution to the MDEV-31240 issue.

Comment by Sergei Petrunia [ 2023-05-12 ]

Thanks for the view definition.

Putting the view into the query and removing irrelevant parts:

SELECT * FROM 
  (SELECT 
     (SELECT
       ...
        FROM
          (SELECT
                 Schüler_Id,
                 ....
              FROM 
                 Fehlzeit_Schüler
              GROUP BY 
                 Schüler_Id....
          )
          vst 
        WHERE
          s.Id = vst.Schüler_Id AND
      ) AS 'Fehltage_gesamt', 
   FROM 
     Akademie_Schüler s JOIN ...

Note

s.Id = vst.Schüler_Id 

  • vst.Schüler_Id is the Split Materialized column.
  • s.Id is the outside reference.

Indeed this is the same construct as in MDEV-31240. The fix for MDEV-31240 will fix this.

Comment by Sergei Petrunia [ 2023-05-12 ]

Ok the patch for MDEV-31240 is pushed into 10.4. It will be merged to other versions.

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