![]() |
MySQL 8.0.40
Source Code Documentation
|
#include "sql/sql_insert.h"
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <atomic>
#include <iterator>
#include <map>
#include <utility>
#include "field_types.h"
#include "lex_string.h"
#include "m_ctype.h"
#include "m_string.h"
#include "my_alloc.h"
#include "my_base.h"
#include "my_bitmap.h"
#include "my_dbug.h"
#include "my_psi_config.h"
#include "my_sys.h"
#include "my_table_map.h"
#include "my_thread_local.h"
#include "mysql/components/services/bits/psi_bits.h"
#include "mysql/mysql_lex_string.h"
#include "mysql/psi/mysql_table.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql_com.h"
#include "mysqld_error.h"
#include "pfs_table_provider.h"
#include "prealloced_array.h"
#include "sql/auth/auth_acls.h"
#include "sql/auth/auth_common.h"
#include "sql/binlog.h"
#include "sql/create_field.h"
#include "sql/dd/cache/dictionary_client.h"
#include "sql/dd/dd.h"
#include "sql/dd/dictionary.h"
#include "sql/dd_sql_view.h"
#include "sql/debug_sync.h"
#include "sql/derror.h"
#include "sql/discrete_interval.h"
#include "sql/field.h"
#include "sql/handler.h"
#include "sql/item.h"
#include "sql/key.h"
#include "sql/lock.h"
#include "sql/locked_tables_list.h"
#include "sql/mdl.h"
#include "sql/mysqld.h"
#include "sql/nested_join.h"
#include "sql/opt_explain.h"
#include "sql/opt_explain_format.h"
#include "sql/partition_info.h"
#include "sql/protocol.h"
#include "sql/query_options.h"
#include "sql/rpl_rli.h"
#include "sql/select_lex_visitor.h"
#include "sql/sql_alter.h"
#include "sql/sql_array.h"
#include "sql/sql_base.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_error.h"
#include "sql/sql_gipk.h"
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_resolver.h"
#include "sql/sql_select.h"
#include "sql/sql_show.h"
#include "sql/sql_table.h"
#include "sql/sql_view.h"
#include "sql/stateless_allocator.h"
#include "sql/system_variables.h"
#include "sql/table_trigger_dispatcher.h"
#include "sql/thd_raii.h"
#include "sql/transaction.h"
#include "sql/transaction_info.h"
#include "sql/trigger_def.h"
#include "sql/visible_fields.h"
#include "sql_string.h"
#include "template_utils.h"
#include "thr_lock.h"
Namespaces | |
namespace | dd |
The version of the current data dictionary table definitions. | |
Functions | |
static bool | check_view_insertability (THD *thd, Table_ref *view, const Table_ref *insert_table_ref) |
Additional check for insertability for VIEW. More... | |
static void | prepare_for_positional_update (TABLE *table, Table_ref *tables) |
Get extra info for tables we insert into. More... | |
static bool | check_single_table_insert (const mem_root_deque< Item * > &fields, Table_ref *view, Table_ref **insert_table_ref) |
Check that insert fields are from a single table of a multi-table view. More... | |
static bool | check_insert_fields (THD *thd, Table_ref *table_list, mem_root_deque< Item * > *fields) |
Check insert fields. More... | |
static bool | check_valid_table_refs (const Table_ref *view, const mem_root_deque< Item * > &values, table_map map) |
Check that table references are restricted to the supplied table map. More... | |
bool | validate_default_values_of_unset_fields (THD *thd, TABLE *table) |
Validates default value of fields which are not specified in the column list of INSERT statement. More... | |
void | prepare_triggers_for_insert_stmt (THD *thd, TABLE *table) |
Prepare triggers for INSERT-like statement. More... | |
static bool | mysql_prepare_blob_values (THD *thd, const mem_root_deque< Item * > &fields, MEM_ROOT *mem_root) |
Setup data for field BLOB/GEOMETRY field types for execution of "INSERT...UPDATE" statement. More... | |
static bool | fix_join_cond_for_insert (THD *thd, Table_ref *tr) |
Recursive helper function for resolving join conditions for insertion into view for prepared statements. More... | |
static bool | allocate_column_bitmap (THD *thd, TABLE *table, MY_BITMAP **bitmap) |
static bool | last_uniq_key (TABLE *table, uint keynr) |
Check if there are more unique keys after the current one. More... | |
bool | write_record (THD *thd, TABLE *table, COPY_INFO *info, COPY_INFO *update) |
Write a record to table with optional deletion of conflicting records, invoke proper triggers if needed. More... | |
bool | check_that_all_fields_are_given_values (THD *thd, TABLE *entry, Table_ref *table_list) |
Check that all fields with aren't null_fields are used. More... | |
static TABLE * | create_table_from_items (THD *thd, HA_CREATE_INFO *create_info, Table_ref *create_table, Alter_info *alter_info, const mem_root_deque< Item * > &items, handlerton **post_ddl_ht) |
Create table from lists of fields and items (or just return TABLE object for pre-opened existing table). More... | |
|
static |
Check insert fields.
thd | The current thread. |
table_list | The table for insert. |
fields | The insert fields. |
Resolved reference to base table is returned in lex->insert_table_leaf.
|
static |
Check that insert fields are from a single table of a multi-table view.
fields | The insert fields to be checked. | |
view | The view for insert. | |
[out] | insert_table_ref | Reference to table to insert into |
This function is called to check that the fields being inserted into are from a single base table. This must be checked when the table to be inserted into is a multi-table view.
Check that all fields with aren't null_fields are used.
thd | thread handler |
entry | table that's checked |
table_list | top-level table or view, used for generating error or warning message |
true | if all fields are given values |
|
static |
Check that table references are restricted to the supplied table map.
The check can be skipped if the supplied table is a base table.
view | Table being specified |
values | Values whose used tables are to be matched against table map |
map | Table map to match against |
|
static |
Additional check for insertability for VIEW.
A view is insertable if the following conditions are true:
thd | thread handler | |
[in,out] | view | reference to view being inserted into. view->contain_auto_increment is true if and only if the view contains an auto_increment field. |
insert_table_ref | reference to underlying table being inserted into |
false | if success |
true | if table is not insertable-into (no error is reported) |
|
static |
Create table from lists of fields and items (or just return TABLE object for pre-opened existing table).
Used by CREATE SELECT.
Let "source table" be the table in the SELECT part.
Let "source table columns" be the set of columns in the SELECT list.
An interesting peculiarity in the syntax CREATE TABLE (<columns>) SELECT is that function defaults are stripped from the the source table columns, but not from the additional columns defined in the CREATE TABLE part. The first TIMESTAMP
column there is also subject to promotion to TIMESTAMP
DEFAULT
CURRENT_TIMESTAMP
ON
UPDATE
CURRENT_TIMESTAMP
, as usual.
[in] | thd | Thread object |
[in] | create_info | Create information (like MAX_ROWS, ENGINE or temporary table flag) |
[in] | create_table | Pointer to Table_ref object providing database and name for table to be created or to be open |
[in,out] | alter_info | Initial list of columns and indexes for the table to be created |
[in] | items | The source table columns. Corresponding column definitions (Create_field's) will be added to the end of alter_info->create_list. |
[out] | post_ddl_ht | Set to handlerton for table's SE, if this SE supports atomic DDL, so caller can call SE post DDL hook after committing transaction. |
non-zero | Pointer to TABLE object for table created or opened |
0 | Error |
Recursive helper function for resolving join conditions for insertion into view for prepared statements.
thd | Thread handler |
tr | Table structure which is traversed recursively |
Check if there are more unique keys after the current one.
table | table that keys are checked for |
keynr | current key number |
|
static |
Setup data for field BLOB/GEOMETRY field types for execution of "INSERT...UPDATE" statement.
For a expression in 'UPDATE' clause like "a= VALUES(a)", let as call Field* referring 'a' as LHS_FIELD and Field* referring field 'a' in "VALUES(a)" as RHS_FIELD
This function creates a separate copy of the blob value for RHS_FIELD, if the field is updated as well as accessed through VALUES() function in 'UPDATE' clause of "INSERT...UPDATE" statement.
[in] | thd | Pointer to THD object. |
[in] | fields | List of fields representing LHS_FIELD of all expressions in 'UPDATE' clause. |
[in] | mem_root | MEM_ROOT for blob copy. |
false | Success |
true | Failure |
Get extra info for tables we insert into.
table | table(TABLE object) we insert into, might be NULL in case of view |
tables | (Table_ref object) or view we insert into |
Prepare triggers for INSERT-like statement.
thd | Thread handler |
table | Table to which insert will happen |
Validates default value of fields which are not specified in the column list of INSERT statement.
thd | thread context |
table | table to which values are inserted. |
Write a record to table with optional deletion of conflicting records, invoke proper triggers if needed.
thd | thread context |
table | table to which record should be written |
info | COPY_INFO structure describing handling of duplicates and which is used for counting number of records inserted and deleted. |
update | COPY_INFO structure describing the UPDATE part (only used for INSERT ON DUPLICATE KEY UPDATE) |
Once this record is written to the table buffer, any AFTER INSERT trigger will be invoked. If instead of inserting a new record we end up updating an old one, both ON UPDATE triggers will fire instead. Similarly both ON DELETE triggers will be invoked if are to delete conflicting records.
Call thd->transaction.stmt.mark_modified_non_trans_table() if table is a non-transactional table.
< Flag for fatal errors