MySQL 9.1.0
Source Code Documentation
pfs_digest.h
Go to the documentation of this file.
1/* Copyright (c) 2011, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef PFS_DIGEST_H
25#define PFS_DIGEST_H
26
27/**
28 @file storage/perfschema/pfs_digest.h
29 Statement Digest data structures (declarations).
30*/
31
32#include <sys/types.h>
33#include <atomic>
34
35#include "lf.h"
36#include "my_inttypes.h"
37#include "mysql_com.h"
38#include "sql/sql_digest.h"
44
45extern bool flag_statements_digest;
46extern size_t digest_max;
47extern ulong digest_lost;
48struct PFS_thread;
49
50/**
51 Structure to store a hash value (digest) for a statement.
52*/
55 unsigned char m_hash[DIGEST_HASH_SIZE];
56};
57
58/** A statement digest stat record. */
60 /** Internal lock. */
62
63 /** Digest Schema + Digest Hash. */
65
66 /** Digest Storage. */
68
69 /** Statement stat. */
71
72 /** Query sample SQL text. */
74 /** Length of @c m_query_sample. */
76 /** True if @c m_query_sample was truncated. */
78 /** Statement character set number. */
80 /** Query sample seen timestamp.*/
82 /** Query sample timer wait.*/
83 std::atomic<std::uint64_t> m_query_sample_timer_wait;
84 /** Query sample reference count. */
85 std::atomic<std::uint32_t> m_query_sample_refs;
86
87 /** First and last seen timestamps.*/
90
91 // FIXME : allocate in separate buffer
93
94 /** Reset data for this record. */
95 void reset_data(unsigned char *token_array, size_t token_array_length,
96 char *query_sample_array);
97 /** Reset data and remove index for this record. */
98 void reset_index(PFS_thread *thread);
99
100 /** Get the age in micro seconds of the last query sample. */
102 const ulonglong age = m_last_seen - m_query_sample_seen;
103 return age;
104 }
105
106 /** Set the query sample wait time. */
108 m_query_sample_timer_wait.store(wait_time);
109 }
110
111 /** Get the query sample wait time. */
112 ulonglong get_sample_timer_wait() { return m_query_sample_timer_wait.load(); }
113
114 /** Increment the query sample reference count. */
116 /* Return value prior to increment. */
117 return (uint)m_query_sample_refs.fetch_add(1);
118 }
119
120 /** Decrement the query sample reference count. */
122 /* Return value prior to decrement. */
123 return (uint)m_query_sample_refs.fetch_sub(1);
124 }
125};
126
127int init_digest(const PFS_global_param *param);
128void cleanup_digest();
129
130int init_digest_hash(const PFS_global_param *param);
133 PFS_thread *thread, const sql_digest_storage *digest_storage,
134 const char *schema_name, uint schema_name_length);
135
138
139/* Exposing the data directly, for iterators. */
141
142extern LF_HASH digest_hash;
143
144#endif
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
static int wait_time
Definition: mysql.cc:213
Common definition between mysql server & client.
Data types for columns used in the performance schema tables (declarations)
int init_digest(const PFS_global_param *param)
Initialize table EVENTS_STATEMENTS_SUMMARY_BY_DIGEST.
Definition: pfs_digest.cc:77
bool flag_statements_digest
Consumer flag for table EVENTS_STATEMENTS_SUMMARY_BY_DIGEST.
Definition: pfs_digest.cc:62
int init_digest_hash(const PFS_global_param *param)
Initialize the digest hash.
Definition: pfs_digest.cc:220
PFS_statements_digest_stat * statements_digest_stat_array
EVENTS_STATEMENTS_SUMMARY_BY_DIGEST buffer.
Definition: pfs_digest.cc:58
LF_HASH digest_hash
Definition: pfs_digest.cc:70
void cleanup_digest_hash()
Definition: pfs_digest.cc:231
void cleanup_digest()
Cleanup table EVENTS_STATEMENTS_SUMMARY_BY_DIGEST.
Definition: pfs_digest.cc:147
ulong digest_lost
Definition: pfs_digest.cc:55
PFS_statements_digest_stat * find_or_create_digest(PFS_thread *thread, const sql_digest_storage *digest_storage, const char *schema_name, uint schema_name_length)
Definition: pfs_digest.cc:248
void reset_esms_by_digest()
Definition: pfs_digest.cc:421
size_t digest_max
Definition: pfs_digest.cc:54
void reset_histogram_by_digest()
Definition: pfs_digest.cc:453
#define PFS_ALIGNED
Definition: pfs_global.h:57
Performance schema internal locks (declarations).
Object names (declarations).
Statistics (declarations).
#define DIGEST_HASH_SIZE
DIGEST hash size, in bytes.
Definition: sql_digest.h:90
Definition: lf.h:187
Structure to store a hash value (digest) for a statement.
Definition: pfs_digest.h:53
PFS_schema_name m_schema_name
Definition: pfs_digest.h:54
unsigned char m_hash[DIGEST_HASH_SIZE]
Definition: pfs_digest.h:55
Performance schema global sizing parameters.
Definition: pfs_server.h:124
Definition: pfs_histogram.h:38
Definition: pfs_name.h:194
Statistics for statement usage.
Definition: pfs_stat.h:376
A statement digest stat record.
Definition: pfs_digest.h:59
sql_digest_storage m_digest_storage
Digest Storage.
Definition: pfs_digest.h:67
ulonglong m_query_sample_seen
Query sample seen timestamp.
Definition: pfs_digest.h:81
ulonglong get_sample_timer_wait()
Get the query sample wait time.
Definition: pfs_digest.h:112
std::atomic< std::uint32_t > m_query_sample_refs
Query sample reference count.
Definition: pfs_digest.h:85
uint m_query_sample_cs_number
Statement character set number.
Definition: pfs_digest.h:79
ulonglong m_last_seen
Definition: pfs_digest.h:89
ulonglong get_sample_age() const
Get the age in micro seconds of the last query sample.
Definition: pfs_digest.h:101
PFS_digest_key m_digest_key
Digest Schema + Digest Hash.
Definition: pfs_digest.h:64
uint dec_sample_ref()
Decrement the query sample reference count.
Definition: pfs_digest.h:121
char * m_query_sample
Query sample SQL text.
Definition: pfs_digest.h:73
uint inc_sample_ref()
Increment the query sample reference count.
Definition: pfs_digest.h:115
PFS_statement_stat m_stat
Statement stat.
Definition: pfs_digest.h:70
std::atomic< std::uint64_t > m_query_sample_timer_wait
Query sample timer wait.
Definition: pfs_digest.h:83
void set_sample_timer_wait(ulonglong wait_time)
Set the query sample wait time.
Definition: pfs_digest.h:107
pfs_lock m_lock
Internal lock.
Definition: pfs_digest.h:61
size_t m_query_sample_length
Length of m_query_sample.
Definition: pfs_digest.h:75
bool m_query_sample_truncated
True if m_query_sample was truncated.
Definition: pfs_digest.h:77
PFS_histogram m_histogram
Definition: pfs_digest.h:92
ulonglong m_first_seen
First and last seen timestamps.
Definition: pfs_digest.h:88
Instrumented thread implementation.
Definition: pfs_instr.h:375
A 'lock' protecting performance schema internal buffers.
Definition: pfs_lock.h:154
Structure to store token count/array for a statement on which digest is to be calculated.
Definition: sql_digest.h:98