MySQL 26.7.0
Source Code Documentation
ddl::Builder Struct Reference

For loading indexes. More...

#include <ddl0impl-builder.h>

Classes

struct  Thread_ctx
 State of a cluster index reader thread. More...
 

Public Types

enum class  State : uint8_t {
  INIT , ADD , SETUP_SORT , SORT ,
  BTREE_BUILD , FTS_SORT_AND_BUILD , FINISH , STOP ,
  ERROR
}
 Build phase/states. More...
 

Public Member Functions

 Builder (ddl::Context &ctx, Loader &loader, size_t i) noexcept
 Constructor. More...
 
 ~Builder () noexcept
 Destructor/. More...
 
dberr_t get_error () const noexcept
 
bool set_error (dberr_t err) noexcept
 Set the error code. More...
 
size_t id () const noexcept
 
dict_index_tindex () noexcept
 
Contextctx () noexcept
 
void fallback_to_single_thread () noexcept
 Parallel scan thread spawn failed, release the extra thread states. More...
 
bool is_spatial_index () const noexcept
 
bool is_fts_index () const noexcept
 
bool is_unique_index () const noexcept
 
State get_state () const noexcept
 
void set_state (State state) noexcept
 Set the next state. More...
 
Alter_stagestage () noexcept
 
void set_next_state () noexcept
 Set the next state. More...
 
dberr_t init (Cursor &cursor, size_t n_threads) noexcept
 Initialize the cursor. More...
 
dberr_t add_row (Cursor &cursor, Row &row, size_t thread_id, Latch_release &&latch_release) noexcept
 Add a row to the merge buffer. More...
 
bool is_skip_file_sort () const noexcept
 
dberr_t fts_sort_and_build () noexcept
 FTS: Sort and insert the rows read. More...
 
dberr_t setup_sort () noexcept
 Non-FTS: Sort the rows read. More...
 
dberr_t merge_sort (size_t thread_id) noexcept
 Non-FTS: Sort the rows read. More...
 
dberr_t btree_build () noexcept
 Load the sorted data into the B+Tree. More...
 
dberr_t finish () noexcept
 Close temporary files, Flush all dirty pages, apply the row log and write the redo log record. More...
 
dberr_t dtuple_copy_blobs (dtuple_t *dtuple, ulint *offsets, const mrec_t *mrec, mem_heap_t *heap) noexcept
 Copy blobs to the tuple. More...
 
dberr_t append (ddl::file_t &file, IO_buffer file_buffer) noexcept
 Write data to disk - in append mode. More...
 
const char * tmpdir () const noexcept
 
dberr_t batch_insert (size_t thread_id, Latch_release &&latch_release) noexcept
 Insert cached rows. More...
 
void batch_insert_deep_copy_tuples (size_t thread_id) noexcept
 Note that the latches are going to be released. More...
 
dberr_t check_state_of_online_build_log () noexcept
 Check the state of the online build log for the index. More...
 
dberr_t handle_error (dberr_t err) noexcept
 Cleanup DDL after error in online build Note: To be called if DDL must cleanup due to error in online build. More...
 

Static Public Member Functions

static void write_redo (const dict_index_t *index) noexcept
 Write an MLOG_INDEX_LOAD record to indicate in the redo-log that redo-logging of individual index pages was disabled, and the flushing of such pages to the data files was completed. More...
 

Private Types

using Allocator = ut::allocator< Thread_ctx * >
 
using Thread_ctxs = std::vector< Thread_ctx *, Allocator >
 

Private Member Functions

dberr_t create_merge_sort_tasks () noexcept
 Create the tasks to merge Sort the file before we load the file into the Btree index. More...
 
void finalize () noexcept
 Flush all dirty pages, apply the row log and write the redo log record. More...
 
dberr_t batch_add_row (Row &row, size_t thread_id) noexcept
 Cache a row for batch inserts. More...
 
dberr_t bulk_add_row (Cursor &cursor, Row &row, size_t thread_id, Latch_release &&latch_release) noexcept
 Add a row to the merge buffer. More...
 
