MySQL 8.4.2
Source Code Documentation
dict0stats.h File Reference

Code used for calculating and manipulating table statistics. More...

#include "univ.i"
#include "dict0types.h"
#include "mem0mem.h"
#include "trx0types.h"
#include "dict0stats.ic"

Go to the source code of this file.

Classes

class  TableStatsRecord
 Represent the record of innodb_table_stats table. More...
 

Enumerations

enum  dict_stats_upd_option_t { DICT_STATS_RECALC_PERSISTENT , DICT_STATS_RECALC_TRANSIENT , DICT_STATS_EMPTY_TABLE , DICT_STATS_FETCH_ONLY_IF_NOT_IN_MEMORY }
 

Functions

static void dict_stats_set_persistent (dict_table_t *table, bool ps_on, bool ps_off)
 Set the persistent statistics flag for a given table. More...
 
static bool dict_stats_is_persistent_enabled (const dict_table_t *table)
 Check whether persistent statistics is enabled for a given table. More...
 
static void dict_stats_auto_recalc_set (dict_table_t *table, bool auto_recalc_on, bool auto_recalc_off)
 Set the auto recalc flag for a given table (only honored for a persistent stats enabled table). More...
 
static bool dict_stats_auto_recalc_is_enabled (const dict_table_t *table)
 Check whether auto recalc is enabled for a given table. More...
 
static void dict_stats_init (dict_table_t *table)
 Initialize table's stats for the first time when opening a table. More...
 
static void dict_stats_deinit (dict_table_t *table)
 Deinitialize table's stats after the last close of the table. More...
 
dberr_t dict_stats_update (dict_table_t *table, dict_stats_upd_option_t stats_upd_option, trx_t *trx=nullptr)
 Calculates new estimates for table and index statistics. More...
 
dberr_t dict_stats_drop_index (const char *tname, const char *iname, char *errstr, ulint errstr_sz)
 Removes the information for a particular index's stats from the persistent storage if it exists and if there is data stored for this index. More...
 
dberr_t dict_stats_drop_table (const char *table_name, char *errstr, ulint errstr_sz)
 Removes the statistics for a table and all of its indexes from the persistent storage if it exists and if there is data stored for the table. More...
 
void dict_stats_update_for_index (dict_index_t *index)
 Fetches or calculates new estimates for index statistics. More...
 
dberr_t dict_stats_rename_table (const char *old_name, const char *new_name, char *errstr, size_t errstr_sz)
 Renames a table in InnoDB persistent stats storage. More...
 
dberr_t dict_stats_rename_index (const dict_table_t *table, const char *old_index_name, const char *new_index_name)
 Renames an index in InnoDB persistent stats storage. More...
 

Detailed Description

Code used for calculating and manipulating table statistics.

Created Jan 06, 2010 Vasil Dimov

Enumeration Type Documentation

◆ dict_stats_upd_option_t

Enumerator
DICT_STATS_RECALC_PERSISTENT 
DICT_STATS_RECALC_TRANSIENT 
DICT_STATS_EMPTY_TABLE 
DICT_STATS_FETCH_ONLY_IF_NOT_IN_MEMORY 

Function Documentation

◆ dict_stats_auto_recalc_is_enabled()

static bool dict_stats_auto_recalc_is_enabled ( const dict_table_t table)
inlinestatic

Check whether auto recalc is enabled for a given table.

Returns
true if enabled, false otherwise in: table

◆ dict_stats_auto_recalc_set()

static void dict_stats_auto_recalc_set ( dict_table_t table,
bool  auto_recalc_on,
bool  auto_recalc_off 
)
inlinestatic

Set the auto recalc flag for a given table (only honored for a persistent stats enabled table).

The flag is set only in the in-memory table object and is not saved in InnoDB files. It will be read from the .frm file upon first open from MySQL after a server restart.

Parameters
[in,out]tabletable
[in]auto_recalc_onexplicitly enabled
[in]auto_recalc_offexplicitly disabled

◆ dict_stats_deinit()

static void dict_stats_deinit ( dict_table_t table)
inlinestatic

Deinitialize table's stats after the last close of the table.

This is used to detect "FLUSH TABLE" and refresh the stats upon next open. in/out: table

◆ dict_stats_drop_index()

dberr_t dict_stats_drop_index ( const char *  db_and_table,
const char *  iname,
char *  errstr,
ulint  errstr_sz 
)

