summaryrefslogtreecommitdiff
path: root/sql/sql_view.cc
diff options
context:
space:
mode:
authorJon Olav Hauglid <jon.hauglid@sun.com>2009-12-10 13:37:18 +0100
committerJon Olav Hauglid <jon.hauglid@sun.com>2009-12-10 13:37:18 +0100
commit1cfcd2d210b8a069496571d3d35bf3b8bd5ee67e (patch)
treeed39d148a9de59b92d9f8a2f84135a1986504c87 /sql/sql_view.cc
parentb6fb4dbab23490eca5c181e3fb68ce61bdd36a87 (diff)
downloadmariadb-git-1cfcd2d210b8a069496571d3d35bf3b8bd5ee67e.tar.gz
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.
Diffstat (limited to 'sql/sql_view.cc')
-rw-r--r--sql/sql_view.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 6d2836afc0d..17ac10ebfb9 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -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 */