void clear_virtual_heap () noexcept
 Clear the heap used for virtual columns. More...
 
void fts_add_doc_id (dfield_t *dst, const dict_field_t *src, doc_id_t &write_doc_id) noexcept
 Add the FTS document ID to the destination field. More...
 
dberr_t copy_row (Copy_ctx &ctx, size_t &mv_rows_added) noexcept
 Add a row to the write buffer. More...
 
dberr_t get_virtual_column (Copy_ctx &ctx, const dict_field_t *ifield, dict_col_t *col, dfield_t *&src_field, size_t &mv_rows_added) noexcept
 Setup the virtual column src column. More...
 
dberr_t enqueue_parsing (const dtuple_t &row, size_t field_no) noexcept
 Enqueue parsing of the field of the row. More...
 
dberr_t enqueue_parsing (const dtuple_t &row) noexcept
 Enqueue parsing of the row. More...
 
dberr_t copy_columns (Copy_ctx &ctx, size_t &mv_rows_added, doc_id_t &write_doc_id) noexcept
 Copy the columns to the temporary file buffer. More...
 
dberr_t add_to_key_buffer (Copy_ctx &ctx, size_t &mv_rows_added) noexcept
 Add row to the key buffer. More...
 
void fts_wait_for_completion (const dict_index_t *index) noexcept
 Wait for FTS completion. More...
 
dberr_t key_buffer_sort (size_t thread_id) noexcept
 Sort the data in the key buffer. More...
 
dberr_t insert_direct (Cursor &cursor, size_t thread_id) noexcept
 Sort the buffer in memory and insert directly in the BTree loader, don't write to a temporary file. More...
 
bool create_file (ddl::file_t &file) noexcept
 Create the merge file, if needed. More...
 
dberr_t check_duplicates (Thread_ctxs &dupcheck) noexcept
 Check for duplicates in the first block. More...
 

Static Private Member Functions

static void convert (const dict_index_t *clust_index, const dfield_t *row_field, dfield_t *field, ulint len, const page_size_t &page_size, bool is_sdi, mem_heap_t *heap) noexcept
 Convert the field data from compact to redundant format. More...
 
static void copy_blobs (const dict_index_t *index, const mrec_t *mrec, const ulint *offsets, const page_size_t &page_size, dtuple_t *tuple, bool is_sdi, mem_heap_t *heap) noexcept
 Copy externally stored columns to the data tuple. More...
 

Private Attributes

size_t m_id {}
 Buffer ID. More...
 
std::atomic< Statem_state {State::INIT}
 Initial phase. More...
 
ddl::Contextm_ctx
 DDL Context. More...
 
Loaderm_loader
 Loader that owns the instance. More...
 
dict_index_tm_index {}
 Index to create (if not FTS index). More...
 
const char * m_tmpdir {}
 Temporary file path. More...
 
Thread_ctxs m_thread_ctxs {}
 Per thread context. More...
 
dfield_tm_prev_fields {}
 For tracking duplicates. More...
 
Dup m_clust_dup {}
 For collecting duplicate entries (error reporting). More...
 
Scoped_heap m_v_heap {}
 Scoped virtual column heap. More...
 
Scoped_heap m_conv_heap {}
 Scoped conversion heap. More...
 
dict_index_tm_sort_index {}
 The index to be built, FTS or non-FTS. More...
 
std::atomic< size_t > m_n_sort_tasks {}
 Number of active sort tasks. More...
 
Btree_loadm_btr_load {}
 Cluster index bulk load instance to use, direct insert without a file sort. More...
 
Alter_stagem_local_stage {}
 Stage per builder. More...
 

Detailed Description

For loading indexes.

Member Typedef Documentation

◆ Allocator

◆ Thread_ctxs

using ddl::Builder::Thread_ctxs = std::vector<Thread_ctx *, Allocator>
private

Member Enumeration Documentation

◆ State

