• Vlad Lesin's avatar
    MDEV-30648 btr_estimate_n_rows_in_range() accesses unfixed, unlatched page · 687fd6be
    Vlad Lesin authored
    The issue is caused by MDEV-30400 fix.
    
    There are two cursors in btr_estimate_n_rows_in_range() - p1 and p2, but
    both share the same mtr. Each cursor contains mtr savepoint for the
    previously fetched block to release it then the current block is
    fetched.
    
    Before MDEV-30400 the block was released with
    mtr_t::release_block_at_savepoint(), it just unfixed a block and
    released its page patch. In MDEV-30400 it was replaced with
    mtr_t::rollback_to_savepoint(), which does the same as the former
    mtr_t::release_block_at_savepoint(ulint begin, ulint end) but also
    erases the corresponding slots from mtr memo, what invalidates any
    stored mtr's memo savepoints, greater or equal to "begin".
    
    The idea of the fix is to get rid of savepoints at all in
    btr_estimate_n_rows_in_range() and
    btr_estimate_n_rows_in_range_on_level(). As
    mtr_t::rollback_to_savepoint() erases elements from mtr_t::m_memo, we
    know what element of mtr_t::m_memo can be deleted on the certain case,
    so there is no need to store savepoints.
    
    See also the following slides for details:
    https://docs.google.com/presentation/d/1RFYBo7EUhM22ab3GOYctv3j_3yC0vHtBY9auObZec8U
    
    Reviewed by: Marko Mäkelä
    687fd6be
btr0cur.cc 218 KB