MySQL 8.0.40
Source Code Documentation
dict0stats_bg.cc File Reference

Code used for background table and index stats gathering. More...

#include "sql_thd_internal_api.h"
#include <stddef.h>
#include <sys/types.h>
#include <vector>
#include "dict0dd.h"
#include "dict0dict.h"
#include "dict0stats.h"
#include "dict0stats_bg.h"
#include "os0thread-create.h"
#include "row0mysql.h"
#include "srv0start.h"
#include "ut0new.h"

Typedefs

typedef ut::allocator< table_id_trecalc_pool_allocator_t
 Allocator type, used by std::vector. More...
 
typedef std::vector< table_id_t, recalc_pool_allocator_trecalc_pool_t
 The multitude of tables whose stats are to be automatically recalculated - an STL vector. More...
 
typedef recalc_pool_t::iterator recalc_pool_iterator_t
 Iterator type for iterating over the elements of objects of type recalc_pool_t. More...
 

Functions

static bool SHUTTING_DOWN ()
 
static void dict_stats_recalc_pool_init ()
 Initialize the recalc pool, called once during thread initialization. More...
 
static void dict_stats_recalc_pool_deinit ()
 Free the resources occupied by the recalc pool, called once during thread de-initialization. More...
 
void dict_stats_recalc_pool_add (const dict_table_t *table)
 Add a table to the recalc pool, which is processed by the background stats gathering thread. More...
 
static bool dict_stats_recalc_pool_get (table_id_t *id)
 Get a table from the auto recalc pool. More...
 
void dict_stats_recalc_pool_del (const dict_table_t *table)
 Delete a given table from the auto recalc pool. More...
 
void dict_stats_wait_bg_to_stop_using_table (dict_table_t *table, trx_t *trx)
 Wait until background stats thread has stopped using the specified table. More...
 
void dict_stats_thread_init ()
 Initialize global variables needed for the operation of dict_stats_thread() Must be called before dict_stats_thread() is started. More...
 
void dict_stats_thread_deinit ()
 Free resources allocated by dict_stats_thread_init(), must be called after dict_stats_thread() has exited. More...
 
static void dict_stats_process_entry_from_recalc_pool (THD *thd)
 Get the first table that has been added for auto recalc and eventually update its stats. More...
 
void dict_stats_disabled_debug_update (THD *, SYS_VAR *, void *, const void *save)
 Disables dict stats thread. More...
 
void dict_stats_thread ()
 This is the thread for background stats gathering. More...
 
void dict_stats_shutdown ()
 Shutdown the dict stats thread. More...
 

Variables

constexpr std::chrono::seconds MIN_RECALC_INTERVAL {10}
 Minimum time interval between stats recalc for a given table. More...
 
os_event_t dict_stats_event = nullptr
 Event to wake up the stats thread. More...
 
bool innodb_dict_stats_disabled_debug
 Used by SET GLOBAL innodb_dict_stats_disabled_debug = 1;. More...
 
static os_event_t dict_stats_disabled_event
 
static ib_mutex_t recalc_pool_mutex
 This mutex protects the "recalc_pool" variable. More...
 
static const ulint RECALC_POOL_INITIAL_SLOTS = 128
 The number of tables that can be added to "recalc_pool" before it is enlarged. More...
 
static recalc_pool_trecalc_pool
 Pool where we store information on which tables are to be processed by background statistics gathering. More...
 

Detailed Description

Code used for background table and index stats gathering.

Created Apr 25, 2012 Vasil Dimov

Typedef Documentation

◆ recalc_pool_allocator_t

Allocator type, used by std::vector.

◆ recalc_pool_iterator_t

typedef recalc_pool_t::iterator recalc_pool_iterator_t

Iterator type for iterating over the elements of objects of type recalc_pool_t.

◆ recalc_pool_t

The multitude of tables whose stats are to be automatically recalculated - an STL vector.

Function Documentation

◆ dict_stats_disabled_debug_update()

void dict_stats_disabled_debug_update ( THD thd,
SYS_VAR var,
void *  var_ptr,
const void *  save 
)

Disables dict stats thread.

It's used by: SET GLOBAL innodb_dict_stats_disabled_debug = 1 (0).

