MySQL 8.4.3
Source Code Documentation
dd::info_schema::Table_statistics Class Reference

The class hold dynamic table statistics for a table. More...

#include <table_stats.h>

Public Member Functions

 Table_statistics ()
 
bool is_stat_cached_in_mem (const String &db_name, const String &table_name, const char *partition_name)
 Check if the stats are cached for given db.table_name. More...
 
bool is_stat_cached_in_mem (const String &db_name, const String &table_name)
 
void cache_stats_in_mem (const String &db_name, const String &table_name, const char *partition_name, handler *file)
 Store the statistics form the given handler. More...
 
void cache_stats_in_mem (const String &db_name, const String &table_name, handler *file)
 
void cache_stats_in_mem (const String &db_name, const String &table_name, const char *partition_name, ha_statistics &stats)
 Store the statistics. More...
 
void cache_stats_in_mem (const String &db_name, const String &table_name, ha_statistics &stats)
 
ulonglong read_stat (THD *thd, const String &schema_name_ptr, const String &table_name_ptr, const String &index_name_ptr, const char *partition_name, const String &column_name_ptr, uint index_ordinal_position, uint column_ordinal_position, const String &engine_name_ptr, dd::Object_id se_private_id, const char *ts_se_private_data, const char *tbl_se_private_data, const ulonglong &table_stat_data, const ulonglong &cached_time, enum_table_stats_type stype)
 Read dynamic table/index statistics from SE by opening the user table provided OR by reading cached statistics from Query_block. More...
 
ulonglong read_stat (THD *thd, const String &schema_name_ptr, const String &table_name_ptr, const String &engine_name_ptr, const char *partition_name, dd::Object_id se_private_id, const char *ts_se_private_data, const char *tbl_se_private_data, const ulonglong &table_stat_data, const ulonglong &cached_time, enum_table_stats_type stype)
 
void invalidate_cache (void)
 
String_type error ()
 
void store_error_message (const String &db_name, const String &table_name, const char *partition_name, const String_type &error_msg)
 Set error string for the given key. More...
 
bool check_error_for_key (const String &db_name, const String &table_name)
 Check if we have seen a error. More...
 
bool is_reading_stats_by_open () const
 Check if open table in progress. More...
 
bool is_valid () const
 Predicate for determinig if cache is valid. More...
 

Public Attributes

ha_statistics m_stats
 

Private Member Functions

ulonglong read_stat_from_SE (THD *thd, const String &schema_name_ptr, const String &table_name_ptr, const String &index_name_ptr, const String &column_name_ptr, uint index_ordinal_position, uint column_ordinal_position, dd::Object_id se_private_id, const char *ts_se_private_data, const char *tbl_se_private_data, enum_table_stats_type stype, handlerton *hton)
 Read dynamic table/index statistics from SE API's OR by reading cached statistics from Query_block. More...
 
ulonglong read_stat_by_open_table (THD *thd, const String &schema_name_ptr, const String &table_name_ptr, const String &index_name_ptr, const char *partition_name, const String &column_name_ptr, uint column_ordinal_position, enum_table_stats_type stype)
 Read dynamic table/index statistics by opening the table OR by reading cached statistics from Query_block. More...
 
void set_stat_cached (const String &db_name, const String &table_name, const char *partition_name)
 Mark the cache as valid for a given table. More...
 
void set_stat_cached (const String &db_name, const String &table_name)
 
String_type form_key (const String &db_name, const String &table_name, const char *partition_name)
 Build a key representing the table for which stats are cached. More...
 
ulonglong get_stat (ha_statistics &stat, enum_table_stats_type stype)
 Return statistics of the a given type. More...
 
ulonglong get_stat (enum_table_stats_type stype)
 
void set_checksum (ulonglong &&checksum)
 Set checksum. More...
 
ulonglong get_checksum () const
 Get checksum. More...
 
void set_read_stats_by_open (bool status)
 Set open table in progress. More...
 

Private Attributes

String_type m_key
 
String_type m_error
 
ulonglong m_checksum
 
bool m_read_stats_by_open
 

Detailed Description

The class hold dynamic table statistics for a table.

This cache is used by internal UDF's defined for the purpose of INFORMATION_SCHEMA queries which retrieve dynamic table statistics. The class caches statistics for just one table.

Overall aim of introducing this cache is to avoid making multiple calls to same SE API to retrieve the statistics.

Constructor & Destructor Documentation

◆ Table_statistics()

dd::info_schema::Table_statistics::Table_statistics ( )
inline

Member Function Documentation

◆ cache_stats_in_mem() [1/4]

