MySQL  8.0.21
Source Code Documentation
row0merge.h File Reference

Index build routines using a merge sort. More...

#include "btr0types.h"
#include "data0data.h"
#include "dict0types.h"
#include "lock0types.h"
#include "mtr0mtr.h"
#include "que0types.h"
#include "rem0rec.h"
#include "rem0types.h"
#include "row0mysql.h"
#include "srv0srv.h"
#include "trx0types.h"
#include "univ.i"
#include "ut0stage.h"

Go to the source code of this file.

Classes

struct  mtuple_t
 Merge record in row_merge_buf_t. More...
 
struct  row_merge_buf_t
 Buffer for sorting in main memory. More...
 
struct  merge_file_t
 Information about temporary files used in merge sort. More...
 
struct  index_field_t
 Index field definition. More...
 
struct  index_def_t
 Definition of an index being created. More...
 
struct  row_merge_dup_t
 Structure for reporting duplicate records. More...
 

Typedefs

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

Functions

void row_merge_dup_report (row_merge_dup_t *dup, const dfield_t *entry)
 Report a duplicate key. More...
 
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. More...
 
void row_merge_drop_indexes (trx_t *trx, dict_table_t *table, ibool locked)
 Drop those indexes which were created before an error occurred. More...
 
int row_merge_file_create_low (const char *path)
 Create temporary merge files in the given paramater path, and if UNIV_PFS_IO defined, register the file descriptor with Performance Schema. More...
 
void row_merge_file_destroy_low (int fd)
 Destroy a merge file. More...
 
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. More...
 
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. More...
 
dict_index_trow_merge_create_index (trx_t *trx, dict_table_t *table, const index_def_t *index_def, const dict_add_v_col_t *add_v)
 Create the index and load in to the dictionary. More...
 
dberr_t row_merge_drop_table (trx_t *trx, dict_table_t *table)
 Drop a table. More...
 
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, bool skip_pk_sort, ut_stage_alter_t *stage, const dict_add_v_col_t *add_v, struct TABLE *eval_table)
 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. More...
 
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. More...
 
void row_merge_buf_sort (row_merge_buf_t *buf, row_merge_dup_t *dup)
 Sort a buffer. More...
 
ibool row_merge_write (int fd, ulint offset, const void *buf)
 Write a merge block to the file system. More...
 
row_merge_buf_trow_merge_buf_empty (row_merge_buf_t *buf)
 Empty a sort buffer. More...
 
int row_merge_file_create (merge_file_t *merge_file, const char *path)
 Create a merge file int the given location. More...
 
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, ut_stage_alter_t *stage=nullptr)
 Merge disk files. More...
 
row_merge_buf_trow_merge_buf_create (dict_index_t *index)
 Allocate a sort buffer. More...
 
void row_merge_buf_free (row_merge_buf_t *buf)
 Deallocate a sort buffer. More...
 
void row_merge_file_destroy (merge_file_t *merge_file)
 Destroy a merge file. More...
 
ibool row_merge_read (int fd, ulint offset, row_merge_block_t *buf)
 Read a merge block from the file system. More...
 
const byterow_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. More...
 

Detailed Description

Index build routines using a merge sort.

Created 13/06/2005 Jan Lindstrom

Typedef Documentation

◆ mrec_buf_t

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.

◆ mrec_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.

◆ 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

◆ row_make_new_pathname()

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

The caller is responsible for freeing the memory allocated for the return value.

Returns
new pathname of tablespace file, or NULL if space = 0
Parameters
tablein: table to be renamed
new_namein: new name

◆ row_merge_buf_create()

row_merge_buf_t* row_merge_buf_create ( dict_index_t index)

Allocate a sort buffer.

Returns
own: sort buffer
Parameters
indexin: secondary index

◆ row_merge_buf_empty()

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

◆ row_merge_buf_free()

void row_merge_buf_free ( row_merge_buf_t buf)

Deallocate a sort buffer.

in,own: sort buffer to be freed

Parameters
bufin,own: sort buffer to be freed

◆ row_merge_buf_sort()

void row_merge_buf_sort ( row_merge_buf_t buf,
row_merge_dup_t dup 
)

Sort a buffer.

in/out: reporter of duplicates (NULL if non-unique index)

Parameters
bufin/out: sort buffer
dupin/out: reporter of duplicates (NULL if non-unique index)

◆ row_merge_buf_write()

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
[in]bufsorted buffer
[in]ofoutput file
[out]blockbuffer for writing to file

