summaryrefslogtreecommitdiff
path: root/sql/sql_view.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_view.cc')
-rw-r--r--sql/sql_view.cc59
1 files changed, 33 insertions, 26 deletions
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 3d8b9323b2a..0a8c2eac1a0 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
+/* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,7 +22,7 @@
#include "sql_base.h" // find_table_in_global_list, lock_table_names
#include "sql_parse.h" // sql_parse
#include "sql_cache.h" // query_cache_*
-#include "lock.h" // wait_if_global_read_lock
+#include "lock.h" // MYSQL_OPEN_SKIP_TEMPORARY
#include "sql_show.h" // append_identifier
#include "sql_table.h" // build_table_filename
#include "sql_db.h" // mysql_opt_change_db, mysql_change_db
@@ -550,7 +550,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
}
/* prepare select to resolve all fields */
- lex->view_prepare_mode= 1;
+ lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_VIEW;
if (unit->prepare(thd, 0, 0))
{
/*
@@ -649,13 +649,6 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
}
#endif
-
- if (thd->global_read_lock.wait_if_global_read_lock(thd, FALSE, TRUE))
- {
- res= TRUE;
- goto err;
- }
-
res= mysql_register_view(thd, view, mode);
if (mysql_bin_log.is_open())
@@ -704,7 +697,6 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
if (mode != VIEW_CREATE_NEW)
query_cache_invalidate3(thd, view, 0);
- thd->global_read_lock.start_waiting_global_read_lock(thd);
if (res)
goto err;
@@ -849,7 +841,8 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
thd->variables.sql_mode&= ~MODE_ANSI_QUOTES;
lex->unit.print(&view_query, QT_ORDINARY);
- lex->unit.print(&is_query, QT_IS);
+ lex->unit.print(&is_query,
+ enum_query_type(QT_TO_SYSTEM_CHARSET | QT_WITHOUT_INTRODUCERS));
thd->variables.sql_mode|= sql_mode;
}
@@ -1280,6 +1273,7 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
TABLE_LIST *view_tables= lex->query_tables;
TABLE_LIST *view_tables_tail= 0;
TABLE_LIST *tbl;
+ Security_context *security_ctx;
/*
Check rights to run commands (EXPLAIN SELECT & SHOW CREATE) which show
@@ -1426,26 +1420,39 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
if (table->view_suid)
{
/*
- Prepare a security context to check underlying objects of the view
+ For suid views prepare a security context for checking underlying
+ objects of the view.
*/
if (!(table->view_sctx= (Security_context *)
thd->stmt_arena->alloc(sizeof(Security_context))))
goto err;
- /* Assign the context to the tables referenced in the view */
- if (view_tables)
- {
- DBUG_ASSERT(view_tables_tail);
- for (tbl= view_tables; tbl != view_tables_tail->next_global;
- tbl= tbl->next_global)
- tbl->security_ctx= table->view_sctx;
- }
- /* assign security context to SELECT name resolution contexts of view */
- for(SELECT_LEX *sl= lex->all_selects_list;
- sl;
- sl= sl->next_select_in_list())
- sl->context.security_ctx= table->view_sctx;
+ security_ctx= table->view_sctx;
+ }
+ else
+ {
+ /*
+ For non-suid views inherit security context from view's table list.
+ This allows properly handle situation when non-suid view is used
+ from within suid view.
+ */
+ security_ctx= table->security_ctx;
}
+ /* Assign the context to the tables referenced in the view */
+ if (view_tables)
+ {
+ DBUG_ASSERT(view_tables_tail);
+ for (tbl= view_tables; tbl != view_tables_tail->next_global;
+ tbl= tbl->next_global)
+ tbl->security_ctx= security_ctx;
+ }
+
+ /* assign security context to SELECT name resolution contexts of view */
+ for(SELECT_LEX *sl= lex->all_selects_list;
+ sl;
+ sl= sl->next_select_in_list())
+ sl->context.security_ctx= security_ctx;
+
/*
Setup an error processor to hide error messages issued by stored
routines referenced in the view