InnoDB Plugin  1.0
Data Structures | Typedefs | Functions | Variables
row0merge.h File Reference
#include "univ.i"
#include "data0data.h"
#include "dict0types.h"
#include "trx0types.h"
#include "que0types.h"
#include "mtr0mtr.h"
#include "rem0types.h"
#include "rem0rec.h"
#include "read0types.h"
#include "btr0types.h"
#include "row0mysql.h"
#include "lock0types.h"
#include "srv0srv.h"
Include dependency graph for row0merge.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  mtuple_t
struct  row_merge_buf_t
struct  merge_file_t
struct  index_field_t
struct  index_def_t
struct  row_merge_dup_t

Typedefs

typedef byte row_merge_block_t
 Block size for I/O operations in merge sort.
typedef byte mrec_buf_t [UNIV_PAGE_SIZE_MAX]
 Secondary buffer for I/O operations of merge records.
typedef byte mrec_t
 Merge record in row_merge_block_t.

Functions

UNIV_INTERN void row_merge_dup_report (row_merge_dup_t *dup, const dfield_t *entry))
UNIV_INTERN dberr_t row_merge_lock_table (trx_t *trx, dict_table_t *table, enum lock_mode mode))
UNIV_INTERN void row_merge_drop_indexes_dict (trx_t *trx, table_id_t table_id))
UNIV_INTERN void row_merge_drop_indexes (trx_t *trx, dict_table_t *table, ibool locked))
UNIV_INTERN void row_merge_drop_temp_indexes (void)
UNIV_INTERN int row_merge_file_create_low (void))
UNIV_INTERN void row_merge_file_destroy_low (int fd)
UNIV_INTERN char * row_make_new_pathname (dict_table_t *table, const char *new_name)
UNIV_INTERN dberr_t row_merge_rename_tables_dict (dict_table_t *old_table, dict_table_t *new_table, const char *tmp_name, trx_t *trx))
UNIV_INTERN dberr_t row_merge_rename_index_to_add (trx_t *trx, table_id_t table_id, index_id_t index_id))
UNIV_INTERN dberr_t row_merge_rename_index_to_drop (trx_t *trx, table_id_t table_id, index_id_t index_id))
UNIV_INTERN dict_index_trow_merge_create_index (trx_t *trx, dict_table_t *table, const index_def_t *index_def)
UNIV_INTERN ibool row_merge_is_index_usable (const trx_t *trx, const dict_index_t *index)
UNIV_INTERN dberr_t row_merge_drop_table (trx_t *trx, dict_table_t *table))
UNIV_INTERN dberr_t row_merge_build_indexes (trx_t *trx, dict_table_t *old_table, dict_table_t *new_table, bool online, dict_index_t **indexes, const ulint *key_numbers, ulint n_indexes, struct TABLE *table, const dtuple_t *add_cols, const ulint *col_map, ulint add_autoinc, ib_sequence_t &sequence)
UNIV_INTERN void row_merge_buf_write (const row_merge_buf_t *buf, const merge_file_t *of, row_merge_block_t *block))
UNIV_INTERN void row_merge_buf_sort (row_merge_buf_t *buf, row_merge_dup_t *dup)))
UNIV_INTERN ibool row_merge_write (int fd, ulint offset, const void *buf)
UNIV_INTERN row_merge_buf_trow_merge_buf_empty (row_merge_buf_t *buf))
UNIV_INTERN int row_merge_file_create (merge_file_t *merge_file))
UNIV_INTERN dberr_t row_merge_sort (trx_t *trx, const row_merge_dup_t *dup, merge_file_t *file, row_merge_block_t *block, int *tmpfd))
UNIV_INTERN row_merge_buf_trow_merge_buf_create (dict_index_t *index))
UNIV_INTERN void row_merge_buf_free (row_merge_buf_t *buf))
UNIV_INTERN void row_merge_file_destroy (merge_file_t *merge_file))
UNIV_INTERN ibool row_merge_read (int fd, ulint offset, row_merge_block_t *buf)
UNIV_INTERN const byte * row_merge_read_rec (row_merge_block_t *block, mrec_buf_t *buf, const byte *b, const dict_index_t *index, int fd, ulint *foffs, const mrec_t **mrec, ulint *offsets))

Variables

UNIV_INTERN dberr_t warn_unused_result

Detailed Description

Index build routines using a merge sort

Created 13/06/2005 Jan Lindstrom

Typedef Documentation

typedef byte mrec_buf_t[UNIV_PAGE_SIZE_MAX]

Secondary buffer for I/O operations of merge records.

This buffer is used for writing or reading a record that spans two row_merge_block_t. Thus, it must be able to hold one merge record, whose maximum size is the same as the minimum size of row_merge_block_t.