void dd::info_schema::Table_statistics::cache_stats_in_mem ( const String db_name,
const String table_name,
const char *  partition_name,
ha_statistics stats 
)
inline

Store the statistics.

Parameters
db_name- Schema name.
table_name- Table name.
partition_name- Partition name.
stats- ha_statistics of the table.

◆ cache_stats_in_mem() [2/4]

void dd::info_schema::Table_statistics::cache_stats_in_mem ( const String db_name,
const String table_name,
const char *  partition_name,
handler file 
)
inline

Store the statistics form the given handler.

Parameters
db_name- Schema name.
table_name- Table name.
partition_name- Partition name.
file- Handler object for the table.

◆ cache_stats_in_mem() [3/4]

void dd::info_schema::Table_statistics::cache_stats_in_mem ( const String db_name,
const String table_name,
ha_statistics stats 
)
inline

◆ cache_stats_in_mem() [4/4]

void dd::info_schema::Table_statistics::cache_stats_in_mem ( const String db_name,
const String table_name,
handler file 
)
inline

◆ check_error_for_key()

bool dd::info_schema::Table_statistics::check_error_for_key ( const String db_name,
const String table_name 
)
inline

Check if we have seen a error.

Parameters
db_nameDatabase name.
table_nameTable name.
Returns
true if there is error reported. false if not.

◆ error()

String_type dd::info_schema::Table_statistics::error ( )
inline

◆ form_key()

String_type dd::info_schema::Table_statistics::form_key ( const String db_name,
const String table_name,
const char *  partition_name 
)
inlineprivate

Build a key representing the table for which stats are cached.

Parameters
db_name- Database name.
table_name- Table name.
partition_name- Partition name.
Returns
String_type representing the key.

◆ get_checksum()

ulonglong dd::info_schema::Table_statistics::get_checksum ( ) const
inlineprivate

Get checksum.

◆ get_stat() [1/2]

ulonglong dd::info_schema::Table_statistics::get_stat ( enum_table_stats_type  stype)
inlineprivate

◆ get_stat() [2/2]

ulonglong dd::info_schema::Table_statistics::get_stat ( ha_statistics stat,
enum_table_stats_type  stype 
)
private

Return statistics of the a given type.

Parameters
statha_statistics for the current cached table.
stypeType of statistics requested.
Returns
ulonglong statistics value.

◆ invalidate_cache()

void dd::info_schema::Table_statistics::invalidate_cache ( void  )
inline

◆ is_reading_stats_by_open()

bool dd::info_schema::Table_statistics::is_reading_stats_by_open ( ) const
inline

Check if open table in progress.

◆ is_stat_cached_in_mem() [1/2]

bool dd::info_schema::Table_statistics::is_stat_cached_in_mem ( const String db_name,
const String table_name 
)
inline

◆ is_stat_cached_in_mem() [2/2]

bool dd::info_schema::Table_statistics::is_stat_cached_in_mem ( const String db_name,
const String table_name,
const char *  partition_name 
)
inline

Check if the stats are cached for given db.table_name.

Parameters
db_name- Schema name.
table_name- Table name.
partition_name- Partition name.
Returns
true if stats are cached, else false.

◆ is_valid()

bool dd::info_schema::Table_statistics::is_valid ( void  ) const
inline

Predicate for determinig if cache is valid.

◆ read_stat() [1/2]

ulonglong dd::info_schema::Table_statistics::read_stat ( THD thd,
const String schema_name_ptr,
const String table_name_ptr,
const String engine_name_ptr,
const char *  partition_name,
dd::Object_id  se_private_id,
const char *  ts_se_private_data,
const char *  tbl_se_private_data,
const ulonglong table_stat_data,
const ulonglong cached_time,
enum_table_stats_type  stype 
)
inline

◆ read_stat() [2/2]

ulonglong dd::info_schema::Table_statistics::read_stat ( THD thd,
const String schema_name_ptr,
const String table_name_ptr,
const String index_name_ptr,
const char *  partition_name,
const String column_name_ptr,
uint  index_ordinal_position,
uint  column_ordinal_position,
const String engine_name_ptr,
dd::Object_id  se_private_id,
const char *  ts_se_private_data,
const char *  tbl_se_private_data,
const ulonglong table_stat_data,
const ulonglong cached_time,
enum_table_stats_type  stype 
)

Read dynamic table/index statistics from SE by opening the user table provided OR by reading cached statistics from Query_block.

