MySQL 8.3.0
Source Code Documentation
Alter_stage Class Reference

Class used to report ALTER TABLE progress via performance_schema. More...

#include <ut0stage.h>

Public Member Functions

 Alter_stage (const dict_index_t *pk) noexcept
 Constructor. More...
 
 Alter_stage (const Alter_stage &rhs) noexcept
 Copy constructor. More...
 
 ~Alter_stage ()
 Destructor. More...
 
void begin_phase_read_pk (size_t n_sort_indexes)
 Flag an ALTER TABLE start (read primary key phase). More...
 
void n_pk_recs_inc ()
 Increment the number of records in PK (table) with 1. More...
 
void n_pk_recs_inc (uint64_t n)
 See simple increment version above. More...
 
void inc (uint64_t inc_val)
 Flag either one record or one page processed, depending on the current phase. More...
 
void end_phase_read_pk ()
 Flag the end of reading of the primary key. More...
 
void begin_phase_sort (double sort_multi_factor)
 Flag the beginning of the sort phase. More...
 
void begin_phase_insert ()
 Flag the beginning of the insert phase. More...
 
void begin_phase_flush (page_no_t n_flush_pages)
 Flag the beginning of the flush phase. More...
 
void begin_phase_log_index ()
 Flag the beginning of the log index phase. More...
 
void begin_phase_log_table ()
 Flag the beginning of the log table phase. More...
 
void begin_phase_end ()
 Flag the beginning of the end phase. More...
 
void aggregate (const Alter_stages &alter_stages) noexcept
 Aggregate the results of the build from the sub builds. More...
 

Private Types

enum  {
  NOT_STARTED = 0 , READ_PK = 1 , SORT = 2 , INSERT = 3 ,
  FLUSH = 4 , LOG_INDEX = 5 , LOG_TABLE = 6 , END = 7
}
 Current phase. More...
 
using Counter = std::pair< uint64_t, uint64_t >
 
using Progress = std::pair< PSI_stage_progress *, Counter >
 
using Stage = std::pair< const PSI_stage_info *, Progress >
 
using Stages = std::vector< Stage, ut::allocator< Stage > >
 

Private Member Functions

void reestimate ()
 Update the estimate of total work to be done. More...
 
void change_phase (const PSI_stage_info *new_stage)
 Change the current phase. More...
 

Private Attributes

Stage m_stage {}
 Progress counters for the various stages. More...
 
Stages m_stages {}
 Collection of previous stages. More...
 
const dict_index_tm_pk {}
 Old table PK. More...
 
std::atomic< uint64_t > m_n_pk_recs {}
 Number of records in the primary key (table), including delete marked records. More...
 
page_no_t m_n_pk_pages {}
 Number of leaf pages in the primary key. More...
 
double m_n_recs_per_page {}
 Estimated number of records per page in the primary key. More...
 
size_t m_n_sort_indexes {}
 Number of indexes that are being added. More...
 
uint64_t m_sort_multi_factor {}
 During the sort phase, increment the counter once per this many pages processed. More...
 
uint64_t m_n_inserted {}
 Number of records processed during sort & insert phases. More...
 
page_no_t m_n_flush_pages {}
 Number of pages to flush. More...
 
enum Alter_stage:: { ... }  NOT_STARTED
 Current phase. More...
 

Detailed Description

Class used to report ALTER TABLE progress via performance_schema.

The only user of this class is the ALTER TABLE code and it calls the methods in the following order constructor begin_phase_read_pk() multiple times: n_pk_recs_inc() // once per record read inc() // once per page read end_phase_read_pk() if any new indexes are being added, for each one: begin_phase_sort() multiple times: inc() // once per record sorted begin_phase_insert() multiple times: inc() // once per record inserted being_phase_log_index() multiple times: inc() // once per log-block applied begin_phase_flush() multiple times: inc() // once per page flushed begin_phase_log_table() multiple times: inc() // once per log-block applied begin_phase_end() destructor

This class knows the specifics of each phase and tries to increment the progress in an even manner across the entire ALTER TABLE lifetime.

Member Typedef Documentation

◆ Counter

using Alter_stage::Counter = std::pair<uint64_t, uint64_t>
private

◆ Progress

using Alter_stage::Progress = std::pair<PSI_stage_progress *, Counter>
private

◆ Stage

using Alter_stage::Stage = std::pair<const PSI_stage_info *, Progress>
private

◆ Stages

using Alter_stage::Stages = std::vector<Stage, ut::allocator<Stage> >
private

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

Current phase.

Enumerator
NOT_STARTED 

Init phase.

READ_PK 

Scan phase.

SORT 

Sort phase.

INSERT 

Bulk load/insert phase.

FLUSH 

Flush non-redo logged pages phase.

LOG_INDEX 

Apply entries from the row log to the index after creation.

LOG_TABLE 

Apply entries from the row log to the table after the build.

END 

End/Stop.

