MySQL 8.0.40
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 (uint64_t n=1)
 Increment the number of records in PK (table) with 1. More...
 
void inc (uint64_t inc_val)
 Flag either one record or one page processed, depending on the current phase. More...
 
void inc_progress_if_needed (uint64_t &unreported_recs, bool is_last_report=false)
 Increment the progress if we have crossed the threshold for unreported records, or if it is the last report. 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

bool should_inc_progress (uint64_t inc_val) const
 Check whether we have seen enough records to increment the progress. More...
 
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 all [previous + current] stages. More...
 
IB_mutex m_mutex {LATCH_ID_ALTER_STAGE}
 Mutex required to update values for m_n_pk_pages and m_n_flush_pages. 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...
 
uint64_t m_recs_req_for_prog {}
 Number of records for which we increment the progress. 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...
 
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(1) // once per page read end_phase_read_pk() if any new indexes are being added, for each one: begin_phase_sort() multiple times: inc(1) // once per every m_recs_req_for_prog records sorted begin_phase_insert() multiple times: inc(1) // once per every m_recs_req_for_prog records 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

◆ inc_progress_if_needed()

void Alter_stage::inc_progress_if_needed ( uint64_t &  unreported_recs,
bool  is_last_report = false 
)
inline

Increment the progress if we have crossed the threshold for unreported records, or if it is the last report.

Parameters
[in,out]unreported_recsNumber of records not updated to Alter_stage up till now. After reporting sets itself to 0.
[in]is_last_reportif true, update the status irrespective of number of unreported_recs.

◆ n_pk_recs_inc()

void Alter_stage::n_pk_recs_inc ( uint64_t  n = 1)
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.

Parameters
[in]nNumber of new records to report.

◆ reestimate()

void Alter_stage::reestimate ( )
inlineprivate

Update the estimate of total work to be done.

◆ should_inc_progress()

bool Alter_stage::should_inc_progress ( uint64_t  inc_val) const
inlineprivate

Check whether we have seen enough records to increment the progress.

Parameters
[in]inc_valthis many units processed up til now
Returns
true, if we have seen records as much to increment the progress.

Member Data Documentation

◆ m_mutex

IB_mutex Alter_stage::m_mutex {LATCH_ID_ALTER_STAGE}
private

Mutex required to update values for m_n_pk_pages and m_n_flush_pages.

We also use this mutex for reestimating & updating the progress, as it is done parallelly by multiple threads.

◆ m_n_flush_pages

page_no_t Alter_stage::m_n_flush_pages {}
private

Number of pages to flush.

Protected by m_mutex.

◆ m_n_pk_pages

page_no_t Alter_stage::m_n_pk_pages {}
private

Number of leaf pages in the primary key.

Protected by m_mutex.

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

Can only be modified between stages.

◆ m_n_sort_indexes

size_t Alter_stage::m_n_sort_indexes {}
private

Number of indexes that are being added.

Is only set during begin_phase_read_pk().

◆ m_pk

const dict_index_t* Alter_stage::m_pk {}
private

Old table PK.

Used for calculating the estimate.

◆ m_recs_req_for_prog

uint64_t Alter_stage::m_recs_req_for_prog {}
private

Number of records for which we increment the progress.

For READ_PK phase 1 For SORT phase m_n_recs_per_page * m_sort_multi_factor For INSERT phase m_n_recs_per_page Can only be modified between stages.

◆ 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. Can only be modified between stages.

◆ m_stage

Stage Alter_stage::m_stage {}
private

Progress counters for the various stages.

◆ m_stages

Stages Alter_stage::m_stages {}
private

Collection of all [previous + current] stages.

Can only be modified between stages.

◆ 

enum { ... } Alter_stage::NOT_STARTED

Current phase.


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