MySQL 9.0.0
Source Code Documentation
ddl::Context Struct Reference

DDL context/configuration. More...

#include <ddl0ddl.h>

Classes

struct  FTS
 Full text search context information and state. More...
 

Public Types

using Scan_buffer_size = std::pair< size_t, size_t >
 Scan sort and IO buffer size. More...
 

Public Member Functions

 Context (trx_t *trx, dict_table_t *old_table, dict_table_t *new_table, bool online, dict_index_t **indexes, const ulint *key_numbers, size_t n_indexes, TABLE *table, const dtuple_t *add_cols, const ulint *col_map, size_t add_autoinc, ddl::Sequence &sequence, bool skip_pk_sort, Alter_stage *stage, const dict_add_v_col_t *add_v, TABLE *eval_table, size_t max_buffer_size, size_t max_threads) noexcept
 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...
 
 ~Context () noexcept
 Destructor. More...
 
dberr_t get_error () const noexcept
 
void set_error (dberr_t err) noexcept
 Set the error code, when it's not specific to an index. More...
 
void set_error (dberr_t err, size_t id) noexcept
 Set the error code and index number where the error occurred. More...
 
dberr_t build () noexcept
 Build the indexes. More...
 
Flush_observerflush_observer () noexcept
 
dict_table_told_table () noexcept
 
dict_table_tnew_table () noexcept
 
Scan_buffer_size scan_buffer_size (size_t n_threads) const noexcept
 Calculate the sort and buffer size per thread. More...
 
size_t merge_io_buffer_size (size_t n_buffers) const noexcept
 Calculate the io buffer size per file for the sort phase. More...
 
size_t load_io_buffer_size (size_t n_buffers) const noexcept
 Calculate the io buffer size per file for the load phase. More...
 
size_t allocate (size_t n) const
 Request number of bytes for a buffer. More...
 
THDthd () noexcept
 
dtuple_tcreate_add_cols () noexcept
 Copy the added columns dtuples so that we don't use the same column data buffer for the added column across multiple threads. More...
 

Private Types

using Key_numbers = std::vector< size_t, ut::allocator< size_t > >
 
using Indexes = std::vector< dict_index_t *, ut::allocator< dict_index_t * > >
 

Private Member Functions

Cursorcursor () noexcept
 
const dict_index_tindex () const noexcept
 
dberr_t read_init (Cursor *cursor) noexcept
 Initialize the context for a cluster index scan. More...
 
dberr_t fts_create (dict_index_t *index) noexcept
 Initialize the FTS build infrastructure. More...
 
dberr_t setup_fts_build () noexcept
 Setup the FTS index build data structures. More...
 
doc_id_t next_doc_id () noexcept
 Get the next Doc ID and increment the current value. More...
 
void update_fts_doc_id () noexcept
 Update the FTS document ID. More...
 
dberr_t check_state_of_online_build_log () noexcept
 Check the state of the online build log for the index. More...
 
void note_max_trx_id (dict_index_t *index) noexcept
 Track the highest TxID that modified this index when the scan was completed. More...
 
dberr_t setup_pk_sort (Cursor *cursor) noexcept
 Setup the primary key sort. More...
 
void setup_nonnull () noexcept
 Init the non-null column constraints checks (if required). More...
 
bool check_null_constraints (const dtuple_t *row) const noexcept
 Check if the nonnull columns satisfy the constraint. More...
 
dberr_t cleanup (dberr_t err) noexcept
 Clean up the data structures at the end of the DDL. More...
 
dberr_t handle_autoinc (const dtuple_t *row) noexcept
 Handle auto increment. More...
 
bool has_virtual_columns () const noexcept
 
bool has_fts_indexes () const noexcept
 
bool is_interrupted () noexcept
 

Private Attributes

std::atomic< dberr_tm_err {DB_SUCCESS}
 Common error code for all index builders running in parallel. More...
 
size_t m_err_key_number {std::numeric_limits<size_t>::max()}
 Index where the error occurred. More...
 
trx_tm_trx {}
 Transaction covering the index build. More...
 
FTS m_fts
 The FTS builder. More...
 
dict_table_tm_old_table {}
 Source table, read rows from this table. More...
 
dict_table_tm_new_table {}
 Table where indexes are created; identical to old_table unless creating a PRIMARY KEY. More...
 
bool m_online {}
 True if creating index online. More...
 
Indexes m_indexes {}
 Indexes to be created. More...
 