◆ row_merge_build_indexes()

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,
bool  skip_pk_sort,
ut_stage_alter_t stage,
const dict_add_v_col_t add_v,
struct TABLE eval_table 
)

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.

Parameters
[in]trxtransaction
[in]old_tabletable where rows are read from
[in]new_tabletable where indexes are created; identical to old_table unless creating a PRIMARY KEY
[in]onlinetrue if creating indexes online
[in]indexesindexes to be created
[in]key_numbersMySQL key numbers
[in]n_indexessize of indexes[]
[in,out]tableMySQL table, for reporting erroneous key value if applicable
[in]add_colsdefault values of added columns, or NULL
[in]col_mapmapping of old column numbers to new ones, or NULL if old_table == new_table
[in]add_autoincnumber of added AUTO_INCREMENT columns, or ULINT_UNDEFINED if none is added
[in,out]sequenceautoinc sequence
[in]skip_pk_sortwhether the new PRIMARY KEY will follow existing order
[in,out]stageperformance schema accounting object, used by ALTER TABLE. stage->begin_phase_read_pk() will be called at the beginning of this function and it will be passed to other functions for further accounting.
[in]add_vnew virtual columns added along with indexes
[in]eval_tablemysql table used to evaluate virtual column value, see innobase_get_computed_value().
Returns
DB_SUCCESS or error code

◆ row_merge_create_index()

dict_index_t* row_merge_create_index ( trx_t trx,
dict_table_t table,
const index_def_t index_def,
const dict_add_v_col_t add_v 
)

Create the index and load in to the dictionary.

Parameters
[in,out]trxtrx (sets error_state)
[in,out]tablethe index is on this table
[in]index_defthe index definition
[in]add_vnew virtual columns added along with add index call
Returns
index, or NULL on error

◆ row_merge_drop_indexes()

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. in: TRUE=table locked, FALSE=may need to do a lazy drop

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: dictionary transaction
tablein/out: table containing the indexes
lockedin: TRUE=table locked, FALSE=may need to do a lazy drop

◆ row_merge_drop_table()

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 in: table instance to drop

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 to drop

◆ row_merge_dup_report()

void row_merge_dup_report ( row_merge_dup_t dup,
const dfield_t entry 
)

Report a duplicate key.

in: duplicate index entry

Parameters
dupin/out: for reporting duplicates
entryin: duplicate index entry

◆ row_merge_file_create()

int row_merge_file_create ( merge_file_t merge_file,
const char *  path 
)

Create a merge file int the given location.

Parameters
[out]merge_filemerge file structure
[in]pathlocation for creating temporary file
Returns
file descriptor, or -1 on failure

Create a merge file int the given location.

Parameters
[out]merge_filemerge file structure
[in]pathlocation for creating temporary file
Returns
file descriptor, or -1 on failure

◆ row_merge_file_create_low()

int row_merge_file_create_low ( const char *  path)

Create temporary merge files in the given paramater path, and if UNIV_PFS_IO defined, register the file descriptor with Performance Schema.

Parameters
[in]pathlocation for creating temporary merge files.
Returns
File descriptor

◆ row_merge_file_destroy()

void row_merge_file_destroy ( merge_file_t merge_file)

Destroy a merge file.

in/out: merge file structure

Parameters
merge_filein/out: merge file structure

◆ row_merge_file_destroy_low()

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

And de-register the file from Performance Schema if UNIV_PFS_IO is defined.

Parameters
fdin: merge file descriptor

◆ row_merge_lock_table()

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

◆ row_merge_read()

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
true if request was successful, false if fail
Parameters
fdin: file descriptor
offsetin: offset where to read in number of row_merge_block_t elements
bufout: data

◆ row_merge_read_rec()

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

◆ row_merge_rename_tables_dict()

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

◆ row_merge_sort()

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,
ut_stage_alter_t stage 
)

Merge disk files.

Parameters
[in]trxtransaction
[in]dupdescriptor of index being created
[in,out]filefile containing index entries
[in,out]block3 buffers
[in,out]tmpfdtemporary file handle
[in,out]stageperformance schema accounting object, used by ALTER TABLE. If not NULL, stage->begin_phase_sort() will be called initially and then stage->inc() will be called for each record processed.
Returns
DB_SUCCESS or error code

◆ row_merge_write()

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
true if request was successful, false if fail
Parameters
fdin: file descriptor
offsetin: offset where to write, in number of row_merge_block_t elements
bufin: data