MDEV-39918 Fix crash in degenerate jtbm semi-join with recursive CTE/…#5241
MDEV-39918 Fix crash in degenerate jtbm semi-join with recursive CTE/…#5241akshatnehra wants to merge 1 commit into
Conversation
…UNION engine execute_degenerate_jtbm_semi_join() assumes the subquery engine is SINGLE_SELECT_ENGINE and casts to subselect_single_select_engine*. However, recursive CTEs, UNIONs, EXCEPTs, and INTERSECTs use UNION_ENGINE even when the first SELECT has no tables (table_count==0). This causes an invalid downcast and crash. Fix: check that the engine type is SINGLE_SELECT_ENGINE before entering the degenerate path. Non-SINGLE_SELECT_ENGINE subqueries fall through to the normal JTBM materialization path. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.
There was a problem hiding this comment.
Code Review
This pull request fixes a crash in execute_degenerate_jtbm_semi_join (MDEV-39918) by restricting the degenerate JTBM semi-join path to subqueries using SINGLE_SELECT_ENGINE. Other engine types, such as UNION_ENGINE (used for UNION, EXCEPT, INTERSECT, and recursive CTEs), are now correctly routed through normal JTBM materialization. Test cases covering these scenarios have also been added. There are no review comments, and I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
gkodinov
left a comment
There was a problem hiding this comment.
Thank you for your contribution! This is a preliminary review.
Since this is a bug fix, can you please rebase it on 10.11?
Otherwise it looks OK to me.
Description
This PR fixes MDEV-39918 where MariaDB crashes with an assertion failure (or segfault in non-debug builds) when a recursive CTE or UNION subquery is used in an IN predicate that triggers the degenerate JTBM semi-join path.
execute_degenerate_jtbm_semi_join()assumes the subquery engine isSINGLE_SELECT_ENGINEand casts unconditionally. However, recursive CTEs, UNIONs, EXCEPTs, and INTERSECTs useUNION_ENGINEeven when the first SELECT has no tables (table_count == 0). The existing condition only checkedtable_count, not the engine type.The fix involves:
SINGLE_SELECT_ENGINE) at both call sites before entering the degenerate path. Non-matching subqueries fall through to normal JTBM materialization.How can this PR be tested?
Run the MTR test:
Or manually (this will crash without the fix):
Results from my testing
Client gets:
ERROR 2026 (HY000): TLS/SSL error: unexpected eof while reading(connection lost due to server crash).No crash. UNION/EXCEPT/INTERSECT variants also work correctly.
Basing the PR against the correct MariaDB version
PR quality check
CODING_STANDARDS.mdfile and my PR conforms to this where appropriate.