Constructor & Destructor Documentation

◆ Alter_stage() [1/2]

Alter_stage::Alter_stage ( const dict_index_t pk)
inlineexplicitnoexcept

Constructor.

Parameters
[in]pkprimary key of the old table

◆ Alter_stage() [2/2]

Alter_stage::Alter_stage ( const Alter_stage rhs)
inlineexplicitnoexcept

Copy constructor.

"Inherits" the current state of rhs.

Parameters
[in]rhsInstance to copy current state from.

◆ ~Alter_stage()

Alter_stage::~Alter_stage ( )
inline

Destructor.

Member Function Documentation

◆ aggregate()

void Alter_stage::aggregate ( const Alter_stages alter_stages)
inlinenoexcept

Aggregate the results of the build from the sub builds.

Parameters
[in]alter_stagesSub stages to aggregate.

◆ begin_phase_end()

void Alter_stage::begin_phase_end ( )
inline

Flag the beginning of the end phase.

◆ begin_phase_flush()

void Alter_stage::begin_phase_flush ( page_no_t  n_flush_pages)
inline

Flag the beginning of the flush phase.

Parameters
[in]n_flush_pagesthis many pages are going to be flushed

◆ begin_phase_insert()

void Alter_stage::begin_phase_insert ( )
inline

Flag the beginning of the insert phase.

◆ begin_phase_log_index()

void Alter_stage::begin_phase_log_index ( )
inline

Flag the beginning of the log index phase.

◆ begin_phase_log_table()

void Alter_stage::begin_phase_log_table ( )
inline

Flag the beginning of the log table phase.

◆ begin_phase_read_pk()

void Alter_stage::begin_phase_read_pk ( size_t  n_sort_indexes)
inline

Flag an ALTER TABLE start (read primary key phase).

Parameters
[in]n_sort_indexesnumber of indexes that will be sorted during ALTER TABLE, used for estimating the total work to be done

◆ begin_phase_sort()

void Alter_stage::begin_phase_sort ( double  sort_multi_factor)
inline

Flag the beginning of the sort phase.

Parameters
[in]sort_multi_factorsince merge sort processes one page more than once we only update the estimate once per this many pages processed.

◆ change_phase()

void Alter_stage::change_phase ( const PSI_stage_info new_stage)
inlineprivate

Change the current phase.

Parameters
[in]new_stagepointer to the new stage to change to

◆ end_phase_read_pk()

void Alter_stage::end_phase_read_pk ( )
inline

Flag the end of reading of the primary key.

Here we know the exact number of pages and records and calculate the number of records per page and refresh the estimate.

◆ inc()

void Alter_stage::inc ( uint64_t  inc_val)
inline

Flag either one record or one page processed, depending on the current phase.

Parameters
[in]inc_valflag this many units processed at once

◆ n_pk_recs_inc() [1/2]

void Alter_stage::n_pk_recs_inc ( )
inline

Increment the number of records in PK (table) with 1.

This is used to get more accurate estimate about the number of records per page which is needed because some phases work on per-page basis while some work on per-record basis and we want to get the progress as even as possible.

◆ n_pk_recs_inc() [2/2]

void Alter_stage::n_pk_recs_inc ( uint64_t  n)
inline

See simple increment version above.

Parameters
[in]nNumber fo records read so far.

◆ reestimate()

void Alter_stage::reestimate ( )
inlineprivate

Update the estimate of total work to be done.

Member Data Documentation

◆ m_n_flush_pages

page_no_t Alter_stage::m_n_flush_pages {}
private

Number of pages to flush.

◆ m_n_inserted

uint64_t Alter_stage::m_n_inserted {}
private

Number of records processed during sort & insert phases.

We need to increment the counter only once page, or once per recs-per-page records.

◆ m_n_pk_pages

page_no_t Alter_stage::m_n_pk_pages {}
private

Number of leaf pages in the primary key.

◆ m_n_pk_recs

std::atomic<uint64_t> Alter_stage::m_n_pk_recs {}
private

Number of records in the primary key (table), including delete marked records.

◆ m_n_recs_per_page

double Alter_stage::m_n_recs_per_page {}
private

Estimated number of records per page in the primary key.

◆ m_n_sort_indexes

size_t Alter_stage::m_n_sort_indexes {}
private

Number of indexes that are being added.

◆ m_pk

const dict_index_t* Alter_stage::m_pk {}
private

Old table PK.

Used for calculating the estimate.

◆ m_sort_multi_factor

uint64_t Alter_stage::m_sort_multi_factor {}
private

During the sort phase, increment the counter once per this many pages processed.

This is because sort processes one page more than once.

◆ m_stage

Stage Alter_stage::m_stage {}
private

Progress counters for the various stages.

◆ m_stages

Stages Alter_stage::m_stages {}
private

Collection of previous stages.

◆ 

enum { ... } Alter_stage::NOT_STARTED

Current phase.


The documentation for this class was generated from the following file: