InnoDB Plugin  1.0
Data Structures | Macros | Functions | Variables
row0mysql.h File Reference
#include "univ.i"
#include "data0data.h"
#include "que0types.h"
#include "dict0types.h"
#include "trx0types.h"
#include "row0types.h"
#include "btr0pcur.h"
#include "row0mysql.ic"
Include dependency graph for row0mysql.h:
This graph shows which files directly or indirectly include this file:

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_trow_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_trow_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_trow_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

Detailed Description

Interface between Innobase row operations and MySQL. Contains also create table and other data dictionary operations.

Created 9/17/2000 Heikki Tuuri

Macro Definition Documentation

#define ROW_MYSQL_DUMMY_TEMPLATE
Value:
3 /* dummy template used in
row_scan_and_check_index */

Function Documentation

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.

Returns
true if ok
Parameters
prebuiltin: prebuilt struct in MySQL handle
indexin: index
n_rowsout: 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.

Returns
error number or DB_SUCCESS
Parameters
indexin, own: index definition (will be freed)
trxin: transaction handle
field_lengthsin: 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.

Returns
own: a prebuilt struct in: length in bytes of a row in the MySQL format
Parameters
tablein: 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.

Returns
error code or DB_SUCCESS
Parameters
tablein, own: table definition (will be freed, or on DB_SUCCESS added to the data dictionary cache)
trxin/out: transaction
commitin: 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.

Returns
own: update node in: mem heap from which allocated
Parameters
tablein: table to update
UNIV_INTERN dberr_t row_discard_tablespace_for_mysql ( const char *  name,
trx_t trx 
)

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.

Returns
error code or DB_SUCCESS
Parameters
namein: table name
trxin: transaction handle
UNIV_INTERN dberr_t row_drop_database_for_mysql ( const char *  name,
trx_t trx 
)

Drops a database for MySQL.

Returns
error code or DB_SUCCESS
Parameters
namein: database name which ends to '/'
trxin: 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.

Returns
error code or DB_SUCCESS
Parameters
namein: table name
trxin: dictionary transaction handle
drop_dbin: true=dropping whole database
nonatomicin: 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.

Returns
how many tables dropped + remaining tables in list
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!

Returns
how many tables in list
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.

Returns
prebuilt update vector in: prebuilt struct in MySQL handle
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.

Returns
error code or DB_SUCCESS
Parameters
tablein/out: table
prebuiltin: prebuilt struct in MySQL
UNIV_INTERN dberr_t row_insert_for_mysql ( byte *  mysql_rec,
row_prebuilt_t prebuilt 
)

Does an insert for MySQL.

Returns
error code or DB_SUCCESS
Parameters
mysql_recin: row in the MySQL format
prebuiltin: 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.

Returns
true if monitor table
Parameters
table_namein: 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.

Returns
true if temporary table in: table name in the form 'database/tablename'
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.

Returns
error code or DB_SUCCESS
Parameters
prebuiltin: 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.

Returns
error code or DB_SUCCESS
Parameters
prebuiltin: prebuilt struct in the MySQL table handle
tablein: table to lock, or NULL if prebuilt->table should be locked as prebuilt->select_lock_type
modein: 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

Parameters
trxin/out: transaction
filein: 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.

Returns
true if it was a lock wait and we should continue running the query thread
Parameters
new_errout: possible new error encountered in rollback, or the old error which was during the function entry
trxin: transaction
thrin: query thread, or NULL
saveptin: 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

Parameters
trxin/out: transaction
filein: 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.

Returns
error code or DB_SUCCESS
Parameters
trxin/out: transaction
tablein: table to lock
modein: LOCK_X or LOCK_S
op_infoin: 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

Parameters
mbminlenin: minimum size of a character, in bytes
padout: 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.

Returns
pointer to BLOB data in: BLOB reference length (not BLOB length)
Parameters
lenout: BLOB length
refin: 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.

Returns
pointer to the data, we skip the 1 or 2 bytes at the start that are used to store the len in: storage length of len: either 1 or 2 bytes
Parameters
lenout: variable-length field length
fieldin: 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!

Parameters
destin: where to store
col_lenin: 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
datain: 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.

Returns
up to which byte we used buf in the conversion in: nonzero=compact format
Parameters
dfieldin/out: dfield where dtype information must be already set when this function is called!
bufin/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_colTRUE 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_datain: 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_lenin: 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.

Returns
pointer to the data, we skip the 1 or 2 bytes at the start that are used to store the len in: storage length of len: either 1 or 2 bytes
Parameters
destin: where to store
lenin: 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.

Returns
error code or DB_SUCCESS
Parameters
tablein/out: table
trxin/out: transaction
new_idout: 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

Parameters
prebuiltin, 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.

Returns
error code or DB_SUCCESS
Parameters
old_namein: old table name
new_namein: new table name
trxin/out: transaction
commitin: 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.

Returns
error code or DB_SUCCESS
Parameters
trxin: transaction
sql_stringin: 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_lengthin: length of sql_string
namein: table full name in the normalized form database_name/table_name
reject_fksin: 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).

Returns
TRUE if the clustered index was generated automatically in: table
UNIV_INTERN dberr_t row_truncate_table_for_mysql ( dict_table_t table,
trx_t trx 
)

Truncates a table for MySQL.

Returns
error code or DB_SUCCESS
Parameters
tablein: table handle
trxin: 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.

Parameters
prebuiltin/out: prebuilt struct in MySQL handle
has_latches_on_recsin: 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.

Returns
error code or DB_SUCCESS
Parameters
thrin: query thread
nodein: update node used in the cascade or set null operation
tablein: 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.

Returns
error code or DB_SUCCESS
Parameters
mysql_recin: the row to be updated, in the MySQL format
prebuiltin: 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

Parameters
prebuiltin/out: prebuilt struct in MySQL handle