• Sergei Petrunia's avatar
    MDEV-26047: MariaDB server crash at Item_subselect::init_expr_cache_tracker · 5100b20b
    Sergei Petrunia authored
    The cause of crash:
    remove_redundant_subquery_clauses() removes redundant item expressions.
    The primary goal of this is to remove the subquery items.
    The removal process unlinks the subquery from SELECT_LEX tree, but does
    not remove it from SELECT_LEX:::ref_pointer_array or from JOIN::all_fields.
    Then, setup_subquery_caches() tries to wrap the subquery item in an
    expression cache, which fails, the first reason for failure being that
    the item doesn't have a query plan.
    
    Solution: do not wrap eliminated items with expression cache.
    (also added an assert to check that we do not attempt to execute them).
    
    This may look like an incomplete fix: why don't we remove any mention
    of eliminated item everywhere? The difficulties here are:
    * items can be "un-removed" (see set_fake_select_as_master_processor)
    * it's difficult to remove an element from ref_pointer_array: Item_ref
    objects refer to elements of that array, so one can't shift elements in
    it. Replacing eliminated subselect with a dummy Item doesn't look like a
    good idea, either.
    5100b20b
subselect_innodb.test 18.9 KB