MySQL 8.4.3
Source Code Documentation
buf0stats.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2015, 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/buf0stats.h
29 Buffer pool stats
30
31 Created May 22, 2015 Vasil Dimov
32 *******************************************************/
33
34#ifndef buf0stats_h
35#define buf0stats_h
36
37#include "univ.i"
38
39#include "dict0types.h" /* index_id_t, DICT_IBUF_ID_MIN */
40#include "fsp0sysspace.h" /* srv_tmp_space */
41#include "ibuf0ibuf.h" /* IBUF_SPACE_ID */
42#include "ut0lock_free_hash.h" /* ut_lock_free_hash_t */
43#include "ut0new.h" /* ut::new_withkey(), ut::delete_() */
44
45/** Per index buffer pool statistics - contains how many pages for each index
46are cached in the buffer pool(s). This is a key,value store where the key is
47the index id and the value is the number of pages in the buffer pool that
48belong to this index. */
50 public:
51 /** Constructor. */
53 m_store = ut::new_withkey<ut_lock_free_hash_t>(
55 }
56
57 /** Destructor. */
59
60 /** Increment the number of pages for a given index with 1.
61 @param[in] id id of the index whose count to increment */
62 void inc(const index_id_t &id) {
63 if (should_skip(id)) {
64 return;
65 }
66
67 m_store->inc(id.conv_to_int());
68 }
69
70 /** Decrement the number of pages for a given index with 1.
71 @param[in] id id of the index whose count to decrement */
72 void dec(const index_id_t &id) {
73 if (should_skip(id)) {
74 return;
75 }
76
77 m_store->dec(id.conv_to_int());
78 }
79
80 /** Get the number of pages in the buffer pool for a given index.
81 @param[in] id id of the index whose pages to peek
82 @return number of pages */
83 uint64_t get(const index_id_t &id) {
84 if (should_skip(id)) {
85 return (0);
86 }
87
88 const int64_t ret = m_store->get(id.conv_to_int());
89
91 /* If the index is not found in this structure,
92 then 0 of its pages are in the buffer pool. */
93 return (0);
94 }
95
96 return (static_cast<uint64_t>(ret >= 0 ? ret : 0));
97 }
98
99 private:
100 /** Assess if we should skip a page from accounting.
101 @param[in] id index_id of the page
102 @return true if it should not be accounted */
103 bool should_skip(const index_id_t &id) {
104 const bool is_temp = fsp_is_system_temporary(id.m_space_id);
105
106 return (id.is_ibuf() || is_temp ||
107 (id.m_index_id & 0xFFFFFFFF00000000ULL) != 0);
108 }
109
110 /** (key, value) storage. */
112};
113
114/** Container for how many pages from each index are contained in the buffer
115pool(s). */
117
118#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:326
Per index buffer pool statistics - contains how many pages for each index are cached in the buffer po...
Definition: buf0stats.h:49
~buf_stat_per_index_t()
Destructor.
Definition: buf0stats.h:58
buf_stat_per_index_t()
Constructor.
Definition: buf0stats.h:52
ut_lock_free_hash_t * m_store
(key, value) storage.
Definition: buf0stats.h:111
void inc(const index_id_t &id)
Increment the number of pages for a given index with 1.
Definition: buf0stats.h:62
bool should_skip(const index_id_t &id)
Assess if we should skip a page from accounting.
Definition: buf0stats.h:103
void dec(const index_id_t &id)
Decrement the number of pages for a given index with 1.
Definition: buf0stats.h:72
uint64_t get(const index_id_t &id)
Get the number of pages in the buffer pool for a given index.
Definition: buf0stats.h:83
Globally unique index identifier.
Definition: dict0types.h:237
static const int64_t NOT_FOUND
The value that is returned when the searched for key is not found.
Definition: ut0lock_free_hash.h:56
Lock free hash table.
Definition: ut0lock_free_hash.h:374
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:557
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:571
int64_t get(uint64_t key) const override
Get the value mapped to a given key.
Definition: ut0lock_free_hash.h:426
Data dictionary global types.
bool fsp_is_system_temporary(space_id_t space_id)
Check if tablespace is system temporary.
Definition: fsp0fsp.cc:305
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:810
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:190
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:50