enum class ddl::Builder::State : uint8_t
strong

Build phase/states.

Enumerator
INIT 

Initial phase.

ADD 

Collect the rows for the index to build.

SETUP_SORT 

Setup the merge sort and add the tasks to the task queue.

SORT 

Sort the collected rows, if required.

The builder moves to state BTREE_BUILD after all sort tasks are completed successfully or there was an error during the sort phase.

BTREE_BUILD 

Build the btree.

FTS_SORT_AND_BUILD 

FTS sort and build, this is done in one "step".

FINISH 

Finish the loading of the index.

STOP 

Stop on success.

ERROR 

Stop on error.

Constructor & Destructor Documentation

◆ Builder()

ddl::Builder::Builder ( ddl::Context ctx,
Loader loader,
size_t  i 
)
noexcept

Constructor.

Parameters
[in,out]ctxDDL context.
[in,out]loaderOwner of the instance.
[in]iIndex ordinal value.

◆ ~Builder()

ddl::Builder::~Builder ( )
noexcept

Destructor/.

Member Function Documentation

◆ add_row()

dberr_t ddl::Builder::add_row ( Cursor cursor,
Row row,
size_t  thread_id,
Latch_release &&  latch_release 
)
noexcept

Add a row to the merge buffer.

Parameters
[in,out]cursorCurrent scan cursor.
[in,out]rowRow to add.
[in]thread_idID of current thread.
[in,out]latch_releaseCalled when a log free check is required.
Returns
DB_SUCCESS or error code.

◆ add_to_key_buffer()

dberr_t ddl::Builder::add_to_key_buffer ( Copy_ctx ctx,
size_t &  mv_rows_added 
)
privatenoexcept

Add row to the key buffer.

Parameters
[in,out]ctxCopy context.
[in,out]mv_rows_addedNumber of multi-value index rows added.
Returns
DB_SUCCESS or error code.

◆ append()

dberr_t ddl::Builder::append ( ddl::file_t file,
IO_buffer  file_buffer 
)
noexcept

Write data to disk - in append mode.

Increment the file size.

Parameters
[in,out]fileFile handle.
[in]file_bufferWrite the buffer contents to disk.
Returns
DB_SUCCESS or error code.

◆ batch_add_row()

dberr_t ddl::Builder::batch_add_row ( Row row,
size_t  thread_id 
)
privatenoexcept

Cache a row for batch inserts.

Currently used by spatial indexes.

Parameters
[in,out]rowRow to add.
[in]thread_idID of current thread.
Returns
DB_SUCCESS or error code.

◆ batch_insert()

dberr_t ddl::Builder::batch_insert ( size_t  thread_id,
Latch_release &&  latch_release 
)
noexcept

Insert cached rows.

Parameters
[in]thread_idInsert cached rows for this thread ID.
[in,out]latch_releaseCalled when a log free check is required.
Returns
DB_SUCCESS or error number

◆ batch_insert_deep_copy_tuples()

void ddl::Builder::batch_insert_deep_copy_tuples ( size_t  thread_id)
noexcept

Note that the latches are going to be released.

Do a deep copy of the tuples that are being inserted in batches by batch_insert

Parameters
[in]thread_idDeep copy cached rows for this thread ID.

◆ btree_build()

dberr_t ddl::Builder::btree_build ( )
noexcept

Load the sorted data into the B+Tree.

Returns
DB_SUCESS or error code.

◆ bulk_add_row()

dberr_t ddl::Builder::bulk_add_row ( Cursor cursor,
Row row,
size_t  thread_id,
Latch_release &&  latch_release 
)
privatenoexcept

Add a row to the merge buffer.

Parameters
[in,out]cursorCurrent scan cursor.
[in,out]rowRow to add.
[in]thread_idID of current thread.
[in,out]latch_releaseCalled when a log free check is required.
Returns
DB_SUCCESS or error code.

◆ check_duplicates()

dberr_t ddl::Builder::check_duplicates ( Thread_ctxs dupcheck)
privatenoexcept

