MySQL 8.0.40
Source Code Documentation
|
#include "sql/sql_view.h"
#include <sys/types.h>
#include <climits>
#include <cstdio>
#include <cstring>
#include <utility>
#include "lex_string.h"
#include "m_ctype.h"
#include "m_string.h"
#include "mem_root_deque.h"
#include "my_alloc.h"
#include "my_base.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_sqlcommand.h"
#include "my_sys.h"
#include "mysql/mysql_lex_string.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql_com.h"
#include "mysqld_error.h"
#include "sql/auth/auth_acls.h"
#include "sql/auth/auth_common.h"
#include "sql/auth/sql_security_ctx.h"
#include "sql/binlog.h"
#include "sql/dd/cache/dictionary_client.h"
#include "sql/dd/dd.h"
#include "sql/dd/dd_schema.h"
#include "sql/dd/dd_view.h"
#include "sql/dd/dictionary.h"
#include "sql/dd/string_type.h"
#include "sql/dd/types/abstract_table.h"
#include "sql/dd/types/view.h"
#include "sql/dd_sql_view.h"
#include "sql/derror.h"
#include "sql/enum_query_type.h"
#include "sql/error_handler.h"
#include "sql/field.h"
#include "sql/item.h"
#include "sql/key.h"
#include "sql/mdl.h"
#include "sql/mysqld.h"
#include "sql/opt_trace.h"
#include "sql/parse_tree_node_base.h"
#include "sql/parser_yystype.h"
#include "sql/query_options.h"
#include "sql/sp_cache.h"
#include "sql/sql_base.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_error.h"
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_parse.h"
#include "sql/sql_show.h"
#include "sql/sql_table.h"
#include "sql/strfunc.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql/thd_raii.h"
#include "sql/transaction.h"
#include "sql_string.h"
#include "thr_lock.h"
Classes | |
class | Make_view_tracker |
RAII class to ease error handling in parse_view_definition() More... | |
class | DD_table_access_error_handler |
This internal handler is used to trap ER_NO_SYSTEM_TABLE_ACCESS. More... | |
Namespaces | |
namespace | dd |
The version of the current data dictionary table definitions. | |
Functions | |
static void | make_unique_view_field_name (Item *target, const mem_root_deque< Item * > &item_list, Item *last_element) |
bool | check_duplicate_names (const Create_col_name_list *column_names, const mem_root_deque< Item * > &item_list, bool gen_unique_view_name) |
When creating a derived table, check if duplicate column names are present, and possibly generate unique names instead. More... | |
void | make_valid_column_names (LEX *lex) |
Check if auto generated column names are conforming and possibly generate a conforming name for them if not. More... | |
static bool | fill_defined_view_parts (THD *thd, Table_ref *view) |
bool | create_view_precheck (THD *thd, Table_ref *tables, Table_ref *view, enum_view_create_mode mode) |
CREATE VIEW privileges pre-check. More... | |
bool | mysql_create_view (THD *thd, Table_ref *views, enum_view_create_mode mode) |
Creating/altering VIEW procedure. More... | |
bool | is_updatable_view (THD *thd, Table_ref *view) |
bool | mysql_register_view (THD *thd, Table_ref *view, enum_view_create_mode mode) |
Register view by writing its definition to the data-dictionary. More... | |
bool | open_and_read_view (THD *thd, TABLE_SHARE *share, Table_ref *view_ref) |
Open and read a view definition. More... | |
void | merge_query_blocks (LEX *view_lex, LEX *parent_lex) |
Merge a view query expression into the parent expression. More... | |
bool | parse_view_definition (THD *thd, Table_ref *view_ref) |
Parse a view definition. More... | |
bool | mysql_drop_view (THD *thd, Table_ref *views) |
Drop view. More... | |
bool | check_key_in_view (THD *thd, Table_ref *view, const Table_ref *table_ref) |
check of key (primary or unique) presence in updatable view More... | |
bool | insert_view_fields (mem_root_deque< Item * > *list, Table_ref *view) |
bool check_duplicate_names | ( | const Create_col_name_list * | column_names, |
const mem_root_deque< Item * > & | item_list, | ||
bool | gen_unique_view_name | ||
) |
When creating a derived table, check if duplicate column names are present, and possibly generate unique names instead.
column_names | User-provided list of column names, NULL if none |
item_list | SELECT list of underlying query expression |
gen_unique_view_name | See description. |
check of key (primary or unique) presence in updatable view
If the table to be checked is a view and the query has LIMIT clause, then check that the view fulfills one of the following constraints: 1) it contains the primary key of the underlying updatable table. 2) it contains a unique key of the underlying updatable table whose columns are all non-nullable. 3) it contains all columns of the underlying updatable table.
thd | thread handler |
view | view for check with opened table |
table_ref | underlying updatable table of the view |
bool create_view_precheck | ( | THD * | thd, |
Table_ref * | tables, | ||
Table_ref * | view, | ||
enum_view_create_mode | mode | ||
) |
CREATE VIEW privileges pre-check.
thd | thread handler |
tables | tables used in the view |
view | views to create |
mode | VIEW_CREATE_NEW, VIEW_ALTER, VIEW_CREATE_OR_REPLACE |
false | Operation was a success. |
true | An error occurred. |
bool insert_view_fields | ( | mem_root_deque< Item * > * | list, |
Table_ref * | view | ||
) |
|
static |
void make_valid_column_names | ( | LEX * | lex | ) |
Check if auto generated column names are conforming and possibly generate a conforming name for them if not.
lex | LEX for this thread. |
Merge a view query expression into the parent expression.
Update all LEX pointers inside the view expression to point to the parent LEX.
view_lex | View's LEX object. |
parent_lex | Original LEX object. |
bool mysql_create_view | ( | THD * | thd, |
Table_ref * | views, | ||
enum_view_create_mode | mode | ||
) |
Creating/altering VIEW procedure.
Atomicity: The operation to create, alter and create_or_replace a view is atomic/crash-safe. Changes to the Data-dictionary and writing event to binlog are part of the same transaction. All the changes are done as part of the same transaction or do not have any side effects on the operation failure. Data-dictionary and table definition caches are in sync with operation state. Cache do not contain any stale/incorrect data in case of failure. In case of crash, there won't be any discrepancy between the data-dictionary table and the binary log.
thd | thread handler |
views | views to create |
mode | VIEW_CREATE_NEW, VIEW_ALTER, VIEW_CREATE_OR_REPLACE |
false | Operation was a success. |
true | An error occurred. |
Drop view.
Atomicity: The operation to drop a view is atomic/crash-safe. Changes to the Data-dictionary and writing event to binlog are part of the same transaction. All the changes are done as part of the same transaction or do not have any side effects on the operation failure. Data-dictionary and table definition caches are in sync with operation state. Cache do not contain any stale/incorrect data in case of failure. In case of crash, there won't be any discrepancy between the data-dictionary table and the binary log. The partial execution of a drop view statement is not supported any more with atomic drop view implementation.
[in] | thd | thread handler |
[in] | views | views to delete |
false | OK |
true | Error |
bool mysql_register_view | ( | THD * | thd, |
Table_ref * | view, | ||
enum_view_create_mode | mode | ||
) |
Register view by writing its definition to the data-dictionary.
thd | Thread handler. |
view | View description |
mode | VIEW_CREATE_NEW, VIEW_ALTER or VIEW_CREATE_OR_REPLACE. |
false | OK |
true | Error |
bool open_and_read_view | ( | THD * | thd, |
TABLE_SHARE * | share, | ||
Table_ref * | view_ref | ||
) |
Open and read a view definition.
[in] | thd | Thread handler |
[in] | share | Share object of view |
[in,out] | view_ref | Table_ref structure for view reference |
Parse a view definition.
Among other effects, it adds underlying tables to the global list of tables, so the next iteration in open_tables() will open them.
[in] | thd | Thread handler |
[in,out] | view_ref | Table_ref structure for view reference |