diff options
Diffstat (limited to 'sql/sql_view.cc')
-rw-r--r-- | sql/sql_view.cc | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/sql/sql_view.cc b/sql/sql_view.cc index cef20ba08f9..0684e6ebcc5 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -1,5 +1,5 @@ /* Copyright (c) 2004, 2013, Oracle and/or its affiliates. - Copyright (c) 2011, 2015, MariaDB + Copyright (c) 2011, 2016, MariaDB Corporation 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 @@ -35,6 +35,7 @@ #include "sp_cache.h" #include "datadict.h" // dd_frm_is_view() #include "sql_derived.h" +#include "sql_cte.h" // check_dependencies_in_with_clauses() #define MD5_BUFF_LENGTH 33 @@ -58,7 +59,7 @@ static int mysql_register_view(THD *, TABLE_LIST *, enum_view_create_mode); NAME_LEN, it is truncated. */ -static void make_unique_view_field_name(Item *target, +static void make_unique_view_field_name(THD *thd, Item *target, List<Item> &item_list, Item *last_element) { @@ -96,7 +97,7 @@ static void make_unique_view_field_name(Item *target, } target->orig_name= target->name; - target->set_name(buff, name_len, system_charset_info); + target->set_name(thd, buff, name_len, system_charset_info); } @@ -123,7 +124,7 @@ static void make_unique_view_field_name(Item *target, isn't allowed */ -bool check_duplicate_names(List<Item> &item_list, bool gen_unique_view_name) +bool check_duplicate_names(THD *thd, List<Item> &item_list, bool gen_unique_view_name) { Item *item; List_iterator_fast<Item> it(item_list); @@ -144,9 +145,9 @@ bool check_duplicate_names(List<Item> &item_list, bool gen_unique_view_name) if (!gen_unique_view_name) goto err; if (item->is_autogenerated_name) - make_unique_view_field_name(item, item_list, item); + make_unique_view_field_name(thd, item, item_list, item); else if (check->is_autogenerated_name) - make_unique_view_field_name(check, item_list, item); + make_unique_view_field_name(thd, check, item_list, item); else goto err; } @@ -167,7 +168,7 @@ err: @param item_list List of Items which should be checked */ -static void make_valid_column_names(List<Item> &item_list) +void make_valid_column_names(THD *thd, List<Item> &item_list) { Item *item; uint name_len; @@ -181,7 +182,7 @@ static void make_valid_column_names(List<Item> &item_list) continue; name_len= my_snprintf(buff, NAME_LEN, "Name_exp_%u", column_no); item->orig_name= item->name; - item->set_name(buff, name_len, system_charset_info); + item->set_name(thd, buff, name_len, system_charset_info); } DBUG_VOID_RETURN; @@ -216,7 +217,7 @@ fill_defined_view_parts (THD *thd, TABLE_LIST *view) decoy= *view; decoy.mdl_request.key.mdl_key_init(&view->mdl_request.key); - if (tdc_open_view(thd, &decoy, decoy.alias, OPEN_VIEW_NO_PARSE)) + if (tdc_open_view(thd, &decoy, OPEN_VIEW_NO_PARSE)) return TRUE; if (!lex->definer) @@ -428,6 +429,13 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, lex->link_first_table_back(view, link_to_local); view->open_type= OT_BASE_ONLY; + + if (check_dependencies_in_with_clauses(lex->with_clauses_list)) + { + res= TRUE; + goto err; + } + WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL); /* @@ -439,7 +447,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, view->mdl_request.set_type(MDL_EXCLUSIVE); } - if (open_temporary_tables(thd, lex->query_tables) || + if (thd->open_temporary_tables(lex->query_tables) || open_and_lock_tables(thd, lex->query_tables, TRUE, 0)) { view= lex->unlink_first_table(&link_to_local); @@ -549,16 +557,16 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, } while ((item= it++, name= nm++)) { - item->set_name(name->str, (uint) name->length, system_charset_info); + item->set_name(thd, name->str, (uint) name->length, system_charset_info); item->is_autogenerated_name= FALSE; } } /* Check if the auto generated column names are conforming. */ for (sl= select_lex; sl; sl= sl->next_select()) - make_valid_column_names(sl->item_list); + make_valid_column_names(thd, sl->item_list); - if (check_duplicate_names(select_lex->item_list, 1)) + if (check_duplicate_names(thd, select_lex->item_list, 1)) { res= TRUE; goto err; @@ -635,7 +643,8 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, if (!res && mysql_bin_log.is_open()) { - String buff; + StringBuffer<128> buff(thd->variables.character_set_client); + DBUG_ASSERT(buff.charset()->mbminlen == 1); const LEX_STRING command[3]= {{ C_STRING_WITH_LEN("CREATE ") }, { C_STRING_WITH_LEN("ALTER ") }, @@ -905,7 +914,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, view_query.length(0); is_query.length(0); { - ulong sql_mode= thd->variables.sql_mode & MODE_ANSI_QUOTES; + sql_mode_t sql_mode= thd->variables.sql_mode & MODE_ANSI_QUOTES; thd->variables.sql_mode&= ~MODE_ANSI_QUOTES; lex->unit.print(&view_query, enum_query_type(QT_VIEW_INTERNAL | @@ -1142,7 +1151,7 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table, bool result, view_is_mergeable; TABLE_LIST *UNINIT_VAR(view_main_select_tables); DBUG_ENTER("mysql_make_view"); - DBUG_PRINT("info", ("table: 0x%lx (%s)", (ulong) table, table->table_name)); + DBUG_PRINT("info", ("table: %p (%s)", table, table->table_name)); if (table->required_type == FRMTYPE_TABLE) { @@ -1337,7 +1346,7 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table, view_select= &lex->select_lex; view_select->select_number= ++thd->lex->stmt_lex->current_select_number; - ulonglong saved_mode= thd->variables.sql_mode; + sql_mode_t saved_mode= thd->variables.sql_mode; /* switch off modes which can prevent normal parsing of VIEW - MODE_REAL_AS_FLOAT affect only CREATE TABLE parsing + MODE_PIPES_AS_CONCAT affect expression parsing @@ -1387,6 +1396,9 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table, TABLE_LIST *tbl; Security_context *security_ctx= 0; + if (check_dependencies_in_with_clauses(thd->lex->with_clauses_list)) + goto err; + /* Check rights to run commands (ANALYZE SELECT, EXPLAIN SELECT & SHOW CREATE) which show underlying tables. @@ -1616,6 +1628,8 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table, sl->context.error_processor_data= (void *)table; } + view_select->master_unit()->is_view= true; + /* check MERGE algorithm ability - algorithm is not explicit TEMPORARY TABLE |