Check for duplicates in the first block.

Parameters
[in]dupcheckFiles to check for duplicates.
Returns
DB_SUCCESS or error code.

◆ check_state_of_online_build_log()

dberr_t ddl::Builder::check_state_of_online_build_log ( )
noexcept

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

Returns
DB_SUCCESS or error code.

◆ clear_virtual_heap()

void ddl::Builder::clear_virtual_heap ( )
inlineprivatenoexcept

Clear the heap used for virtual columns.

◆ convert()

void ddl::Builder::convert ( const dict_index_t clust_index,
const dfield_t row_field,
dfield_t field,
ulint  len,
const page_size_t page_size,
bool  is_sdi,
mem_heap_t heap 
)
staticprivatenoexcept

Convert the field data from compact to redundant format.

Parameters
[in]clust_indexClustered index being built
[in]row_fieldField to copy from
[out]fieldField to copy to
[in]lenLength of the field data
[in]page_sizeCompressed BLOB page size
[in]is_sditrue for SDI Indexes
[in,out]heapMemory heap where to allocate data when converting to ROW_FORMAT=REDUNDANT, or nullptr

◆ copy_blobs()

void ddl::Builder::copy_blobs ( const dict_index_t index,
const mrec_t mrec,
const ulint offsets,
const page_size_t page_size,
dtuple_t tuple,
bool  is_sdi,
mem_heap_t heap 
)
staticprivatenoexcept

Copy externally stored columns to the data tuple.

Parameters
[in]indexIndex dictionary object.
[in]mrecRecord containing BLOB pointers, or nullptr to use tuple instead.
[in]offsetsOffsets of mrec.
[in]page_sizeCompressed page size in bytes, or 0
[in,out]tupleData tuple.
[in]is_sdiTrue for SDI Indexes
[in,out]heapMemory heap

◆ copy_columns()

dberr_t ddl::Builder::copy_columns ( Copy_ctx ctx,
size_t &  mv_rows_added,
doc_id_t write_doc_id 
)
privatenoexcept

Copy the columns to the temporary file buffer.

Parameters
[in,out]ctxCopy context.
[in,out]mv_rows_addedMulti value rows added.
[in,out]write_doc_idBuffer for storing the FTS doc ID.
Returns
DB_SUCCESS or error code.

◆ copy_row()

dberr_t ddl::Builder::copy_row ( Copy_ctx ctx,
size_t &  mv_rows_added 
)
privatenoexcept

Add a row to the write buffer.

Parameters
[in,out]ctxCopy context.
[in,out]mv_rows_addedNumber of multi-value rows added.
Returns
DB_SUCCESS or error code.

◆ create_file()

bool ddl::Builder::create_file ( ddl::file_t file)
privatenoexcept

Create the merge file, if needed.

Parameters
[in,out]fileFile handle.
Returns
true if file was opened successfully .

◆ create_merge_sort_tasks()

dberr_t ddl::Builder::create_merge_sort_tasks ( )
privatenoexcept

Create the tasks to merge Sort the file before we load the file into the Btree index.

Returns
DB_SUCCESS or error code.

◆ ctx()

Context & ddl::Builder::ctx ( )
inlinenoexcept
Returns
the DDL context.

◆ dtuple_copy_blobs()

dberr_t ddl::Builder::dtuple_copy_blobs ( dtuple_t dtuple,
ulint offsets,
const mrec_t mrec,
mem_heap_t heap 
)
noexcept

Copy blobs to the tuple.

Parameters
[out]dtupleTuple to copy to.
[in,out]offsetsColumn offsets in the row.
[in]mrecCurrent row.
[in,out]heapHeap for the allocating tuple memory.
Returns
DB_SUCCESS or error code.

◆ enqueue_parsing() [1/2]

dberr_t ddl::Builder::enqueue_parsing ( const dtuple_t row)
privatenoexcept

Enqueue parsing of the row.

Asserts we are building FTS index only.

