1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

Backport of revno: 3673

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.
This commit is contained in:
Jon Olav Hauglid
2009-12-10 13:37:18 +01:00
parent b6fb4dbab2
commit 1cfcd2d210
5 changed files with 271 additions and 3 deletions

View File

@ -1137,6 +1137,20 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
table->view_db.length= table->db_length;
table->view_name.str= table->table_name;
table->view_name.length= table->table_name_length;
/*
We don't invalidate a prepared statement when a view changes,
or when someone creates a temporary table.
Instead, the view is inlined into the body of the statement
upon the first execution. Below, make sure that on
re-execution of a prepared statement we don't prefer
a temporary table to the view, if the view name was shadowed
with a temporary table with the same name.
This assignment ensures that on re-execution open_table() will
not try to call find_temporary_table() for this TABLE_LIST,
but will invoke open_table_from_share(), which will
eventually call this function.
*/
table->open_type= OT_BASE_ONLY;
/*TODO: md5 test here and warning if it is differ */