Key_numbers m_key_numbers {}
 MySQL key numbers. More...
 
TABLEm_table {}
 MySQL table for reporting errors/warnings. More...
 
const dtuple_tm_add_cols {}
 Default value for added columns or null. More...
 
const ulintm_col_map {}
 Mapping of old column numbers to new ones, or nullptr if none were added. More...
 
size_t m_add_autoinc {ULINT_UNDEFINED}
 Number of added AUTO_INCREMENT columns, or ULINT_UNDEFINED if none added. More...
 
ddl::Sequencem_sequence
 Autoinc sequence. More...
 
Alter_stagem_stage {}
 Performance schema accounting object, used by ALTER TABLE. More...
 
const dict_add_v_col_tm_add_v {}
 New virtual columns added along with indexes. More...
 
TABLEm_eval_table {}
 MySQL table used to evaluate virtual column value, see innobase_get_computed_value(). More...
 
bool m_skip_pk_sort {}
 Skip the sorting phase if true. More...
 
std::vector< size_t, ut::allocator< size_t > > m_nonnull {}
 Non null columns. More...
 
size_t m_n_uniq {}
 Number of unique columns in the key. More...
 
bool m_need_observer {}
 true if need flush observer. More...
 
Cursorm_cursor {}
 Cursor for reading the cluster index. More...
 
size_t m_n_allocated {}
 Number of bytes used. More...
 
const size_t m_max_buffer_size {}
 Maximum number of bytes to use. More...
 
const size_t m_max_threads {}
 Maximum number of threads to use. More...
 
ib_mutex_t m_autoinc_mutex
 For parallel access to the autoincrement generator. More...
 
mem_heap_tm_dtuple_heap {}
 Heap for copies of m_add_cols. More...
 

Friends

struct Row
 
class Loader
 
struct Cursor
 
struct Builder
 
struct ddl::FTS
 
struct Load_cursor
 
struct Btree_cursor
 
struct Merge_file_sort
 
struct Parallel_cursor
 

Detailed Description

DDL context/configuration.

Member Typedef Documentation

◆ Indexes

using ddl::Context::Indexes = std::vector<dict_index_t *, ut::allocator<dict_index_t *> >
private

◆ Key_numbers

using ddl::Context::Key_numbers = std::vector<size_t, ut::allocator<size_t> >
private

◆ Scan_buffer_size

using ddl::Context::Scan_buffer_size = std::pair<size_t, size_t>

Scan sort and IO buffer size.

Constructor & Destructor Documentation

◆ Context()

ddl::Context::Context ( trx_t trx,
dict_table_t old_table,
dict_table_t new_table,
bool  online,
dict_index_t **  indexes,
const ulint key_numbers,
size_t  n_indexes,
TABLE table,
const dtuple_t add_cols,
const ulint col_map,
size_t  add_autoinc,
ddl::Sequence sequence,
bool  skip_pk_sort,
Alter_stage stage,
const dict_add_v_col_t add_v,
TABLE eval_table,
size_t  max_buffer_size,
size_t  max_threads 
)
noexcept

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 nullptr 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().
[in]max_buffer_sizeMemory use upper limit.
[in]max_threadstrue if DDL should use multiple threads.

◆ ~Context()

ddl::Context::~Context ( )
noexcept

Destructor.

Member Function Documentation

◆ allocate()

size_t ddl::Context::allocate ( size_t  n) const

Request number of bytes for a buffer.

Parameters
[in]nNumber of bytes requested.
Returns
the number of bytes available.

◆ build()

dberr_t ddl::Context::build ( )
noexcept

Build the indexes.

Returns
DB_SUCCESS or error code.

◆ check_null_constraints()

bool ddl::Context::check_null_constraints ( const dtuple_t row) const
privatenoexcept

Check if the nonnull columns satisfy the constraint.

Parameters
[in]rowRow to check.
Returns
true on success.

◆ check_state_of_online_build_log()

dberr_t ddl::Context::check_state_of_online_build_log ( )
privatenoexcept

Check the state of the online build log for the index.

Returns
DB_SUCCESS or error code.

◆ cleanup()

dberr_t ddl::Context::cleanup ( dberr_t  err)
privatenoexcept

Clean up the data structures at the end of the DDL.

Parameters
[in]errStatus of the DDL.
Returns
DB_SUCCESS or error code.

◆ create_add_cols()

dtuple_t * ddl::Context::create_add_cols ( )
noexcept

