• Oleksandr Byelkin's avatar
    MDEV-25182 Complex query in Store procedure corrupts results · 68e0defc
    Oleksandr Byelkin authored
    At the second execution of the PS
    1. mark_as_dependent() is called with the same parameters as at the first
       execution (select#4 and select#3)
    2. as outer_select (select#3) has been already merged at the first
       execution of PS it cannot be reached using the outer_select() function
       anymore (and so can not stop iteration).
    3. as a result all selects towards the top level select including the
       select for 'ca' are marked as uncacheable.
    4. Marked uncacheable it executed incorrectly triggering filling its
       temporary table several times and using freed memory at the end.
    
    To avoid the problem we use name resolution context to go "up".
    
    NOTE: problem also exists in 10.2 but has no visible effect on execution.
    That is why the problem is fixed in 10.2.
    
    The patch also add debug logging of important procedures and
    better specify parameters types of st_select_lex::mark_as_dependent.
    68e0defc
sql_select.cc 875 KB