typedef byte mrec_t

Merge record in row_merge_block_t.

The format is the same as a record in ROW_FORMAT=COMPACT with the exception that the REC_N_NEW_EXTRA_BYTES are omitted.

typedef byte row_merge_block_t

Block size for I/O operations in merge sort.

The minimum is UNIV_PAGE_SIZE, or page_get_free_space_of_empty() rounded to a power of 2.

When not creating a PRIMARY KEY that contains column prefixes, this can be set as small as UNIV_PAGE_SIZE / 2.

Function Documentation

UNIV_INTERN char* row_make_new_pathname ( dict_table_t table,
const char *  new_name 
)

Provide a new pathname for a table that is being renamed if it belongs to a file-per-table tablespace. The caller is responsible for freeing the memory allocated for the return value.

Returns
new pathname of tablespace file, or NULL if space = 0 in: new name
Parameters
tablein: table to be renamed
UNIV_INTERN row_merge_buf_t* row_merge_buf_create ( dict_index_t index)

Allocate a sort buffer.

Returns
own: sort buffer
Parameters
indexin: secondary index
UNIV_INTERN row_merge_buf_t* row_merge_buf_empty ( row_merge_buf_t buf)

Empty a sort buffer.

Returns
sort buffer
Parameters
bufin,own: sort buffer
UNIV_INTERN void row_merge_buf_free ( row_merge_buf_t buf)

Deallocate a sort buffer.

Parameters
bufin,own: sort buffer to be freed
UNIV_INTERN void row_merge_buf_sort ( row_merge_buf_t buf,
row_merge_dup_t dup 
)

Sort a buffer.

Parameters
bufin/out: sort buffer
dupin/out: reporter of duplicates (NULL if non-unique index)
UNIV_INTERN void row_merge_buf_write ( const row_merge_buf_t buf,
const merge_file_t of,
row_merge_block_t block 
)

Write a buffer to a block.

Parameters
bufin: sorted buffer
ofin: output file
blockout: buffer for writing to file
UNIV_INTERN dberr_t row_merge_build_indexes ( trx_t trx,
dict_table_t old_table,
dict_table_t new_table,
bool  online,
dict_index_t **  indexes,
const ulint *  key_numbers,
ulint  n_indexes,
struct TABLE *  table,
const dtuple_t add_cols,
const ulint *  col_map,
ulint  add_autoinc,
ib_sequence_t sequence 
)

Build indexes on a table by reading a clustered index, creating a temporary file containing index entries, merge sorting these index entries and inserting sorted index entries to indexes.

Returns
DB_SUCCESS or error code
Parameters
trxin: transaction
old_tablein: table where rows are read from
new_tablein: table where indexes are created; identical to old_table unless creating a PRIMARY KEY
onlinein: true if creating indexes online
indexesin: indexes to be created
key_numbersin: MySQL key numbers
n_indexesin: size of indexes[]
tablein/out: MySQL table, for reporting erroneous key value if applicable
add_colsin: default values of added columns, or NULL
col_mapin: mapping of old column numbers to new ones, or NULL if old_table == new_table
add_autoincin: number of added AUTO_INCREMENT column, or ULINT_UNDEFINED if none is added
sequencein/out: autoinc sequence
UNIV_INTERN dict_index_t* row_merge_create_index ( trx_t trx,
dict_table_t table,
const index_def_t index_def 
)

Create the index and load in to the dictionary.

Returns
index, or NULL on error in: the index definition
Parameters
trxin/out: trx (sets error_state)
tablein: the index is on this table
UNIV_INTERN void row_merge_drop_indexes ( trx_t trx,
dict_table_t table,
ibool  locked 
)

Drop those indexes which were created before an error occurred. The data dictionary must have been locked exclusively by the caller, because the transaction will not be committed.

Parameters
trxin/out: transaction
tablein/out: table containing the indexes
lockedin: TRUE=table locked, FALSE=may need to do a lazy drop
UNIV_INTERN void row_merge_drop_indexes_dict ( trx_t trx,
table_id_t  table_id 
)

Drop indexes that were created before an error occurred. The data dictionary must have been locked exclusively by the caller, because the transaction will not be committed.

Parameters
trxin/out: dictionary transaction
table_idin: table identifier
UNIV_INTERN dberr_t row_merge_drop_table ( trx_t trx,
dict_table_t table 
)

Drop a table. The caller must have ensured that the background stats thread is not processing the table. This can be done by calling dict_stats_wait_bg_to_stop_using_table() after locking the dictionary and before calling this function.

Returns
DB_SUCCESS or error code
Parameters
trxin: transaction
tablein: table instance to drop
UNIV_INTERN void row_merge_drop_temp_indexes ( void  )

