1/* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
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 as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software Foundation,
14 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15
16#ifndef PFS_DIGEST_H
17#define PFS_DIGEST_H
18
19/**
20 @file storage/perfschema/pfs_digest.h
21 Statement Digest data structures (declarations).
22*/
23
24#include "pfs_column_types.h"
25#include "lf.h"
26#include "pfs_stat.h"
27#include "sql_digest.h"
28
29extern bool flag_statements_digest;
30extern size_t digest_max;
31extern ulong digest_lost;
32struct PFS_thread;
33
34/**
35 Structure to store a MD5 hash value (digest) for a statement.
36*/
37struct PFS_digest_key
38{
39 unsigned char m_md5[MD5_HASH_SIZE];
40 char m_schema_name[NAME_LEN];
41 uint m_schema_name_length;
42};
43
44/** A statement digest stat record. */
45struct PFS_ALIGNED PFS_statements_digest_stat
46{
47 /** Internal lock. */
48 pfs_lock m_lock;
49
50 /** Digest Schema + MD5 Hash. */
51 PFS_digest_key m_digest_key;
52
53 /** Digest Storage. */
54 sql_digest_storage m_digest_storage;
55
56 /** Statement stat. */
57 PFS_statement_stat m_stat;
58
59 /** First and last seen timestamps.*/
60 ulonglong m_first_seen;
61 ulonglong m_last_seen;
62
63 /** Reset data for this record. */
64 void reset_data(unsigned char* token_array, size_t length);
65 /** Reset data and remove index for this record. */
66 void reset_index(PFS_thread *thread);
67};
68
69int init_digest(const PFS_global_param *param);
70void cleanup_digest();
71
72int init_digest_hash(void);
73void cleanup_digest_hash(void);
74PFS_statement_stat* find_or_create_digest(PFS_thread *thread,
75 const sql_digest_storage *digest_storage,
76 const char *schema_name,
77 uint schema_name_length);
78
79void reset_esms_by_digest();
80
81/* Exposing the data directly, for iterators. */
82extern PFS_statements_digest_stat *statements_digest_stat_array;
83
84extern LF_HASH digest_hash;
85
86#endif
87