MySQL 8.0.39
Source Code Documentation
dict0stats_bg.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2012, 2024, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/** @file include/dict0stats_bg.h
29 Code used for background table and index stats gathering.
30
31 Created Apr 26, 2012 Vasil Dimov
32 *******************************************************/
33
34#ifndef dict0stats_bg_h
35#define dict0stats_bg_h
36
37#include "univ.i"
38
39#include "dict0types.h"
40#include "os0event.h"
41#include "os0thread.h"
42#include "row0mysql.h"
43
44/** Event to wake up the stats thread */
46
47#ifdef HAVE_PSI_INTERFACE
49#endif /* HAVE_PSI_INTERFACE */
50
51#ifdef UNIV_DEBUG
52/** Value of MySQL global used to disable dict_stats thread. */
54#endif /* UNIV_DEBUG */
55
56/** Add a table to the recalc pool, which is processed by the
57 background stats gathering thread. Only the table id is added to the
58 list, so the table can be closed after being enqueued and it will be
59 opened when needed. If the table does not exist later (has been DROPped),
60 then it will be removed from the pool and skipped. */
62 const dict_table_t *table); /*!< in: table to add */
63
64/** Delete a given table from the auto recalc pool.
65 dict_stats_recalc_pool_del() */
67 const dict_table_t *table); /*!< in: table to remove */
68
69/** Yield the data dictionary latch when waiting
70for the background thread to stop accessing a table.
71@param[in] trx transaction holding the data dictionary locks
72@param[in] location location where called */
73static inline void DICT_STATS_BG_YIELD(trx_t *trx, ut::Location location) {
75 std::this_thread::sleep_for(std::chrono::milliseconds(250));
76 row_mysql_lock_data_dictionary(trx, location);
77}
78
79/** Request the background collection of statistics to stop for a table.
80 @retval true when no background process is active
81 @retval false when it is not safe to modify the table definition */
82[[nodiscard]] static inline bool dict_stats_stop_bg(
83 dict_table_t *table); /*!< in/out: table */
84
85/** Wait until background stats thread has stopped using the specified table.
86 The caller must have locked the data dictionary using
87 row_mysql_lock_data_dictionary() and this function may unlock it temporarily
88 and restore the lock before it exits.
89 The background stats thread is guaranteed not to start using the specified
90 table after this function returns and before the caller unlocks the data
91 dictionary because it sets the BG_STAT_IN_PROGRESS bit in table->stats_bg_flag
92 under dict_sys->mutex. */
94 dict_table_t *table, /*!< in/out: table */
95 trx_t *trx); /*!< in/out: transaction to use for
96 unlocking/locking the data dict */
97/** Initialize global variables needed for the operation of dict_stats_thread().
98 Must be called before dict_stats_thread() is started. */
100
101/** Free resources allocated by dict_stats_thread_init(), must be called
102 after dict_stats_thread() has exited. */
104
105#ifdef UNIV_DEBUG
106/** Disables dict stats thread. It's used by:
107 SET GLOBAL innodb_dict_stats_disabled_debug = 1 (0).
108@param[in] thd thread handle
109@param[in] var pointer to system variable
110@param[out] var_ptr where the formal string goes
111@param[in] save immediate result from check function */
112void dict_stats_disabled_debug_update(THD *thd, SYS_VAR *var, void *var_ptr,
113 const void *save);
114#endif /* UNIV_DEBUG */
115
116/** This is the thread for background stats gathering. It pops tables, from
117the auto recalc list and proceeds them, eventually recalculating their
118statistics. */
119void dict_stats_thread();
120
121/** Shutdown the dict stats thread. */
123
124#include "dict0stats_bg.ic"
125
126#endif /* dict0stats_bg_h */
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
os_event_t dict_stats_event
Event to wake up the stats thread.
Definition: dict0stats_bg.cc:59
void dict_stats_thread()
This is the thread for background stats gathering.
Definition: dict0stats_bg.cc:356
void dict_stats_recalc_pool_del(const dict_table_t *table)
Delete a given table from the auto recalc pool.
Definition: dict0stats_bg.cc:168
static void DICT_STATS_BG_YIELD(trx_t *trx, ut::Location location)
Yield the data dictionary latch when waiting for the background thread to stop accessing a table.
Definition: dict0stats_bg.h:73
void dict_stats_thread_init()
Initialize global variables needed for the operation of dict_stats_thread().
Definition: dict0stats_bg.cc:210
void dict_stats_disabled_debug_update(THD *thd, SYS_VAR *var, void *var_ptr, const void *save)
Disables dict stats thread.
Definition: dict0stats_bg.cc:335
static bool dict_stats_stop_bg(dict_table_t *table)
Request the background collection of statistics to stop for a table.
bool innodb_dict_stats_disabled_debug
Value of MySQL global used to disable dict_stats thread.
Definition: dict0stats_bg.cc:63
void dict_stats_thread_deinit()
Free resources allocated by dict_stats_thread_init(), must be called after dict_stats_thread() has ex...
Definition: dict0stats_bg.cc:238
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.
Definition: dict0stats_bg.cc:198
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.
Definition: dict0stats_bg.cc:118
mysql_pfs_key_t dict_stats_recalc_pool_mutex_key
void dict_stats_shutdown()
Shutdown the dict stats thread.
Definition: dict0stats_bg.cc:391
Code used for background table and index stats gathering.
Data dictionary global types.
The interface to the operating system condition variables.
The interface to the operating system process and thread control primitives.
Interface between Innobase row operations and MySQL.
void row_mysql_unlock_data_dictionary(trx_t *trx)
Unlocks the data dictionary exclusive lock.
Definition: row0mysql.cc:2714
void row_mysql_lock_data_dictionary(trx_t *trx, ut::Location location)
Locks the data dictionary exclusively for performing a table create or other data dictionary modifica...
Definition: row0mysql.cc:2700
Definition: plugin.h:67
Data structure for a database table.
Definition: dict0mem.h:1909
Define for performance schema registration key.
Definition: sync0sync.h:51
InnoDB condition variable.
Definition: os0event.cc:63
Definition: trx0trx.h:684
Definition: ut0core.h:33
Version control for database, common definitions, and include files.