28 #define PFS_SIZE_OF_A_TOKEN 2
30 extern bool flag_statements_digest;
31 extern ulong digest_max;
32 extern ulong digest_lost;
36 #define PFS_MD5_SIZE 16
43 unsigned char m_md5[PFS_MD5_SIZE];
44 char m_schema_name[NAME_LEN];
45 uint m_schema_name_length;
62 ulonglong m_last_seen;
71 void cleanup_digest();
73 int init_digest_hash(
void);
74 void cleanup_digest_hash(
void);
76 PSI_digest_storage *digest_storage,
77 const char *schema_name,
78 uint schema_name_length);
80 void get_digest_text(
char *digest_text, PSI_digest_storage *digest_storage);
82 void reset_esms_by_digest();
89 struct PSI_digest_locker *pfs_digest_start_v1(PSI_statement_locker *locker);
90 PSI_digest_locker *pfs_digest_add_token_v1(PSI_digest_locker *locker,
92 OPAQUE_LEX_YYSTYPE *yylval);
94 static inline void digest_reset(PSI_digest_storage *digest)
96 digest->m_full=
false;
97 digest->m_byte_count= 0;
98 digest->m_charset_number= 0;
101 static inline void digest_copy(PSI_digest_storage *
to,
const PSI_digest_storage *from)
103 if (from->m_byte_count > 0)
105 to->m_full= from->m_full;
106 to->m_byte_count= from->m_byte_count;
107 to->m_charset_number= from->m_charset_number;
108 DBUG_ASSERT(to->m_byte_count <= PSI_MAX_DIGEST_STORAGE_SIZE);
109 memcpy(to->m_token_array, from->m_token_array, to->m_byte_count);
113 DBUG_ASSERT(from->m_byte_count == 0);
116 to->m_charset_number= 0;
124 int index, uint *tok)
126 int safe_byte_count= digest_storage->m_byte_count;
128 if (index + PFS_SIZE_OF_A_TOKEN <= safe_byte_count &&
129 safe_byte_count <= PSI_MAX_DIGEST_STORAGE_SIZE)
131 unsigned char *src= & digest_storage->m_token_array[
index];
132 *tok= src[0] | (src[1] << 8);
133 return index + PFS_SIZE_OF_A_TOKEN;
138 return PSI_MAX_DIGEST_STORAGE_SIZE + 1;
144 inline void store_token(PSI_digest_storage* digest_storage, uint token)
146 DBUG_ASSERT(digest_storage->m_byte_count >= 0);
147 DBUG_ASSERT(digest_storage->m_byte_count <= PSI_MAX_DIGEST_STORAGE_SIZE);
149 if (digest_storage->m_byte_count + PFS_SIZE_OF_A_TOKEN <= PSI_MAX_DIGEST_STORAGE_SIZE)
151 unsigned char* dest= & digest_storage->m_token_array[digest_storage->m_byte_count];
152 dest[0]= token & 0xff;
153 dest[1]= (token >> 8) & 0xff;
154 digest_storage->m_byte_count+= PFS_SIZE_OF_A_TOKEN;
158 digest_storage->m_full=
true;
166 int index,
char ** id_string,
int *id_length)
169 DBUG_ASSERT(index <= digest_storage->m_byte_count);
170 DBUG_ASSERT(digest_storage->m_byte_count <= PSI_MAX_DIGEST_STORAGE_SIZE);
176 unsigned char *src= & digest_storage->m_token_array[
index];
177 uint length= src[0] | (src[1] << 8);
178 *id_string= (
char *) (src + 2);
181 new_index= index + PFS_SIZE_OF_A_TOKEN + length;
182 DBUG_ASSERT(new_index <= digest_storage->m_byte_count);
191 uint id_length,
const char *id_name)
193 DBUG_ASSERT(digest_storage->m_byte_count >= 0);
194 DBUG_ASSERT(digest_storage->m_byte_count <= PSI_MAX_DIGEST_STORAGE_SIZE);
196 uint bytes_needed= 2 * PFS_SIZE_OF_A_TOKEN + id_length;
197 if (digest_storage->m_byte_count + bytes_needed <= PSI_MAX_DIGEST_STORAGE_SIZE)
199 unsigned char* dest= & digest_storage->m_token_array[digest_storage->m_byte_count];
201 dest[0]= token & 0xff;
202 dest[1]= (token >> 8) & 0xff;
204 dest[2]= id_length & 0xff;
205 dest[3]= (id_length >> 8) & 0xff;
208 memcpy((
char *)(dest + 4), id_name, id_length);
209 digest_storage->m_byte_count+= bytes_needed;
213 digest_storage->m_full=
true;