Drop all partially created indexes during crash recovery.

UNIV_INTERN void row_merge_dup_report ( row_merge_dup_t dup,
const dfield_t entry 
)

Report a duplicate key.

Parameters
dupin/out: for reporting duplicates
entryin: duplicate index entry
UNIV_INTERN int row_merge_file_create ( merge_file_t merge_file)

Create a merge file.

Returns
file descriptor, or -1 on failure
Parameters
merge_fileout: merge file structure
UNIV_INTERN int row_merge_file_create_low ( void  )

Creates temporary merge files, and if UNIV_PFS_IO defined, register the file descriptor with Performance Schema.

Returns
File descriptor
UNIV_INTERN void row_merge_file_destroy ( merge_file_t merge_file)

Destroy a merge file.

Parameters
merge_filein/out: merge file structure
UNIV_INTERN void row_merge_file_destroy_low ( int  fd)

Destroy a merge file. And de-register the file from Performance Schema if UNIV_PFS_IO is defined. in: merge file descriptor

UNIV_INTERN ibool row_merge_is_index_usable ( const trx_t trx,
const dict_index_t index 
)

Check if a transaction can use an index.

Returns
TRUE if index can be used by the transaction else FALSE in: index to check
Parameters
trxin: transaction
UNIV_INTERN dberr_t row_merge_lock_table ( trx_t trx,
dict_table_t table,
enum lock_mode  mode 
)

Sets an exclusive lock on a table, for the duration of creating indexes.

Returns
error code or DB_SUCCESS
Parameters
trxin/out: transaction
tablein: table to lock
modein: LOCK_X or LOCK_S
UNIV_INTERN ibool row_merge_read ( int  fd,
ulint  offset,
row_merge_block_t buf 
)

Read a merge block from the file system.

Returns
TRUE if request was successful, FALSE if fail out: data
Parameters
fdin: file descriptor
offsetin: offset where to read in number of row_merge_block_t elements
UNIV_INTERN const byte* row_merge_read_rec ( row_merge_block_t block,
mrec_buf_t buf,
const byte *  b,
const dict_index_t index,
int  fd,
ulint *  foffs,
const mrec_t **  mrec,
ulint *  offsets 
)

Read a merge record.

Returns
pointer to next record, or NULL on I/O error or end of list
Parameters
blockin/out: file buffer
bufin/out: secondary buffer
bin: pointer to record
indexin: index of the record
fdin: file descriptor
foffsin/out: file offset
mrecout: pointer to merge record, or NULL on end of list (non-NULL on I/O error)
offsetsout: offsets of mrec
UNIV_INTERN dberr_t row_merge_rename_index_to_add ( trx_t trx,
table_id_t  table_id,
index_id_t  index_id 
)

Rename an index in the dictionary that was created. The data dictionary must have been locked exclusively by the caller, because the transaction will not be committed.

Returns
DB_SUCCESS if all OK
Parameters
trxin/out: transaction
table_idin: table identifier
index_idin: index identifier
UNIV_INTERN dberr_t row_merge_rename_index_to_drop ( trx_t trx,
table_id_t  table_id,
index_id_t  index_id 
)

Rename an index in the dictionary that is to be dropped. The data dictionary must have been locked exclusively by the caller, because the transaction will not be committed.

Returns
DB_SUCCESS if all OK
Parameters
trxin/out: transaction
table_idin: table identifier
index_idin: index identifier
UNIV_INTERN dberr_t row_merge_rename_tables_dict ( dict_table_t old_table,
dict_table_t new_table,
const char *  tmp_name,
trx_t trx 
)

Rename the tables in the data dictionary. The data dictionary must have been locked exclusively by the caller, because the transaction will not be committed.

Returns
error code or DB_SUCCESS
Parameters
old_tablein/out: old table, renamed to tmp_name
new_tablein/out: new table, renamed to old_table->name
tmp_namein: new name for old_table
trxin/out: dictionary transaction
UNIV_INTERN dberr_t row_merge_sort ( trx_t trx,
const row_merge_dup_t dup,
merge_file_t file,
row_merge_block_t block,
int *  tmpfd 
)

Merge disk files.

Returns
DB_SUCCESS or error code
Parameters
trxin: transaction
dupin: descriptor of index being created
filein/out: file containing index entries
blockin/out: 3 buffers
tmpfdin/out: temporary file handle
UNIV_INTERN ibool row_merge_write ( int  fd,
ulint  offset,
const void *  buf 
)

Write a merge block to the file system.

Returns
TRUE if request was successful, FALSE if fail in: data
Parameters
fdin: file descriptor
offsetin: offset where to write, in number of row_merge_block_t elements