MySQL 8.0.31
Source Code Documentation
buf0stats.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2015, 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/buf0stats.h
28 Buffer pool stats
29
30 Created May 22, 2015 Vasil Dimov
31 *******************************************************/
32
33#ifndef buf0stats_h
34#define buf0stats_h
35
36#include "univ.i"
37
38#include "dict0types.h" /* index_id_t, DICT_IBUF_ID_MIN */
39#include "fsp0sysspace.h" /* srv_tmp_space */
40#include "ibuf0ibuf.h" /* IBUF_SPACE_ID */
41#include "ut0lock_free_hash.h" /* ut_lock_free_hash_t */
42#include "ut0new.h" /* ut::new_withkey(), ut::delete_() */
43
44/** Per index buffer pool statistics - contains how many pages for each index
45are cached in the buffer pool(s). This is a key,value store where the key is
46the index id and the value is the number of pages in the buffer pool that
47belong to this index. */
49 public:
50 /** Constructor. */
52 m_store = ut::new_withkey<ut_lock_free_hash_t>(
54 }
55
56 /** Destructor. */
58
59 /** Increment the number of pages for a given index with 1.
60 @param[in] id id of the index whose count to increment */
61 void inc(const index_id_t &id) {
62 if (should_skip(id)) {
63 return;
64 }
65
66 m_store->inc(id.conv_to_int());
67 }
68
69 /** Decrement the number of pages for a given index with 1.
70 @param[in] id id of the index whose count to decrement */
71 void dec(const index_id_t &id) {
72 if (should_skip(id)) {
73 return;
74 }
75
76 m_store->dec(id.conv_to_int());
77 }
78
79 /** Get the number of pages in the buffer pool for a given index.
80 @param[in] id id of the index whose pages to peek
81 @return number of pages */
82 uint64_t get(const index_id_t &id) {
83 if (should_skip(id)) {
84 return (0);
85 }
86
87 const int64_t ret = m_store->get(id.conv_to_int());
88
90 /* If the index is not found in this structure,
91 then 0 of its pages are in the buffer pool. */
92 return (0);
93 }
94
95 return (static_cast<uint64_t>(ret >= 0 ? ret : 0));
96 }
97
98 private:
99 /** Assess if we should skip a page from accounting.
100 @param[in] id index_id of the page
101 @return true if it should not be accounted */
102 bool should_skip(const index_id_t &id) {
103 const bool is_temp = fsp_is_system_temporary(id.m_space_id);
104
105 return (id.is_ibuf() || is_temp ||
106 (id.m_index_id & 0xFFFFFFFF00000000ULL) != 0);
107 }
108
109 /** (key, value) storage. */
111};
112
113/** Container for how many pages from each index are contained in the buffer
114pool(s). */
116
117#endif /* buf0stats_h */
buf_stat_per_index_t * buf_stat_per_index
Container for how many pages from each index are contained in the buffer pool(s).
Definition: buf0buf.cc:321
Per index buffer pool statistics - contains how many pages for each index are cached in the buffer po...
Definition: buf0stats.h:48
~buf_stat_per_index_t()
Destructor.
Definition: buf0stats.h:57
buf_stat_per_index_t()
Constructor.
Definition: buf0stats.h:51
ut_lock_free_hash_t * m_store
(key, value) storage.
Definition: buf0stats.h:110
void inc(const index_id_t &id)
Increment the number of pages for a given index with 1.
Definition: buf0stats.h:61
bool should_skip(const index_id_t &id)
Assess if we should skip a page from accounting.
Definition: buf0stats.h:102
void dec(const index_id_t &id)
Decrement the number of pages for a given index with 1.
Definition: buf0stats.h:71
uint64_t get(const index_id_t &id)
Get the number of pages in the buffer pool for a given index.
Definition: buf0stats.h:82
Globally unique index identifier.
Definition: dict0types.h:222
static const int64_t NOT_FOUND
The value that is returned when the searched for key is not found.
Definition: ut0lock_free_hash.h:55
Lock free hash table.
Definition: ut0lock_free_hash.h:373
void inc(uint64_t key) override
Increment the value for a given key with 1 or insert a new tuple (key, 1).
Definition: ut0lock_free_hash.h:556
void dec(uint64_t key) override
Decrement the value of a given key with 1 or insert a new tuple (key, -1).
Definition: ut0lock_free_hash.h:570
int64_t get(uint64_t key) const override
Get the value mapped to a given key.
Definition: ut0lock_free_hash.h:425
Data dictionary global types.
bool fsp_is_system_temporary(space_id_t space_id)
Check if tablespace is system temporary.
Definition: fsp0fsp.cc:298
Multi file, shared, system tablespace implementation.
Insert buffer.
void delete_(T *ptr) noexcept
Releases storage which has been dynamically allocated through any of the ut::new*() variants.
Definition: ut0new.h:807
PSI_memory_key_t make_psi_memory_key(PSI_memory_key key)
Convenience helper function to create type-safe representation of PSI_memory_key.
Definition: ut0new.h:188
Version control for database, common definitions, and include files.
Lock free hash implementation.
Dynamic memory allocation routines and custom allocators specifically crafted to support memory instr...
PSI_memory_key mem_key_buf_stat_per_index_t
Definition: ut0new.cc:49