diff options
author | Jon Olav Hauglid <jon.hauglid@sun.com> | 2010-02-18 14:54:38 +0100 |
---|---|---|
committer | Jon Olav Hauglid <jon.hauglid@sun.com> | 2010-02-18 14:54:38 +0100 |
commit | d62496ce611c7c0eccf3ac6c54114e86681f67dd (patch) | |
tree | a0aa3df92234543674ec89cc1a34e3e77ec06808 /sql/sql_base.cc | |
parent | 58a076867246ac4f931f89ee729c520600d84ae8 (diff) | |
download | mariadb-git-d62496ce611c7c0eccf3ac6c54114e86681f67dd.tar.gz |
Bug #48315 Metadata lock is not taken for merged views that use
an INFORMATION_SCHEMA table
When a prepared statement using a merged view containing an information
schema table was executed, a metadata lock of the view was not taken.
This meant that it was possible for concurrent view DDL to execute,
thereby breaking the binary log. For example, it was possible
for DROP VIEW to appear in the binary log before a query using the view.
This also happened when a statement in a stored routine was executed a
second time.
For such views, the information schema table is merged into the view
during the prepare phase (or first execution of a statement in a routine).
The problem was that we took a short cut and were not executing full-blown
view opening during subsequent executions of the statement. As a result,
a metadata lock on the view was not taken to protect the view definition.
This patch resolves the problem by making sure a metadata lock is taken
for views even after information schema tables are merged into them.
Test cased added to view.test.
Diffstat (limited to 'sql/sql_base.cc')
-rw-r--r-- | sql/sql_base.cc | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 6ff7085f740..d5a664df0d0 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -4168,9 +4168,18 @@ open_and_process_table(THD *thd, LEX *lex, TABLE_LIST *tables, TABLE_LIST is processed. This code works only during re-execution. */ if (tables->view) - goto process_view_routines; - if (!mysql_schema_table(thd, lex, tables) && - !check_and_update_table_version(thd, tables, tables->table->s)) + { + /* + We still need to take a MDL lock on the merged view to protect + it from concurrent changes. + */ + if (!open_table_get_mdl_lock(thd, tables, &tables->mdl_request, + ot_ctx, flags)) + goto process_view_routines; + /* Fall-through to return error. */ + } + else if (!mysql_schema_table(thd, lex, tables) && + !check_and_update_table_version(thd, tables, tables->table->s)) { goto end; } |