Parameters
[in]rowThe row which contains fields to parse.
Returns
DB_SUCCESS or error code.

◆ enqueue_parsing() [2/2]

dberr_t ddl::Builder::enqueue_parsing ( const dtuple_t row,
size_t  field_no 
)
privatenoexcept

Enqueue parsing of the field of the row.

Parameters
[in]rowThe row which contains the field to parse
[in]field_noWhich field to parse
Returns
DB_SUCCESS or error code.

◆ fallback_to_single_thread()

void ddl::Builder::fallback_to_single_thread ( )
noexcept

Parallel scan thread spawn failed, release the extra thread states.

◆ finalize()

void ddl::Builder::finalize ( )
privatenoexcept

Flush all dirty pages, apply the row log and write the redo log record.

◆ finish()

dberr_t ddl::Builder::finish ( )
noexcept

Close temporary files, Flush all dirty pages, apply the row log and write the redo log record.

Returns
DB_SUCCESS or error code.

◆ fts_add_doc_id()

void ddl::Builder::fts_add_doc_id ( dfield_t dst,
const dict_field_t src,
doc_id_t write_doc_id 
)
privatenoexcept

Add the FTS document ID to the destination field.

Parameters
[in,out]dstField to write to.
[in]srcField to copy meta data from.
[out]write_doc_idBuffer for copying the doc id.

◆ fts_sort_and_build()

dberr_t ddl::Builder::fts_sort_and_build ( )
noexcept

FTS: Sort and insert the rows read.

Returns
DB_SUCCESS or error code.

◆ fts_wait_for_completion()

void ddl::Builder::fts_wait_for_completion ( const dict_index_t index)
privatenoexcept

Wait for FTS completion.

Parameters
[in]indexIndex being built.

◆ get_error()

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

◆ get_state()

State ddl::Builder::get_state ( ) const
inlinenoexcept
Returns
the current builder state.

◆ get_virtual_column()

dberr_t ddl::Builder::get_virtual_column ( Copy_ctx ctx,
const dict_field_t ifield,
dict_col_t col,
dfield_t *&  src_field,
size_t &  mv_rows_added 
)
privatenoexcept

Setup the virtual column src column.

Parameters
[in,out]ctxCopy context.
[in]ifieldIndex field.
[in]colTable column.
[out]src_fieldComputed value.
[in,out]mv_rows_addedNumber of multi-value rows added.
Returns
DB_SUCCESS or error code.

◆ handle_error()

dberr_t ddl::Builder::handle_error ( dberr_t  err)
noexcept

Cleanup DDL after error in online build Note: To be called if DDL must cleanup due to error in online build.

Pages which are buffer-fixed (in Page_load::release) until the next iteration, must be unfixed (with Page_load::latch) before returning the error.

Note
: Assumes that either m_btr_load->release is called before or m_n_recs is 0 (no records are inserted yet).
Parameters
[in]errError hit in online build
Returns
the cursor error status.

◆ id()

size_t ddl::Builder::id ( ) const
inlinenoexcept
Returns
the instance ID.

◆ index()

dict_index_t * ddl::Builder::index ( )
inlinenoexcept
Returns
the index being built.

◆ init()

dberr_t ddl::Builder::init ( Cursor cursor,
size_t  n_threads 
)
noexcept

Initialize the cursor.

Parameters
[in,out]cursorCursor to initialize.
[in]n_threadsNumber of threads used for reading.
Returns
DB_SUCCESS or error code.

◆ insert_direct()

dberr_t ddl::Builder::insert_direct ( Cursor cursor,
size_t  thread_id 
)
privatenoexcept

Sort the buffer in memory and insert directly in the BTree loader, don't write to a temporary file.

Parameters
[in,out]cursorCurrent scan cursor.
[in]thread_idID of current thread.
Returns
DB_SUCCESS or error code.

◆ is_fts_index()

bool ddl::Builder::is_fts_index ( ) const
inlinenoexcept
Returns
true if the index is an FTS index.

◆ is_skip_file_sort()

