MySQL 8.4.3
Source Code Documentation
sql_view.h File Reference
#include "lex_string.h"
#include "sql/auth/auth_acls.h"
#include "sql/mem_root_array.h"

Go to the source code of this file.

Macros

#define VIEW_ANY_ACL   (SELECT_ACL | UPDATE_ACL | INSERT_ACL | DELETE_ACL)
 

Typedefs

typedef Mem_root_array_YY< LEX_CSTRINGCreate_col_name_list
 

Functions

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 *view, enum_view_create_mode mode)
 Creating/altering VIEW procedure. More...
 
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 mysql_drop_view (THD *thd, Table_ref *view)
 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_names)
 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...
 
bool open_and_read_view (THD *thd, TABLE_SHARE *share, Table_ref *view_ref)
 Open and read a view definition. More...
 
bool parse_view_definition (THD *thd, Table_ref *view_ref)
 Parse a view definition. More...
 
bool is_updatable_view (THD *thd, Table_ref *view)
 

Macro Definition Documentation

◆ VIEW_ANY_ACL

#define VIEW_ANY_ACL   (SELECT_ACL | UPDATE_ACL | INSERT_ACL | DELETE_ACL)

Typedef Documentation

◆ Create_col_name_list

Function Documentation

◆ check_duplicate_names()

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.

Parameters
column_namesUser-provided list of column names, NULL if none
item_listSELECT list of underlying query expression
gen_unique_view_nameSee description.
  • If a list of column names has been provided: it is simply searched for duplicates (which cause an error).
  • otherwise, column names are derived from the underlying query expression's SELECT list elements; if two of those elements have duplicate autogenerated names: if gen_unique_view_name is false: error it it is true: we generate a unique name using make_unique_view_field_name()
Returns
true if error.

◆ check_key_in_view()

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

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.

Parameters
thdthread handler
viewview for check with opened table
table_refunderlying updatable table of the view
Returns
false is success, true if error

◆ create_view_precheck()

bool create_view_precheck ( THD thd,
Table_ref tables,
Table_ref view,
enum_view_create_mode  mode 
)

CREATE VIEW privileges pre-check.

Parameters
thdthread handler
tablestables used in the view
viewviews to create
modeVIEW_CREATE_NEW, VIEW_ALTER, VIEW_CREATE_OR_REPLACE
Return values
falseOperation was a success.
trueAn error occurred.

◆ insert_view_fields()

bool insert_view_fields ( mem_root_deque< Item * > *  list,
Table_ref view 
)

◆ is_updatable_view()

bool is_updatable_view ( THD thd,
Table_ref view 
)
See also
Query_block::merge_derived()

◆ make_valid_column_names()

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.

Parameters
lexLEX for this thread.

◆ mysql_create_view()

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.

Parameters
thdthread handler
viewsviews to create
modeVIEW_CREATE_NEW, VIEW_ALTER, VIEW_CREATE_OR_REPLACE
Note
This function handles both create and alter view commands.
Return values
falseOperation was a success.
trueAn error occurred.

◆ mysql_drop_view()

bool mysql_drop_view ( THD thd,
Table_ref views 
)

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.

Parameters
[in]thdthread handler
[in]viewsviews to delete
Return values
falseOK
trueError

◆ mysql_register_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.

Parameters
thdThread handler.
viewView description
modeVIEW_CREATE_NEW, VIEW_ALTER or VIEW_CREATE_OR_REPLACE.
Note
The caller must rollback both statement and transaction on failure, before any further accesses to DD. This is because such a failure might be caused by a deadlock, which requires rollback before any other operations on SE (including reads using attachable transactions) can be done.
Return values
falseOK
trueError
See also
Item::print_for_order()

◆ open_and_read_view()

bool open_and_read_view ( THD thd,
TABLE_SHARE share,
Table_ref view_ref 
)

Open and read a view definition.

Parameters
[in]thdThread handler
[in]shareShare object of view
[in,out]view_refTable_ref structure for view reference
Returns
false-in case of success, true-in case of error.
Note
In case true value returned an error has been already set in DA.

◆ parse_view_definition()

bool parse_view_definition ( THD thd,
Table_ref view_ref 
)

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.

Parameters
[in]thdThread handler
[in,out]view_refTable_ref structure for view reference
Returns
false-in case of success, true-in case of error.
Note
In case true value returned an error has been already set in DA.