• Igor Babaev's avatar
    MDEV-23406 Signal 8 in maria_create after recursive cte query · a244be70
    Igor Babaev authored
    This bug could cause a crash when executing queries that used mutually
    recursive CTEs with system variable big_tables set to 1. It happened due
    to several bugs in the code that handled recursive table references
    referred mutually recursive CTEs. For each recursive table reference a
    temporary table is created that contains all rows generated for the
    corresponding recursive CTE table on the previous step of recursion.
    This temporary table should be created in the same way as the temporary
    table created for a regular materialized derived table using the
    method select_union::create_result_table(). In this case when the
    temporary table is created it uses the select_union::TMP_TABLE_PARAM
    structure as the parameter for the table construction. However the
    code created the temporary table using just the function create_tmp_table()
    and passed pointers to certain fields of the TMP_TABLE_PARAM structure
    used for accumulation of rows of the recursive CTE table as parameters
    for update. This was a mistake because now different temporary tables
    cannot share some TMP_TABLE_PARAM fields in a general case. Besides,
    depending on how mutually recursive CTE tables were defined and which
    of them were referred in the executed query the select_union object
    allocated for a recursive table reference could be allocated again after
    the the temporary table had been created. In this case the TMP_TABLE_PARAM
    object associated with the temporary table created for the recursive
    table reference contained unassigned fields needed for execution when
    Aria engine is employed as the engine for temporary tables.
    This patch ensures that
    - select_union object is created only once for any recursive table
      reference
    - any temporary table created for recursive CTEs uses its own
      TMP_TABLE_PARAM structure
    The patch also fixes a problem caused by incomplete cleanup of join tables
    associated with recursive table references.
    
    Approved by Oleksandr Byelkin <sanja@mariadb.com>
    a244be70
sql_union.cc 48.8 KB