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.cc89
1 files changed, 41 insertions, 48 deletions
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 9091de619e6..29d24649bb3 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -27,7 +27,6 @@
#include "sql_show.h" // append_identifier
#include "sql_table.h" // build_table_filename
#include "sql_db.h" // mysql_opt_change_db, mysql_change_db
-#include "sql_acl.h" // *_ACL, check_grant
#include "sql_select.h"
#include "parse_file.h"
#include "sp_head.h"
@@ -35,8 +34,8 @@
#include "sp_cache.h"
#include "datadict.h" // dd_frm_is_view()
#include "sql_derived.h"
-#include "sql_cte.h" // check_dependencies_in_with_clauses()
#include "opt_trace.h"
+#include "wsrep_mysqld.h"
#define MD5_BUFF_LENGTH 33
@@ -137,7 +136,7 @@ bool check_duplicate_names(THD *thd, List<Item> &item_list, bool gen_unique_view
Item *check;
/* treat underlying fields like set by user names */
if (item->real_item()->type() == Item::FIELD_ITEM)
- item->is_autogenerated_name= FALSE;
+ item->common_flags&= ~IS_AUTO_GENERATED_NAME;
itc.rewind();
while ((check= itc++) && check != item)
{
@@ -145,9 +144,9 @@ bool check_duplicate_names(THD *thd, List<Item> &item_list, bool gen_unique_view
{
if (!gen_unique_view_name)
goto err;
- if (item->is_autogenerated_name)
+ if (item->is_autogenerated_name())
make_unique_view_field_name(thd, item, item_list, item);
- else if (check->is_autogenerated_name)
+ else if (check->is_autogenerated_name())
make_unique_view_field_name(thd, check, item_list, item);
else
goto err;
@@ -179,7 +178,7 @@ void make_valid_column_names(THD *thd, List<Item> &item_list)
for (uint column_no= 1; (item= it++); column_no++)
{
- if (!item->is_autogenerated_name || !check_column_name(item->name.str))
+ if (!item->is_autogenerated_name() || !check_column_name(item->name.str))
continue;
name_len= my_snprintf(buff, NAME_LEN, "Name_exp_%u", column_no);
item->orig_name= item->name.str;
@@ -449,6 +448,14 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
goto err_no_relink;
}
+#ifdef WITH_WSREP
+ if(!wsrep_should_replicate_ddl_iterate(thd, static_cast<const TABLE_LIST *>(tables)))
+ {
+ res= TRUE;
+ goto err_no_relink;
+ }
+#endif
+
view= lex->unlink_first_table(&link_to_local);
if (check_db_dir_existence(view->db.str))
@@ -551,8 +558,8 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
}
while ((item= it++, name= nm++))
{
- item->set_name(thd, name->str, (uint) name->length, system_charset_info);
- item->is_autogenerated_name= FALSE;
+ item->set_name(thd, *name);
+ item->common_flags&= ~IS_AUTO_GENERATED_NAME;
}
}
@@ -587,7 +594,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
This will hold the intersection of the priviliges on all columns in the
view.
*/
- uint final_priv= VIEW_ANY_ACL;
+ privilege_t final_priv(VIEW_ANY_ACL);
for (sl= select_lex; sl; sl= sl->next_select())
{
@@ -597,8 +604,9 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
while ((item= it++))
{
Item_field *fld= item->field_for_view_update();
- uint priv= (get_column_grant(thd, &view->grant, view->db.str,
- view->table_name.str, item->name.str) &
+ privilege_t priv(get_column_grant(thd, &view->grant, view->db.str,
+ view->table_name.str,
+ item->name.str) &
VIEW_ANY_ACL);
if (!fld)
@@ -641,7 +649,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
*/
if (!res)
- tdc_remove_table(thd, TDC_RT_REMOVE_ALL, view->db.str, view->table_name.str, false);
+ tdc_remove_table(thd, view->db.str, view->table_name.str);
if (!res && mysql_bin_log.is_open())
{
@@ -930,16 +938,13 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
view_query.length(0);
is_query.length(0);
{
- sql_mode_t sql_mode= thd->variables.sql_mode & MODE_ANSI_QUOTES;
- thd->variables.sql_mode&= ~MODE_ANSI_QUOTES;
+ Sql_mode_instant_remove sms(thd, MODE_ANSI_QUOTES);
lex->unit.print(&view_query, enum_query_type(QT_VIEW_INTERNAL |
QT_ITEM_ORIGINAL_FUNC_NULLIF));
lex->unit.print(&is_query, enum_query_type(QT_TO_SYSTEM_CHARSET |
QT_WITHOUT_INTRODUCERS |
QT_ITEM_ORIGINAL_FUNC_NULLIF));
-
- thd->variables.sql_mode|= sql_mode;
}
DBUG_PRINT("info", ("View: %.*s", view_query.length(), view_query.ptr()));
@@ -1212,7 +1217,7 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table,
if (table->index_hints && table->index_hints->elements)
{
- my_error(ER_KEY_DOES_NOT_EXITS, MYF(0),
+ my_error(ER_KEY_DOES_NOT_EXISTS, MYF(0),
table->index_hints->head()->key_name.str, table->table_name.str);
DBUG_RETURN(TRUE);
}
@@ -1804,10 +1809,10 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
char path[FN_REFLEN + 1];
TABLE_LIST *view;
String non_existant_views;
- const char *wrong_object_db= NULL, *wrong_object_name= NULL;
- bool error= FALSE;
+ bool delete_error= FALSE, wrong_object_name= FALSE;
bool some_views_deleted= FALSE;
bool something_wrong= FALSE;
+ uint not_exists_count= 0;
DBUG_ENTER("mysql_drop_view");
/*
@@ -1837,32 +1842,22 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
char name[FN_REFLEN];
my_snprintf(name, sizeof(name), "%s.%s", view->db.str,
view->table_name.str);
- if (thd->lex->if_exists())
- {
- push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
- ER_UNKNOWN_VIEW,
- ER_THD(thd, ER_UNKNOWN_VIEW),
- name);
- continue;
- }
- if (not_exist)
+ if (non_existant_views.length())
+ non_existant_views.append(',');
+ non_existant_views.append(name);
+
+ if (!not_exist)
{
- if (non_existant_views.length())
- non_existant_views.append(',');
- non_existant_views.append(name);
+ wrong_object_name= 1;
+ my_error(ER_WRONG_OBJECT, MYF(ME_WARNING), view->db.str,
+ view->table_name.str, "VIEW");
}
else
- {
- if (!wrong_object_name)
- {
- wrong_object_db= view->db.str;
- wrong_object_name= view->table_name.str;
- }
- }
+ not_exists_count++;
continue;
}
if (unlikely(mysql_file_delete(key_file_frm, path, MYF(MY_WME))))
- error= TRUE;
+ delete_error= TRUE;
some_views_deleted= TRUE;
@@ -1870,23 +1865,21 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
For a view, there is a TABLE_SHARE object.
Remove it from the table definition cache, in case the view was cached.
*/
- tdc_remove_table(thd, TDC_RT_REMOVE_ALL, view->db.str, view->table_name.str,
- FALSE);
+ tdc_remove_table(thd, view->db.str, view->table_name.str);
query_cache_invalidate3(thd, view, 0);
sp_cache_invalidate();
}
- if (unlikely(wrong_object_name))
- {
- my_error(ER_WRONG_OBJECT, MYF(0), wrong_object_db, wrong_object_name,
- "VIEW");
- }
+ something_wrong= (delete_error ||
+ (!thd->lex->if_exists() && (not_exists_count ||
+ wrong_object_name)));
+
if (unlikely(non_existant_views.length()))
{
- my_error(ER_UNKNOWN_VIEW, MYF(0), non_existant_views.c_ptr_safe());
+ my_error(ER_UNKNOWN_VIEW, MYF(something_wrong ? 0 : ME_NOTE),
+ non_existant_views.c_ptr_safe());
}
- something_wrong= error || wrong_object_name || non_existant_views.length();
if (some_views_deleted || !something_wrong)
{
/* if something goes wrong, bin-log with possible error code,