• Sergei Petrunia's avatar
    MDEV-23160: SIGSEGV in Explain_node::print_explain_for_children on UNION SELECT · 6bc2e933
    Sergei Petrunia authored
    and also MDEV-25564, MDEV-18157.
    
    Attempt to produce EXPLAIN output caused a crash in
    Explain_node::print_explain_for_children. The cause of this was that an
    Explain_node (actually a derived) had a link to child select#N, but
    there was no query plan present for select#N.
    
    The query plan wasn't present because the subquery was eliminated.
    - Either it was a degenerate subquery like "(SELECT 1)" in MDEV-25564.
    - Or it was a subquery in a UNION subquery's ORDER BY clause:
       col IN (SELECT ... UNION
               SELECT ... ORDER BY (SELECT FROM t1))
    
    In such cases, legacy code structure in subquery/union processing code(*)
    makes it hard to detect that the subquery was eliminated, so we end up
    with EXPLAIN data structures (Explain_node::children) having dangling
    links to child subqueries.
    Do make the checks and don't follow the dangling links.
    
    (In ideal world, we should not have these dangling links. But fixing
    the code (*) would have high risk for the stable versions).
    6bc2e933
sql_explain.cc 66.7 KB