InnoDB Plugin
1.0
|
#include "univ.i"
#include "data0data.h"
#include "que0types.h"
#include "dict0types.h"
#include "trx0types.h"
#include "row0types.h"
#include "btr0pcur.h"
#include "row0mysql.ic"
Go to the source code of this file.
Data Structures | |
struct | mysql_row_templ_t |
struct | row_prebuilt_t |
struct | SysIndexCallback |
Macros | |
#define | row_mysql_lock_data_dictionary(trx) row_mysql_lock_data_dictionary_func(trx, __FILE__, __LINE__) |
#define | row_mysql_freeze_data_dictionary(trx) row_mysql_freeze_data_dictionary_func(trx, __FILE__, __LINE__) |
#define | MYSQL_FETCH_CACHE_SIZE 8 |
#define | MYSQL_FETCH_CACHE_THRESHOLD 4 |
#define | ROW_PREBUILT_ALLOCATED 78540783 |
#define | ROW_PREBUILT_FREED 26423527 |
#define | ROW_PREBUILT_FETCH_MAGIC_N 465765687 |
#define | ROW_MYSQL_WHOLE_ROW 0 |
#define | ROW_MYSQL_REC_FIELDS 1 |
#define | ROW_MYSQL_NO_TEMPLATE 2 |
#define | ROW_MYSQL_DUMMY_TEMPLATE |
#define | ROW_RETRIEVE_PRIMARY_KEY 1 |
#define | ROW_RETRIEVE_ALL_COLS 2 |
#define | ROW_READ_WITH_LOCKS 0 |
#define | ROW_READ_TRY_SEMI_CONSISTENT 1 |
#define | ROW_READ_DID_SEMI_CONSISTENT 2 |
Functions | |
UNIV_INTERN void | row_mysql_prebuilt_free_blob_heap (row_prebuilt_t *prebuilt) |
UNIV_INTERN byte * | row_mysql_store_true_var_len (byte *dest, ulint len, ulint lenlen) |
UNIV_INTERN const byte * | row_mysql_read_true_varchar (ulint *len, const byte *field, ulint lenlen) |
UNIV_INTERN void | row_mysql_store_blob_ref (byte *dest, ulint col_len, const void *data, ulint len) |
UNIV_INTERN const byte * | row_mysql_read_blob_ref (ulint *len, const byte *ref, ulint col_len) |
UNIV_INTERN void | row_mysql_pad_col (ulint mbminlen, byte *pad, ulint len) |
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) |
UNIV_INTERN bool | row_mysql_handle_errors (dberr_t *new_err, trx_t *trx, que_thr_t *thr, trx_savept_t *savept))) |
UNIV_INTERN row_prebuilt_t * | row_create_prebuilt (dict_table_t *table, ulint mysql_row_len) |
UNIV_INTERN void | row_prebuilt_free (row_prebuilt_t *prebuilt, ibool dict_locked) |
UNIV_INTERN void | row_update_prebuilt_trx (row_prebuilt_t *prebuilt, trx_t *trx) |
UNIV_INTERN dberr_t | row_lock_table_autoinc_for_mysql (row_prebuilt_t *prebuilt)) |
UNIV_INTERN dberr_t | row_lock_table_for_mysql (row_prebuilt_t *prebuilt, dict_table_t *table, ulint mode))) |
UNIV_INTERN dberr_t | row_insert_for_mysql (byte *mysql_rec, row_prebuilt_t *prebuilt)) |
UNIV_INTERN void | row_prebuild_sel_graph (row_prebuilt_t *prebuilt) |
UNIV_INTERN upd_t * | row_get_prebuilt_update_vector (row_prebuilt_t *prebuilt) |
UNIV_INTERN ibool | row_table_got_default_clust_index (const dict_table_t *table) |
UNIV_INTERN dberr_t | row_update_for_mysql (byte *mysql_rec, row_prebuilt_t *prebuilt)) |
UNIV_INTERN void | row_unlock_for_mysql (row_prebuilt_t *prebuilt, ibool has_latches_on_recs)) |
UNIV_INTERN bool | row_is_mysql_tmp_table_name (const char *name)) |
UNIV_INTERN upd_node_t * | row_create_update_node_for_mysql (dict_table_t *table, mem_heap_t *heap) |
UNIV_INTERN dberr_t | row_update_cascade_for_mysql (que_thr_t *thr, upd_node_t *node, dict_table_t *table)) |
UNIV_INTERN void | row_mysql_lock_data_dictionary_func (trx_t *trx, const char *file, ulint line) |
UNIV_INTERN void | row_mysql_unlock_data_dictionary (trx_t *trx) |
UNIV_INTERN void | row_mysql_freeze_data_dictionary_func (trx_t *trx, const char *file, ulint line) |
UNIV_INTERN void | row_mysql_unfreeze_data_dictionary (trx_t *trx) |
UNIV_INTERN dberr_t | row_create_table_for_mysql (dict_table_t *table, trx_t *trx, bool commit)) |
UNIV_INTERN dberr_t | row_create_index_for_mysql (dict_index_t *index, trx_t *trx, const ulint *field_lengths) |
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)) |
UNIV_INTERN ulint | row_drop_tables_for_mysql_in_background (void) |
UNIV_INTERN ulint | row_get_background_drop_list_len_low (void) |
UNIV_INTERN dberr_t | row_mysql_lock_table (trx_t *trx, dict_table_t *table, enum lock_mode mode, const char *op_info)) |
UNIV_INTERN dberr_t | row_truncate_table_for_mysql (dict_table_t *table, trx_t *trx)) |
UNIV_INTERN dberr_t | row_drop_table_for_mysql (const char *name, trx_t *trx, bool drop_db, bool nonatomic=true)) |
UNIV_INTERN void | row_mysql_drop_temp_tables (void) |
UNIV_INTERN dberr_t | row_discard_tablespace_for_mysql (const char *name, trx_t *trx)) |
UNIV_INTERN dberr_t | row_import_tablespace_for_mysql (dict_table_t *table, row_prebuilt_t *prebuilt)) |
UNIV_INTERN dberr_t | row_drop_database_for_mysql (const char *name, trx_t *trx)) |
UNIV_INTERN dberr_t | row_rename_table_for_mysql (const char *old_name, const char *new_name, trx_t *trx, bool commit)) |
UNIV_INTERN bool | row_check_index_for_mysql (row_prebuilt_t *prebuilt, const dict_index_t *index, ulint *n_rows)) |
UNIV_INTERN bool | row_is_magic_monitor_table (const char *table_name)) |
UNIV_INTERN void | row_mysql_init (void) |
UNIV_INTERN void | row_mysql_close (void) |
UNIV_INTERN dberr_t | row_mysql_table_id_reassign (dict_table_t *table, trx_t *trx, table_id_t *new_id)) |
Variables | |
ibool | row_rollback_on_timeout |
UNIV_INTERN dberr_t | warn_unused_result |
Interface between Innobase row operations and MySQL. Contains also create table and other data dictionary operations.
Created 9/17/2000 Heikki Tuuri
#define ROW_MYSQL_DUMMY_TEMPLATE |
UNIV_INTERN bool row_check_index_for_mysql | ( | row_prebuilt_t * | prebuilt, |
const dict_index_t * | index, | ||
ulint * | n_rows | ||
) |
Checks that the index contains entries in an ascending order, unique constraint is not broken, and calculates the number of index entries in the read view of the current transaction.
prebuilt | in: prebuilt struct in MySQL handle |
index | in: index |
n_rows | out: number of entries seen in the consistent read |
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. |
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 |
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.
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 |
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 |
Discards the tablespace of a table which stored in an .ibd file. Discarding means that this function deletes the .ibd file and assigns a new table id for the table. Also the flag table->ibd_file_missing is set TRUE.
name | in: table name |
trx | in: transaction handle |
Drops a database for MySQL.
name | in: database name which ends to '/' |
trx | in: transaction handle |
UNIV_INTERN dberr_t row_drop_table_for_mysql | ( | const char * | name, |
trx_t * | trx, | ||
bool | drop_db, | ||
bool | nonatomic = true |
||
) |
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: dictionary transaction handle |
drop_db | in: true=dropping whole database |
nonatomic | in: whether it is permitted to release and reacquire dict_operation_lock |
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.
UNIV_INTERN ulint row_get_background_drop_list_len_low | ( | void | ) |
Get the background drop list length. NOTE: the caller must own the kernel mutex!
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.
UNIV_INTERN dberr_t row_import_tablespace_for_mysql | ( | dict_table_t * | table, |
row_prebuilt_t * | prebuilt | ||
) |
Imports a tablespace. The space id in the .ibd file must match the space id of the table in the data dictionary.
table | in/out: table |
prebuilt | in: prebuilt struct in MySQL |
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 |
UNIV_INTERN bool row_is_magic_monitor_table | ( | const char * | table_name | ) |
Determines if a table is a magic monitor table.
table_name | in: name of the table, in the form database/table_name |
UNIV_INTERN bool row_is_mysql_tmp_table_name | ( | const char * | name | ) |
Checks if a table name contains the string "/#sql" which denotes temporary tables in MySQL.
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 |
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) |
UNIV_INTERN void row_mysql_close | ( | void | ) |
Close this module
UNIV_INTERN void row_mysql_drop_temp_tables | ( | void | ) |
Drop all temporary tables during crash recovery.
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. in: line number
trx | in/out: transaction |
file | in: file name |
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 rollback, or the old error which was during the function entry |
trx | in: transaction |
thr | in: query thread, or NULL |
savept | in: savepoint, or NULL |
UNIV_INTERN void row_mysql_init | ( | void | ) |
Initialize this module
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. in: line number
trx | in/out: transaction |
file | in: file name |
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 |
UNIV_INTERN void row_mysql_pad_col | ( | ulint | mbminlen, |
byte * | pad, | ||
ulint | len | ||
) |
Pad a column with spaces. in: number of bytes to pad
mbminlen | in: minimum size of a character, in bytes |
pad | out: padded buffer |
UNIV_INTERN void row_mysql_prebuilt_free_blob_heap | ( | row_prebuilt_t * | prebuilt | ) |
Frees the blob heap in prebuilt when no longer needed. in: prebuilt struct of a ha_innobase:: table handle
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 |
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 |
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. 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!
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 |
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 |
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 |
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 |
UNIV_INTERN void row_mysql_unfreeze_data_dictionary | ( | trx_t * | trx | ) |
Unlocks the data dictionary shared lock. in/out: transaction
UNIV_INTERN void row_mysql_unlock_data_dictionary | ( | trx_t * | trx | ) |
Unlocks the data dictionary exclusive lock. in/out: transaction
UNIV_INTERN void row_prebuild_sel_graph | ( | row_prebuilt_t * | prebuilt | ) |
Builds a dummy query graph used in selects. in: prebuilt struct in MySQL handle
UNIV_INTERN void row_prebuilt_free | ( | row_prebuilt_t * | prebuilt, |
ibool | dict_locked | ||
) |
Free a prebuilt struct for a MySQL table handle. in: TRUE=data dictionary locked
prebuilt | in, own: prebuilt struct |
UNIV_INTERN dberr_t row_rename_table_for_mysql | ( | const char * | old_name, |
const char * | new_name, | ||
trx_t * | trx, | ||
bool | commit | ||
) |
Renames a table for MySQL.
old_name | in: old table name |
new_name | in: new table name |
trx | in/out: transaction |
commit | in: whether to commit trx |
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 bot participating tables. The indexes are allowed to contain more fields than mentioned in the constraint.
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. |
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).
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 |
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. |
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 |
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 |
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. in: transaction handle
prebuilt | in/out: prebuilt struct in MySQL handle |