Parameters
thd- Current thread.
schema_name_ptr- Schema name of table.
table_name_ptr- Table name of which we need stats.
index_name_ptr- Index name of which we need stats.
partition_name- Partition name.
column_name_ptr- Column name for index.
index_ordinal_position- Ordinal position of index in table.
column_ordinal_position- Ordinal position of column in table.
engine_name_ptr- Engine of the table.
se_private_id- se_private_id of the table.
ts_se_private_data- Tablespace SE private data.
tbl_se_private_data- Table SE private data.
table_stat_data- Cached data from mysql.table_stats / mysql.index_stats table
cached_time- Timestamp value when data was cached.
stype- Enum specifying the stat we are interested to read.
Returns
ulonglong representing value for the status being read.

◆ read_stat_by_open_table()

ulonglong dd::info_schema::Table_statistics::read_stat_by_open_table ( THD thd,
const String schema_name_ptr,
const String table_name_ptr,
const String index_name_ptr,
const char *  partition_name,
const String column_name_ptr,
uint  column_ordinal_position,
enum_table_stats_type  stype 
)
private

Read dynamic table/index statistics by opening the table OR by reading cached statistics from Query_block.

Parameters
thd- Current thread.
schema_name_ptr- Schema name of table.
table_name_ptr- Table name of which we need stats.
index_name_ptr- Index name of which we need stats.
column_name_ptr- Column name for index.
column_ordinal_position- Ordinal position of column in table.
partition_name- Partition name.
stype- Enum specifying the stat we are interested to read.
Returns
ulonglong representing value for the status being read.

◆ read_stat_from_SE()

ulonglong dd::info_schema::Table_statistics::read_stat_from_SE ( THD thd,
const String schema_name_ptr,
const String table_name_ptr,
const String index_name_ptr,
const String column_name_ptr,
uint  index_ordinal_position,
uint  column_ordinal_position,
dd::Object_id  se_private_id,
const char *  ts_se_private_data,
const char *  tbl_se_private_data,
enum_table_stats_type  stype,
handlerton hton 
)
private

Read dynamic table/index statistics from SE API's OR by reading cached statistics from Query_block.

Parameters
thd- Current thread.
schema_name_ptr- Schema name of table.
table_name_ptr- Table name of which we need stats.
index_name_ptr- Index name of which we need stats.
column_name_ptr- Column name for index.
index_ordinal_position- Ordinal position of index in table.
column_ordinal_position- Ordinal position of column in table.
se_private_id- se_private_id of the table.
ts_se_private_data- Tablespace SE private data.
tbl_se_private_data- Table SE private data.
stype- Enum specifying the stat we are interested to read.
hton- Handle to SE for the given table.
Returns
ulonglong representing value for the status being read.

◆ set_checksum()

void dd::info_schema::Table_statistics::set_checksum ( ulonglong &&  checksum)
inlineprivate

Set checksum.

◆ set_read_stats_by_open()

void dd::info_schema::Table_statistics::set_read_stats_by_open ( bool  status)
inlineprivate

Set open table in progress.

◆ set_stat_cached() [1/2]

void dd::info_schema::Table_statistics::set_stat_cached ( const String db_name,
const String table_name 
)
inlineprivate

◆ set_stat_cached() [2/2]

void dd::info_schema::Table_statistics::set_stat_cached ( const String db_name,
const String table_name,
const char *  partition_name 
)
inlineprivate

Mark the cache as valid for a given table.

This creates a key for the cache element. We store just a single table statistics in this cache.

Parameters
db_name- Database name.
table_name- Table name.
partition_name- Partition name.

◆ store_error_message()

void dd::info_schema::Table_statistics::store_error_message ( const String db_name,
const String table_name,
const char *  partition_name,
const String_type error_msg 
)
inline

Set error string for the given key.

The combination of (db, table and partition name) forms the key.

Parameters
db_name- Schema name.
table_name- Table name.
partition_name- Partition name.
error_msg- Error message.
Note
We store the error message so that the error message is shown in I_S.TABLES.COMMENT field. Apart from storing the error message, the below function resets the statistics, this will make sure,
  1. We do not invoke open_tables_for_query() again for other dynamic columns that are fetch from the current row being processed.
  2. We will not see junk values for statistics in results.

Member Data Documentation

◆ m_checksum

ulonglong dd::info_schema::Table_statistics::m_checksum
private

◆ m_error

String_type dd::info_schema::Table_statistics::m_error
private

◆ m_key

String_type dd::info_schema::Table_statistics::m_key
private

◆ m_read_stats_by_open

bool dd::info_schema::Table_statistics::m_read_stats_by_open
private

◆ m_stats

ha_statistics dd::info_schema::Table_statistics::m_stats

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