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