Removes the information for a particular index's stats from the persistent storage if it exists and if there is data stored for this index.

This function creates its own trx and commits it.

Returns
DB_SUCCESS or error code in: size of the errstr buffer

This function creates its own trx and commits it. A note from Marko why we cannot edit user and sys_* tables in one trx: marko: The problem is that ibuf merges should be disabled while we are rolling back dict transactions. marko: If ibuf merges are not disabled, we need to scan the *.ibd files. But we shouldn't open *.ibd files before we have rolled back dict transactions and opened the SYS_* records for the *.ibd files.

Returns
DB_SUCCESS or error code
Parameters
db_and_tablein: db and table, e.g. 'db/table'
inamein: index name
errstrout: error message if != DB_SUCCESS is returned
errstr_szin: size of the errstr buffer

◆ dict_stats_drop_table()

dberr_t dict_stats_drop_table ( const char *  db_and_table,
char *  errstr,
ulint  errstr_sz 
)

Removes the statistics for a table and all of its indexes from the persistent storage if it exists and if there is data stored for the table.

This function creates its own transaction and commits it.

Returns
DB_SUCCESS or error code in: size of errstr buffer

Removes the statistics for a table and all of its indexes from the persistent storage if it exists and if there is data stored for the table.

This function creates its own transaction and commits it.

Returns
DB_SUCCESS or error code
Parameters
db_and_tablein: db and table, e.g. 'db/table'
errstrout: error message if != DB_SUCCESS is returned
errstr_szin: size of errstr buffer

◆ dict_stats_init()

static void dict_stats_init ( dict_table_t table)
inlinestatic

Initialize table's stats for the first time when opening a table.

in/out: table

◆ dict_stats_is_persistent_enabled()

static bool dict_stats_is_persistent_enabled ( const dict_table_t table)
inlinestatic

Check whether persistent statistics is enabled for a given table.

Returns
true if enabled, false otherwise in: table

◆ dict_stats_rename_index()

dberr_t dict_stats_rename_index ( const dict_table_t table,
const char *  old_index_name,
const char *  new_index_name 
)

Renames an index in InnoDB persistent stats storage.

This function creates its own transaction and commits it.

Returns
DB_SUCCESS or error code. DB_STATS_DO_NOT_EXIST will be returned if the persistent stats do not exist. in: new index name

This function creates its own transaction and commits it.

Returns
DB_SUCCESS or error code. DB_STATS_DO_NOT_EXIST will be returned if the persistent stats do not exist.
Parameters
tablein: table whose index is renamed
old_index_namein: old index name
new_index_namein: new index name

◆ dict_stats_rename_table()

dberr_t dict_stats_rename_table ( const char *  old_name,
const char *  new_name,
char *  errstr,
size_t  errstr_sz 
)

Renames a table in InnoDB persistent stats storage.

This function creates its own transaction and commits it.

Returns
DB_SUCCESS or error code in: errstr size

This function creates its own transaction and commits it.

Returns
DB_SUCCESS or error code
Parameters
old_namein: old name, e.g. 'db/table'
new_namein: new name, e.g. 'db/table'
errstrout: error string if != DB_SUCCESS is returned
errstr_szin: errstr size

◆ dict_stats_set_persistent()

static void dict_stats_set_persistent ( dict_table_t table,
bool  ps_on,
bool  ps_off 
)
inlinestatic

Set the persistent statistics flag for a given table.

This is set only in the in-memory table object and is not saved on disk. It will be read from the .frm file upon first open from MySQL after a server restart.

Parameters
[in,out]tabletable
[in]ps_onpersistent stats explicitly enabled
[in]ps_offpersistent stats explicitly disabled

◆ dict_stats_update()

dberr_t dict_stats_update ( dict_table_t table,
dict_stats_upd_option_t  stats_upd_option,
trx_t trx = nullptr 
)

Calculates new estimates for table and index statistics.

The statistics are used in query optimization.

Parameters
[in]tabletable for which statistics are to be updated.
[in]stats_upd_optionstatistics update option (persistent, etc).
[in]trxstatistics update will be done as part of this transaction. if null, a new transaction will be internally created.
Returns
DB_* error code or DB_SUCCESS

◆ dict_stats_update_for_index()

void dict_stats_update_for_index ( dict_index_t index)

Fetches or calculates new estimates for index statistics.

in/out: index

Parameters
indexin/out: index