1
/* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
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.
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.
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 */
23
#define MAX_DIGEST_STORAGE_SIZE (1024*1024)
26
Structure to store token count/array for a statement
27
on which digest is to be calculated.
29
struct sql_digest_storage
33
unsigned char m_md5[MD5_HASH_SIZE];
34
/** Character set number. */
35
uint m_charset_number;
38
Token array is an array of bytes to store tokens received during parsing.
39
Following is the way token array is formed.
40
... <non-id-token> <non-id-token> <id-token> <id_len> <id_text> ...
43
<SELECT_TOKEN> <*> <FROM_TOKEN> <ID_TOKEN> <2> <T1>
45
unsigned char *m_token_array;
46
/* Length of the token array to be considered for DIGEST_TEXT calculation. */
47
uint m_token_array_length;
54
inline void reset(unsigned char *token_array, uint length)
56
m_token_array= token_array;
57
m_token_array_length= length;
66
if (m_token_array_length > 0)
68
memset(m_token_array, 0, m_token_array_length);
70
memset(m_md5, 0, MD5_HASH_SIZE);
73
inline bool is_empty()
75
return (m_byte_count == 0);
78
inline void copy(const sql_digest_storage *from)
81
Keep in mind this is a dirty copy of something that may change,
82
as the thread producing the digest is executing concurrently,
83
without any lock enforced.
85
uint byte_count_copy= m_token_array_length < from->m_byte_count ?
86
m_token_array_length : from->m_byte_count;
88
if (byte_count_copy > 0)
91
m_byte_count= byte_count_copy;
92
m_charset_number= from->m_charset_number;
93
memcpy(m_token_array, from->m_token_array, m_byte_count);
94
memcpy(m_md5, from->m_md5, MD5_HASH_SIZE);
104
typedef struct sql_digest_storage sql_digest_storage;
107
Compute a digest hash.
108
@param digest_storage The digest
109
@param [out] md5 The computed digest hash. This parameter is a buffer of size @c MD5_HASH_SIZE.
111
void compute_digest_md5(const sql_digest_storage *digest_storage, unsigned char *md5);
114
Compute a digest text.
115
A 'digest text' is a textual representation of a query,
117
- comments are removed,
118
- non significant spaces are removed,
119
- literal values are replaced with a special '?' marker,
120
- lists of values are collapsed using a shorter notation
121
@param digest_storage The digest
122
@param [out] digest_text
123
@param digest_text_length Size of @c digest_text.
124
@param [out] truncated true if the text representation was truncated
126
void compute_digest_text(const sql_digest_storage *digest_storage,
127
String *digest_text);