bool ddl::Builder::is_skip_file_sort ( ) const
inlinenoexcept
Returns
true if file sorting can be skipped.

◆ is_spatial_index()

bool ddl::Builder::is_spatial_index ( ) const
inlinenoexcept
Returns
true if the index is a spatial index.

◆ is_unique_index()

bool ddl::Builder::is_unique_index ( ) const
inlinenoexcept
Returns
true if the index is a unique index.

◆ key_buffer_sort()

dberr_t ddl::Builder::key_buffer_sort ( size_t  thread_id)
privatenoexcept

Sort the data in the key buffer.

Parameters
[in]thread_idThread ID of current thread.
Returns
DB_SUCCESS or error code.

◆ merge_sort()

dberr_t ddl::Builder::merge_sort ( size_t  thread_id)
noexcept

Non-FTS: Sort the rows read.

Parameters
[in]thread_idThread state ID.
Returns
DB_SUCCESS or error code.

◆ set_error()

bool ddl::Builder::set_error ( dberr_t  err)
inlinenoexcept

Set the error code.

Parameters
[in]errError code to set.
Returns
true iff this thread successfully set the error code.

◆ set_next_state()

void ddl::Builder::set_next_state ( )
noexcept

Set the next state.

◆ set_state()

void ddl::Builder::set_state ( State  state)
inlinenoexcept

Set the next state.

Parameters
[in]stateState to set.

◆ setup_sort()

dberr_t ddl::Builder::setup_sort ( )
noexcept

Non-FTS: Sort the rows read.

Returns
DB_SUCCESS or error code.

◆ stage()

Alter_stage * ddl::Builder::stage ( )
inlinenoexcept
Returns
the PFS instance that is used to report progress (or nullptr).

◆ tmpdir()

const char * ddl::Builder::tmpdir ( ) const
inlinenoexcept
Returns
the path for temporary files.

◆ write_redo()

void ddl::Builder::write_redo ( const dict_index_t index)
staticnoexcept

Write an MLOG_INDEX_LOAD record to indicate in the redo-log that redo-logging of individual index pages was disabled, and the flushing of such pages to the data files was completed.

Parameters
[in]indexIndex on which redo logging was disabled

Member Data Documentation

◆ m_btr_load

Btree_load* ddl::Builder::m_btr_load {}
private

Cluster index bulk load instance to use, direct insert without a file sort.

◆ m_clust_dup

Dup ddl::Builder::m_clust_dup {}
private

For collecting duplicate entries (error reporting).

◆ m_conv_heap

Scoped_heap ddl::Builder::m_conv_heap {}
private

Scoped conversion heap.

◆ m_ctx

ddl::Context& ddl::Builder::m_ctx
private

DDL Context.

◆ m_id

size_t ddl::Builder::m_id {}
private

Buffer ID.

◆ m_index

dict_index_t* ddl::Builder::m_index {}
private

Index to create (if not FTS index).

◆ m_loader

Loader& ddl::Builder::m_loader
private

Loader that owns the instance.

◆ m_local_stage

Alter_stage* ddl::Builder::m_local_stage {}
private

Stage per builder.

◆ m_n_sort_tasks

std::atomic<size_t> ddl::Builder::m_n_sort_tasks {}
private

Number of active sort tasks.

◆ m_prev_fields

dfield_t* ddl::Builder::m_prev_fields {}
private

For tracking duplicates.

◆ m_sort_index

dict_index_t* ddl::Builder::m_sort_index {}
private

The index to be built, FTS or non-FTS.

◆ m_state

std::atomic<State> ddl::Builder::m_state {State::INIT}
private

Initial phase.

◆ m_thread_ctxs

Thread_ctxs ddl::Builder::m_thread_ctxs {}
private

Per thread context.

◆ m_tmpdir

const char* ddl::Builder::m_tmpdir {}
private

Temporary file path.

◆ m_v_heap

Scoped_heap ddl::Builder::m_v_heap {}
private

Scoped virtual column heap.


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