Copy the added columns dtuples so that we don't use the same column data buffer for the added column across multiple threads.

Returns
new instance or nullptr if out of memory.

◆ cursor()

Cursor * ddl::Context::cursor ( )
inlineprivatenoexcept
Returns
the cluster index read cursor.

◆ flush_observer()

Flush_observer * ddl::Context::flush_observer ( )
noexcept
Returns
the flush observer to use for flushing.

◆ fts_create()

dberr_t ddl::Context::fts_create ( dict_index_t index)
privatenoexcept

Initialize the FTS build infrastructure.

Parameters
[in,out]indexIndex prototype to build.
Returns
DB_SUCCESS or error code.

◆ get_error()

dberr_t ddl::Context::get_error ( ) const
inlinenoexcept
Returns
the DDL error status.

◆ handle_autoinc()

dberr_t ddl::Context::handle_autoinc ( const dtuple_t row)
privatenoexcept

Handle auto increment.

Parameters
[in]rowRow with autoinc column.
Returns
DB_SUCCESS or error code.

◆ has_fts_indexes()

bool ddl::Context::has_fts_indexes ( ) const
privatenoexcept
Returns
true if any FTS indexes are involved.

◆ has_virtual_columns()

bool ddl::Context::has_virtual_columns ( ) const
privatenoexcept
Returns
true if any virtual columns are involved.

◆ index()

const dict_index_t * ddl::Context::index ( ) const
privatenoexcept
Returns
the original table cluster index.

◆ is_interrupted()

bool ddl::Context::is_interrupted ( )
privatenoexcept
Returns
true if the DDL was interrupted.

◆ load_io_buffer_size()

size_t ddl::Context::load_io_buffer_size ( size_t  n_buffers) const
noexcept

Calculate the io buffer size per file for the load phase.

Parameters
[in]n_buffersTotal number of buffers to use for the loading.
Returns
the per thread io buffer size.

◆ merge_io_buffer_size()

size_t ddl::Context::merge_io_buffer_size ( size_t  n_buffers) const
noexcept

Calculate the io buffer size per file for the sort phase.

Parameters
[in]n_buffersTotal number of buffers to use for the merge.
Returns
the sort buffer size for one instance.

◆ new_table()

dict_table_t * ddl::Context::new_table ( )
inlinenoexcept
Returns
the new table.

◆ next_doc_id()

doc_id_t ddl::Context::next_doc_id ( )
privatenoexcept

Get the next Doc ID and increment the current value.

Returns
a document ID.

◆ note_max_trx_id()

void ddl::Context::note_max_trx_id ( dict_index_t index)
privatenoexcept

Track the highest TxID that modified this index when the scan was completed.

We prevent older readers from accessing this index, to ensure read consistency.

Parameters
[in,out]indexIndex to track.

◆ old_table()

dict_table_t * ddl::Context::old_table ( )
inlinenoexcept
Returns
the old table.

◆ read_init()

dberr_t ddl::Context::read_init ( Cursor cursor)
privatenoexcept

Initialize the context for a cluster index scan.

Parameters
[in,out]cursorCursor used for the cluster index read.

◆ scan_buffer_size()

Context::Scan_buffer_size ddl::Context::scan_buffer_size ( size_t  n_threads) const
noexcept

Calculate the sort and buffer size per thread.

Parameters
[in]n_threadsTotal number of threads used for scanning.
Returns
the sort and IO buffer size per thread.

◆ set_error() [1/2]

void ddl::Context::set_error ( dberr_t  err)
inlinenoexcept

Set the error code, when it's not specific to an index.

Parameters
[in]errError code.

◆ set_error() [2/2]

void ddl::Context::set_error ( dberr_t  err,
size_t  id 
)
inlinenoexcept

Set the error code and index number where the error occurred.

Parameters
[in]errError code.
[in]idIndex ordinal value where error occurred.

◆ setup_fts_build()

dberr_t ddl::Context::setup_fts_build ( )
privatenoexcept

Setup the FTS index build data structures.

Returns
DB_SUCCESS or error code.

◆ setup_nonnull()

void ddl::Context::setup_nonnull ( )
privatenoexcept

Init the non-null column constraints checks (if required).

◆ setup_pk_sort()

dberr_t ddl::Context::setup_pk_sort ( Cursor cursor)
privatenoexcept

Setup the primary key sort.

Parameters
[in,out]cursorSetup the primary key data structures.
Returns
DB_SUCCESS or error code.

◆ thd()