Parameters
[in]thdthread handle
[in]varpointer to system variable
[out]var_ptrwhere the formal string goes
[in]saveimmediate result from check function

◆ dict_stats_process_entry_from_recalc_pool()

static void dict_stats_process_entry_from_recalc_pool ( THD thd)
static

Get the first table that has been added for auto recalc and eventually update its stats.

Parameters
[in,out]thdcurrent thread

◆ dict_stats_recalc_pool_add()

void dict_stats_recalc_pool_add ( const dict_table_t table)

Add a table to the recalc pool, which is processed by the background stats gathering thread.

Only the table id is added to the list, so the table can be closed after being enqueued and it will be opened when needed. If the table does not exist later (has been DROPped), then it will be removed from the pool and skipped.

Parameters
tablein: table to add

◆ dict_stats_recalc_pool_deinit()

static void dict_stats_recalc_pool_deinit ( )
static

Free the resources occupied by the recalc pool, called once during thread de-initialization.

◆ dict_stats_recalc_pool_del()

void dict_stats_recalc_pool_del ( const dict_table_t table)

Delete a given table from the auto recalc pool.

dict_stats_recalc_pool_del()

Parameters
tablein: table to remove

◆ dict_stats_recalc_pool_get()

static bool dict_stats_recalc_pool_get ( table_id_t id)
static

Get a table from the auto recalc pool.

The returned table id is removed from the pool.

Returns
true if the pool was non-empty and "id" was set, false otherwise
Parameters
idout: table id, or unmodified if list is empty

◆ dict_stats_recalc_pool_init()

static void dict_stats_recalc_pool_init ( )
static

Initialize the recalc pool, called once during thread initialization.

◆ dict_stats_shutdown()

void dict_stats_shutdown ( )

Shutdown the dict stats thread.

◆ dict_stats_thread()

void dict_stats_thread ( )

This is the thread for background stats gathering.

It pops tables, from the auto recalc list and proceeds them, eventually recalculating their statistics.

◆ dict_stats_thread_deinit()

void dict_stats_thread_deinit ( )

Free resources allocated by dict_stats_thread_init(), must be called after dict_stats_thread() has exited.

◆ dict_stats_thread_init()

void dict_stats_thread_init ( )

Initialize global variables needed for the operation of dict_stats_thread() Must be called before dict_stats_thread() is started.

Initialize global variables needed for the operation of dict_stats_thread().

◆ dict_stats_wait_bg_to_stop_using_table()

void dict_stats_wait_bg_to_stop_using_table ( dict_table_t table,
trx_t trx 
)

Wait until background stats thread has stopped using the specified table.

The caller must have locked the data dictionary using row_mysql_lock_data_dictionary() and this function may unlock it temporarily and restore the lock before it exits. The background stats thread is guaranteed not to start using the specified table after this function returns and before the caller unlocks the data dictionary because it sets the BG_STAT_IN_PROGRESS bit in table->stats_bg_flag under dict_sys->mutex.

Parameters
tablein/out: table
trxin/out: transaction to use for unlocking/locking the data dict

◆ SHUTTING_DOWN()

static bool SHUTTING_DOWN ( )
inlinestatic

Variable Documentation

◆ dict_stats_disabled_event

os_event_t dict_stats_disabled_event
static

◆ dict_stats_event

os_event_t dict_stats_event = nullptr

Event to wake up the stats thread.

◆ innodb_dict_stats_disabled_debug

bool innodb_dict_stats_disabled_debug

Used by SET GLOBAL innodb_dict_stats_disabled_debug = 1;.

Value of MySQL global used to disable dict_stats thread.

◆ MIN_RECALC_INTERVAL

constexpr std::chrono::seconds MIN_RECALC_INTERVAL {10}
constexpr

Minimum time interval between stats recalc for a given table.

◆ recalc_pool

recalc_pool_t* recalc_pool
static

Pool where we store information on which tables are to be processed by background statistics gathering.

◆ RECALC_POOL_INITIAL_SLOTS

const ulint RECALC_POOL_INITIAL_SLOTS = 128
static

The number of tables that can be added to "recalc_pool" before it is enlarged.

◆ recalc_pool_mutex

ib_mutex_t recalc_pool_mutex
static

This mutex protects the "recalc_pool" variable.