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