• Jon Olav Hauglid's avatar
    Backport of revno: 3673 · 1cfcd2d2
    Jon Olav Hauglid authored
    Bug #47313 assert in check_key_in_view during CALL procedure
    
    View definitions are inlined in a stored procedure when the procedure
    is fist called. This means that if a temporary table is later added
    with the same name as the view, the stored procedure will still
    use the view. This happens even if temporary tables normally shadow
    base tables/views.
    
    The reason for the assert was that even if the stored procedure
    referenced the view, open_table() still tried to open the
    temporary table. This "half view/half temporary table" state
    caused the assert.
    
    The bug was not present in 5.1 as open_table() is not called
    for the view there. This code was changed with the introduction 
    of MDL in order to properly lock the view and any objects it 
    refers to.
    
    This patch fixes the problem by instructing open_table()
    to open base tables/views (using OT_BASE_ONLY) when reopening
    tables/views used by stored procedures. This also means that
    a prepared statement is no longer invalidated if a temporary
    table is created with the same name as a view used in the
    prepared statement.
    
    Test case added to sp.test. The test case also demonstrates
    the effect of sp cache invalidation between CALLs.
    1cfcd2d2
sp.test 178 KB