MySQL 5.6.14 Source Code Document
|
#include "row0mysql.h"
#include <debug_sync.h>
#include <my_dbug.h>
#include "row0ins.h"
#include "row0merge.h"
#include "row0sel.h"
#include "row0upd.h"
#include "row0row.h"
#include "que0que.h"
#include "pars0pars.h"
#include "dict0dict.h"
#include "dict0crea.h"
#include "dict0load.h"
#include "dict0boot.h"
#include "dict0stats.h"
#include "dict0stats_bg.h"
#include "trx0roll.h"
#include "trx0purge.h"
#include "trx0rec.h"
#include "trx0undo.h"
#include "lock0lock.h"
#include "rem0cmp.h"
#include "log0log.h"
#include "btr0sea.h"
#include "fil0fil.h"
#include "ibuf0ibuf.h"
#include "fts0fts.h"
#include "fts0types.h"
#include "srv0start.h"
#include "row0import.h"
#include "m_string.h"
#include "my_sys.h"
#include "ha_prototypes.h"
Go to the source code of this file.
Classes | |
struct | row_mysql_drop_t |
Macros | |
#define | STR_EQ(str1, str1_len, str2_onstack) |
#define | PREBUILT_HEAP_INITIAL_SIZE |
#define | TABLE_NOT_IN_THIS_DB "SUBSTR(for_name, 0, LENGTH(:dbname)) <> :dbname" |
Variables | |
UNIV_INTERN ibool | row_rollback_on_timeout = FALSE |
Interface between Innobase row operations and MySQL. Contains also create table and other data dictionary operations.
Created 9/17/2000 Heikki Tuuri
Definition in file row0mysql.cc.
#define PREBUILT_HEAP_INITIAL_SIZE |
#define STR_EQ | ( | str1, | |
str1_len, | |||
str2_onstack | |||
) |
Evaluates to true if str1 equals str2_onstack, used for comparing
the magic table names.
str1 | in: string to compare |
str1_len | in: length of str1, in bytes, including terminating NUL |
str2_onstack | in: char[] array containing a NUL terminated string |
Definition at line 112 of file row0mysql.cc.
UNIV_INTERN dberr_t row_create_index_for_mysql | ( | dict_index_t * | index, |
trx_t * | trx, | ||
const ulint * | field_lengths | ||
) |
Does an index creation operation for MySQL. TODO: currently failure to create an index results in dropping the whole table! This is no problem currently as all indexes must be created at the same time as the table.
index | in, own: index definition (will be freed) |
trx | in: transaction handle |
field_lengths | in: if not NULL, must contain dict_index_get_n_fields(index) actual field lengths for the index columns, which are then checked for not being too large. |
Definition at line 2350 of file row0mysql.cc.
UNIV_INTERN row_prebuilt_t* row_create_prebuilt | ( | dict_table_t * | table, |
ulint | mysql_row_len | ||
) |
Create a prebuilt struct for a MySQL table handle.
table | in: Innobase table handle |
mysql_row_len | in: length in bytes of a row in the MySQL format |
Definition at line 704 of file row0mysql.cc.
UNIV_INTERN dberr_t row_create_table_for_mysql | ( | dict_table_t * | table, |
trx_t * | trx, | ||
bool | commit | ||
) |
Creates a table for MySQL. If the name of the table ends in one of "innodb_monitor", "innodb_lock_monitor", "innodb_tablespace_monitor", "innodb_table_monitor", then this will also start the printing of monitor output by the master thread. If the table name ends in "innodb_mem_validate", InnoDB will try to invoke mem_validate(). On failure the transaction will be rolled back and the 'table' object will be freed.
table | in, own: table definition (will be freed, or on DB_SUCCESS added to the data dictionary cache) |
trx | in/out: transaction |
commit | in: if true, commit the transaction |
Definition at line 2116 of file row0mysql.cc.
UNIV_INTERN upd_node_t* row_create_update_node_for_mysql | ( | dict_table_t * | table, |
mem_heap_t * | heap | ||
) |
Creates an query graph node of 'update' type to be used in the MySQL interface.
table | in: table to update |
heap | in: mem heap from which allocated |
Definition at line 1439 of file row0mysql.cc.
Discards the tablespace of a table which stored in an .ibd file. Discarding means that this function renames the .ibd file and assigns a new table id for the table. Also the flag table->ibd_file_missing is set to TRUE.
name | in: table name |
trx | in: transaction handle |
Definition at line 3019 of file row0mysql.cc.
UNIV_INTERN dberr_t row_drop_table_for_mysql | ( | const char * | name, |
trx_t * | trx, | ||
bool | drop_db, | ||
bool | nonatomic | ||
) |
Drops a table for MySQL. If the name of the dropped table ends in one of "innodb_monitor", "innodb_lock_monitor", "innodb_tablespace_monitor", "innodb_table_monitor", then this will also stop the printing of monitor output by the master thread. If the data dictionary was not already locked by the transaction, the transaction will be committed. Otherwise, the data dictionary will remain locked.
name | in: table name |
trx | in: transaction handle |
drop_db | in: true=dropping whole database |
nonatomic | in: whether it is permitted to release and reacquire dict_operation_lock |
Definition at line 3653 of file row0mysql.cc.
UNIV_INTERN ulint row_drop_tables_for_mysql_in_background | ( | void | ) |
The master thread in srv0srv.cc calls this regularly to drop tables which we must drop in background after queries to them have ended. Such lazy dropping of tables is needed in ALTER TABLE on Unix.
Definition at line 2597 of file row0mysql.cc.
UNIV_INTERN ulint row_get_background_drop_list_len_low | ( | void | ) |
Get the background drop list length. NOTE: the caller must own the drop list mutex!
Definition at line 2672 of file row0mysql.cc.
UNIV_INTERN upd_t* row_get_prebuilt_update_vector | ( | row_prebuilt_t * | prebuilt | ) |
Gets pointer to a prebuilt update vector used in updates. If the update graph has not yet been built in the prebuilt struct, then this function first builds it.
prebuilt | in: prebuilt struct in MySQL handle |
Definition at line 1476 of file row0mysql.cc.
UNIV_INTERN dberr_t row_insert_for_mysql | ( | byte * | mysql_rec, |
row_prebuilt_t * | prebuilt | ||
) |
Does an insert for MySQL.
mysql_rec | in: row in the MySQL format |
prebuilt | in: prebuilt struct in MySQL handle |
Definition at line 1227 of file row0mysql.cc.
UNIV_INTERN dberr_t row_lock_table_autoinc_for_mysql | ( | row_prebuilt_t * | prebuilt | ) |
Sets an AUTO_INC type lock on the table mentioned in prebuilt. The AUTO_INC lock gives exclusive access to the auto-inc counter of the table. The lock is reserved only for the duration of an SQL statement. It is not compatible with another AUTO_INC or exclusive lock on the table.
prebuilt | in: prebuilt struct in the MySQL table handle |
Definition at line 1073 of file row0mysql.cc.
UNIV_INTERN dberr_t row_lock_table_for_mysql | ( | row_prebuilt_t * | prebuilt, |
dict_table_t * | table, | ||
ulint | mode | ||
) |
Sets a table lock on the table mentioned in prebuilt.
prebuilt | in: prebuilt struct in the MySQL table handle |
table | in: table to lock, or NULL if prebuilt->table should be locked as prebuilt->select_lock_type |
mode | in: lock mode of table (ignored if table==NULL) |
Definition at line 1146 of file row0mysql.cc.
UNIV_INTERN void row_mysql_drop_temp_tables | ( | void | ) |
Drop all temporary tables during crash recovery.
Definition at line 4317 of file row0mysql.cc.
UNIV_INTERN void row_mysql_freeze_data_dictionary_func | ( | trx_t * | trx, |
const char * | file, | ||
ulint | line | ||
) |
Locks the data dictionary in shared mode from modifications, for performing foreign key check, rollback, or other operation invisible to MySQL.
trx | in/out: transaction |
file | in: file name |
line | in: line number |
Definition at line 2032 of file row0mysql.cc.
UNIV_INTERN bool row_mysql_handle_errors | ( | dberr_t * | new_err, |
trx_t * | trx, | ||
que_thr_t * | thr, | ||
trx_savept_t * | savept | ||
) |
Handles user errors and lock waits detected by the database engine.
new_err | out: possible new error encountered in lock wait, or if no new error, the value of trx->error_state at the entry of this function |
trx | in: transaction |
thr | in: query thread, or NULL |
savept | in: savepoint, or NULL |
Definition at line 582 of file row0mysql.cc.
UNIV_INTERN void row_mysql_lock_data_dictionary_func | ( | trx_t * | trx, |
const char * | file, | ||
ulint | line | ||
) |
Locks the data dictionary exclusively for performing a table create or other data dictionary modification operation.
trx | in/out: transaction |
file | in: file name |
line | in: line number |
Definition at line 2067 of file row0mysql.cc.
UNIV_INTERN dberr_t row_mysql_lock_table | ( | trx_t * | trx, |
dict_table_t * | table, | ||
enum lock_mode | mode, | ||
const char * | op_info | ||
) |
Sets an exclusive lock on a table.
trx | in/out: transaction |
table | in: table to lock |
mode | in: LOCK_X or LOCK_S |
op_info | in: string for trx->op_info |
Definition at line 3073 of file row0mysql.cc.
UNIV_INTERN void row_mysql_pad_col | ( | ulint | mbminlen, |
byte * | pad, | ||
ulint | len | ||
) |
Pad a column with spaces.
mbminlen | in: minimum size of a character, in bytes |
pad | out: padded buffer |
len | in: number of bytes to pad |
Definition at line 292 of file row0mysql.cc.
UNIV_INTERN void row_mysql_prebuilt_free_blob_heap | ( | row_prebuilt_t * | prebuilt | ) |
Frees the blob heap in prebuilt when no longer needed.
prebuilt | in: prebuilt struct of a ha_innobase:: table handle |
Definition at line 164 of file row0mysql.cc.
UNIV_INTERN const byte* row_mysql_read_blob_ref | ( | ulint * | len, |
const byte * | ref, | ||
ulint | col_len | ||
) |
Reads a reference to a BLOB in the MySQL format.
len | out: BLOB length |
ref | in: BLOB reference in the MySQL format |
col_len | in: BLOB reference length (not BLOB length) |
Definition at line 271 of file row0mysql.cc.
UNIV_INTERN const byte* row_mysql_read_true_varchar | ( | ulint * | len, |
const byte * | field, | ||
ulint | lenlen | ||
) |
Reads a >= 5.0.3 format true VARCHAR length, in the MySQL row format, and returns a pointer to the data.
len | out: variable-length field length |
field | in: field in the MySQL format |
lenlen | in: storage length of len: either 1 or 2 bytes |
Definition at line 209 of file row0mysql.cc.
UNIV_INTERN void row_mysql_store_blob_ref | ( | byte * | dest, |
ulint | col_len, | ||
const void * | data, | ||
ulint | len | ||
) |
Stores a reference to a BLOB in the MySQL format.
dest | in: where to store |
col_len | in: dest buffer size: determines into how many bytes the BLOB length is stored, the space for the length may vary from 1 to 4 bytes |
data | in: BLOB data; if the value to store is SQL NULL this should be NULL pointer |
len | in: BLOB length; if the value to store is SQL NULL this should be 0; remember also to set the NULL bit in the MySQL record header! |
Definition at line 233 of file row0mysql.cc.
UNIV_INTERN byte* row_mysql_store_col_in_innobase_format | ( | dfield_t * | dfield, |
byte * | buf, | ||
ibool | row_format_col, | ||
const byte * | mysql_data, | ||
ulint | col_len, | ||
ulint | comp | ||
) |
Stores a non-SQL-NULL field given in the MySQL format in the InnoDB format. The counterpart of this function is row_sel_field_store_in_mysql_format() in row0sel.cc.
dfield | in/out: dfield where dtype information must be already set when this function is called! |
buf | in/out: buffer for a converted integer value; this must be at least col_len long then! NOTE that dfield may also get a pointer to 'buf', therefore do not discard this as long as dfield is used! |
row_format_col | TRUE if the mysql_data is from a MySQL row, FALSE if from a MySQL key value; in MySQL, a true VARCHAR storage format differs in a row and in a key value: in a key value the length is always stored in 2 bytes! |
mysql_data | in: MySQL column value, not SQL NULL; NOTE that dfield may also get a pointer to mysql_data, therefore do not discard this as long as dfield is used! |
col_len | in: MySQL column length; NOTE that this is the storage length of the column in the MySQL format row, not necessarily the length of the actual payload data; if the column is a true VARCHAR then this is irrelevant |
comp | in: nonzero=compact format |
Definition at line 338 of file row0mysql.cc.
UNIV_INTERN byte* row_mysql_store_true_var_len | ( | byte * | dest, |
ulint | len, | ||
ulint | lenlen | ||
) |
Stores a >= 5.0.3 format true VARCHAR length to dest, in the MySQL row format.
dest | in: where to store |
len | in: length, must fit in two bytes |
lenlen | in: storage length of len: either 1 or 2 bytes |
Definition at line 180 of file row0mysql.cc.
UNIV_INTERN dberr_t row_mysql_table_id_reassign | ( | dict_table_t * | table, |
trx_t * | trx, | ||
table_id_t * | new_id | ||
) |
Reassigns the table identifier of a table.
table | in/out: table |
trx | in/out: transaction |
new_id | out: new table id |
Definition at line 2744 of file row0mysql.cc.
UNIV_INTERN void row_mysql_unfreeze_data_dictionary | ( | trx_t * | trx | ) |
Unlocks the data dictionary shared lock.
trx | in/out: transaction |
Definition at line 2049 of file row0mysql.cc.
UNIV_INTERN void row_mysql_unlock_data_dictionary | ( | trx_t * | trx | ) |
Unlocks the data dictionary exclusive lock.
trx | in/out: transaction |
Definition at line 2089 of file row0mysql.cc.
UNIV_INTERN void row_prebuild_sel_graph | ( | row_prebuilt_t * | prebuilt | ) |
Builds a dummy query graph used in selects.
prebuilt | in: prebuilt struct in MySQL handle |
Definition at line 1410 of file row0mysql.cc.
UNIV_INTERN void row_prebuilt_free | ( | row_prebuilt_t * | prebuilt, |
ibool | dict_locked | ||
) |
Free a prebuilt struct for a MySQL table handle.
prebuilt | in, own: prebuilt struct |
dict_locked | in: TRUE=data dictionary locked |
Definition at line 803 of file row0mysql.cc.
UNIV_INTERN dberr_t row_table_add_foreign_constraints | ( | trx_t * | trx, |
const char * | sql_string, | ||
size_t | sql_length, | ||
const char * | name, | ||
ibool | reject_fks | ||
) |
Scans a table create SQL string and adds to the data dictionary the foreign key constraints declared in the string. This function should be called after the indexes for a table have been created. Each foreign key constraint must be accompanied with indexes in both participating tables. The indexes are allowed to contain more fields than mentioned in the constraint. Check also that foreign key constraints which reference this table are ok.
trx | in: transaction |
sql_string | in: table create statement where foreign keys are declared like: FOREIGN KEY (a, b) REFERENCES table2(c, d), table2 can be written also with the database name before it: test.table2 |
sql_length | in: length of sql_string |
name | in: table full name in the normalized form database_name/table_name |
reject_fks | in: if TRUE, fail with error code DB_CANNOT_ADD_CONSTRAINT if any foreign keys are found. |
Definition at line 2483 of file row0mysql.cc.
UNIV_INTERN ibool row_table_got_default_clust_index | ( | const dict_table_t * | table | ) |
Checks if a table is such that we automatically created a clustered index on it (on row id).
table | in: table |
Definition at line 2016 of file row0mysql.cc.
UNIV_INTERN dberr_t row_truncate_table_for_mysql | ( | dict_table_t * | table, |
trx_t * | trx | ||
) |
Truncates a table for MySQL.
table | in: table handle |
trx | in: transaction handle |
Definition at line 3156 of file row0mysql.cc.
UNIV_INTERN void row_unlock_for_mysql | ( | row_prebuilt_t * | prebuilt, |
ibool | has_latches_on_recs | ||
) |
This can only be used when srv_locks_unsafe_for_binlog is TRUE or this session is using a READ COMMITTED or READ UNCOMMITTED isolation level. Before calling this function row_search_for_mysql() must have initialized prebuilt->new_rec_locks to store the information which new record locks really were set. This function removes a newly set clustered index record lock under prebuilt->pcur or prebuilt->clust_pcur. Thus, this implements a 'mini-rollback' that releases the latest clustered index record lock we set.
prebuilt | in/out: prebuilt struct in MySQL handle |
has_latches_on_recs | in: TRUE if called so that we have the latches on the records under pcur and clust_pcur, and we do not need to reposition the cursors. |
Definition at line 1803 of file row0mysql.cc.
UNIV_INTERN dberr_t row_update_cascade_for_mysql | ( | que_thr_t * | thr, |
upd_node_t * | node, | ||
dict_table_t * | table | ||
) |
Does a cascaded delete or set null in a foreign key operation.
thr | in: query thread |
node | in: update node used in the cascade or set null operation |
table | in: table where we do the operation |
Definition at line 1927 of file row0mysql.cc.
UNIV_INTERN dberr_t row_update_for_mysql | ( | byte * | mysql_rec, |
row_prebuilt_t * | prebuilt | ||
) |
Does an update or delete of a row for MySQL.
mysql_rec | in: the row to be updated, in the MySQL format |
prebuilt | in: prebuilt struct in MySQL handle |
Definition at line 1604 of file row0mysql.cc.
UNIV_INTERN void row_update_prebuilt_trx | ( | row_prebuilt_t * | prebuilt, |
trx_t * | trx | ||
) |
Updates the transaction pointers in query graphs stored in the prebuilt struct.
prebuilt | in/out: prebuilt struct in MySQL handle |
trx | in: transaction handle |
Definition at line 901 of file row0mysql.cc.
UNIV_INLINE void row_update_statistics_if_needed | ( | dict_table_t * | table | ) |
Updates the table modification counter and calculates new estimates for table and index statistics if necessary.
table | in: table |
Definition at line 1022 of file row0mysql.cc.
UNIV_INTERN ibool row_rollback_on_timeout = FALSE |
Provide optional 4.x backwards compatibility for 5.0 and above
Definition at line 68 of file row0mysql.cc.