THD * ddl::Context::thd ( )
noexcept
Returns
the server session/connection context.

◆ update_fts_doc_id()

void ddl::Context::update_fts_doc_id ( )
privatenoexcept

Update the FTS document ID.

Friends And Related Function Documentation

◆ Btree_cursor

friend struct Btree_cursor
friend

◆ Builder

friend struct Builder
friend

◆ Cursor

friend struct Cursor
friend

◆ ddl::FTS

friend struct ddl::FTS
friend

◆ Load_cursor

friend struct Load_cursor
friend

◆ Loader

friend class Loader
friend

◆ Merge_file_sort

friend struct Merge_file_sort
friend

◆ Parallel_cursor

friend struct Parallel_cursor
friend

◆ Row

friend struct Row
friend

Member Data Documentation

◆ m_add_autoinc

size_t ddl::Context::m_add_autoinc {ULINT_UNDEFINED}
private

Number of added AUTO_INCREMENT columns, or ULINT_UNDEFINED if none added.

◆ m_add_cols

const dtuple_t* ddl::Context::m_add_cols {}
private

Default value for added columns or null.

◆ m_add_v

const dict_add_v_col_t* ddl::Context::m_add_v {}
private

New virtual columns added along with indexes.

◆ m_autoinc_mutex

ib_mutex_t ddl::Context::m_autoinc_mutex
private

For parallel access to the autoincrement generator.

◆ m_col_map

const ulint* ddl::Context::m_col_map {}
private

Mapping of old column numbers to new ones, or nullptr if none were added.

◆ m_cursor

Cursor* ddl::Context::m_cursor {}
private

Cursor for reading the cluster index.

◆ m_dtuple_heap

mem_heap_t* ddl::Context::m_dtuple_heap {}
private

Heap for copies of m_add_cols.

◆ m_err

std::atomic<dberr_t> ddl::Context::m_err {DB_SUCCESS}
private

Common error code for all index builders running in parallel.

◆ m_err_key_number

size_t ddl::Context::m_err_key_number {std::numeric_limits<size_t>::max()}
private

Index where the error occurred.

◆ m_eval_table

TABLE* ddl::Context::m_eval_table {}
private

MySQL table used to evaluate virtual column value, see innobase_get_computed_value().

◆ m_fts

FTS ddl::Context::m_fts
private

The FTS builder.

There is one FTS per table.

◆ m_indexes

Indexes ddl::Context::m_indexes {}
private

Indexes to be created.

◆ m_key_numbers

Key_numbers ddl::Context::m_key_numbers {}
private

MySQL key numbers.

◆ m_max_buffer_size

const size_t ddl::Context::m_max_buffer_size {}
private

Maximum number of bytes to use.

◆ m_max_threads

const size_t ddl::Context::m_max_threads {}
private

Maximum number of threads to use.

We don't do a parallel scan of the clustered index when FTS and/or virtual columns are involved. The build phase is parallel though.

◆ m_n_allocated

size_t ddl::Context::m_n_allocated {}
private

Number of bytes used.

◆ m_n_uniq

size_t ddl::Context::m_n_uniq {}
private

Number of unique columns in the key.

◆ m_need_observer

bool ddl::Context::m_need_observer {}
private

true if need flush observer.

◆ m_new_table

dict_table_t* ddl::Context::m_new_table {}
private

Table where indexes are created; identical to old_table unless creating a PRIMARY KEY.

◆ m_nonnull

std::vector<size_t, ut::allocator<size_t> > ddl::Context::m_nonnull {}
private

Non null columns.

◆ m_old_table

dict_table_t* ddl::Context::m_old_table {}
private

Source table, read rows from this table.

◆ m_online

bool ddl::Context::m_online {}
private

True if creating index online.

Non-online implies that we have an S latch on the table, therefore there can't be concurrent updates to the table while we are executing the DDL. We don't log the changes to the row log.

◆ m_sequence

ddl::Sequence& ddl::Context::m_sequence
private

Autoinc sequence.

◆ m_skip_pk_sort

bool ddl::Context::m_skip_pk_sort {}
private

Skip the sorting phase if true.

◆ m_stage

Alter_stage* ddl::Context::m_stage {}
private

Performance 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.

◆ m_table

TABLE* ddl::Context::m_table {}
private

MySQL table for reporting errors/warnings.

◆ m_trx

trx_t* ddl::Context::m_trx {}
private

Transaction covering the index build.


The documentation for this struct was generated from the following files: