MySQL 9.1.0
Source Code Documentation
|
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_t * | m_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... | |
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.
|
private |
|
private |
|
private |
|
private |
|
private |
Current phase.
|
inlineexplicitnoexcept |
Constructor.
[in] | pk | primary key of the old table |
|
inlineexplicitnoexcept |
Copy constructor.
"Inherits" the current state of rhs.
[in] | rhs | Instance to copy current state from. |
|
inline |
Destructor.
|
inlinenoexcept |
Aggregate the results of the build from the sub builds.
[in] | alter_stages | Sub stages to aggregate. |
|
inline |
Flag the beginning of the end phase.
|
inline |
Flag the beginning of the flush phase.
[in] | n_flush_pages | this many pages are going to be flushed |
|
inline |
Flag the beginning of the insert phase.
|
inline |
Flag the beginning of the log index phase.
|
inline |
Flag the beginning of the log table phase.
|
inline |
Flag an ALTER TABLE start (read primary key phase).
[in] | n_sort_indexes | number of indexes that will be sorted during ALTER TABLE, used for estimating the total work to be done |
|
inline |
Flag the beginning of the sort phase.
[in] | sort_multi_factor | since merge sort processes one page more than once we only update the estimate once per this many pages processed. |
|
inlineprivate |
Change the current phase.
[in] | new_stage | pointer to the new stage to change to |
|
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.
|
inline |
Flag either one record or one page processed, depending on the current phase.
[in] | inc_val | flag this many units processed at once |
|
inline |
Increment the progress if we have crossed the threshold for unreported records, or if it is the last report.
[in,out] | unreported_recs | Number of records not updated to Alter_stage up till now. After reporting sets itself to 0. |
[in] | is_last_report | if true, update the status irrespective of number of unreported_recs. |
|
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.
[in] | n | Number of new records to report. |
|
inlineprivate |
Update the estimate of total work to be done.
|
inlineprivate |
Check whether we have seen enough records to increment the progress.
[in] | inc_val | this many units processed up til now |
|
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.
|
private |
Number of pages to flush.
Protected by m_mutex.
|
private |
Number of leaf pages in the primary key.
Protected by m_mutex.
|
private |
Number of records in the primary key (table), including delete marked records.
|
private |
Estimated number of records per page in the primary key.
Can only be modified between stages.
|
private |
Number of indexes that are being added.
Is only set during begin_phase_read_pk().
|
private |
Old table PK.
Used for calculating the estimate.
|
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.
|
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.
|
private |
Progress counters for the various stages.
|
private |
Collection of all [previous + current] stages.
Can only be modified between stages.
enum { ... } Alter_stage::NOT_STARTED |
Current phase.