Skip to content
/ server Public
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mysql-test/include/check_digest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ returns tinyint
not deterministic
begin
declare digest_exists tinyint;
if length(digest) != 32 or conv(digest, 16, 10) = 0 then
if length(digest) != 32 or digest is null then
return 0;
end if;
select exists (select d from test._digests where d = digest) into digest_exists;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ CREATE DEFINER='mariadb.sys'@'localhost' PROCEDURE ps_trace_statement_digest (

When finding a statement of interest within the
performance_schema.events_statements_summary_by_digest table, feed
the DIGEST MD5 value in to this procedure, set how long to poll for,
the DIGEST hash value in to this procedure, set how long to poll for,
and at what interval to poll, and it will generate a report of all
statistics tracked within Performance Schema for that digest for the
interval.
Expand Down
10 changes: 5 additions & 5 deletions sql/sql_digest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

#include "mariadb.h"
#include "my_md5.h"
#include "../mysys/xxhash.h"
#include "unireg.h"

#include "sql_string.h"
Expand Down Expand Up @@ -157,11 +157,11 @@ inline void store_token_identifier(sql_digest_storage* digest_storage,
}
}

void compute_digest_md5(const sql_digest_storage *digest_storage, unsigned char *md5)
void compute_digest_hash(const sql_digest_storage *digest_storage, unsigned char *hash)
{
compute_md5_hash(md5,
(const char *) digest_storage->m_token_array,
digest_storage->m_byte_count);
XXH128_hash_t res = XXH3_128bits(digest_storage->m_token_array,
digest_storage->m_byte_count);
memcpy(hash, &res, sizeof(res));
}

/*
Expand Down
13 changes: 7 additions & 6 deletions sql/sql_digest.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

#include <string.h>
class String;
#include "my_md5.h"

#define MAX_DIGEST_STORAGE_SIZE (1024*1024)

#define DIGEST_HASH_SIZE 16

/**
Structure to store token count/array for a statement
on which digest is to be calculated.
Expand All @@ -30,7 +31,7 @@ struct sql_digest_storage
{
bool m_full;
uint m_byte_count;
unsigned char m_md5[MD5_HASH_SIZE];
unsigned char m_hash[DIGEST_HASH_SIZE];
/** Character set number. */
uint m_charset_number;
/**
Expand Down Expand Up @@ -66,7 +67,7 @@ struct sql_digest_storage
m_full= false;
m_byte_count= 0;
m_charset_number= 0;
memset(m_md5, 0, MD5_HASH_SIZE);
memset(m_hash, 0, DIGEST_HASH_SIZE);
}

inline bool is_empty()
Expand All @@ -90,7 +91,7 @@ struct sql_digest_storage
m_byte_count= byte_count_copy;
m_charset_number= from->m_charset_number;
memcpy(m_token_array, from->m_token_array, m_byte_count);
memcpy(m_md5, from->m_md5, MD5_HASH_SIZE);
memcpy(m_hash, from->m_hash, DIGEST_HASH_SIZE);
}
else
{
Expand All @@ -105,9 +106,9 @@ typedef struct sql_digest_storage sql_digest_storage;
/**
Compute a digest hash.
@param digest_storage The digest
@param [out] md5 The computed digest hash. This parameter is a buffer of size @c MD5_HASH_SIZE.
@param [out] hash The computed digest hash. This parameter is a buffer of size @c DIGEST_HASH_SIZE.
*/
void compute_digest_md5(const sql_digest_storage *digest_storage, unsigned char *md5);
void compute_digest_hash(const sql_digest_storage *digest_storage, unsigned char *hash);

/**
Compute a digest text.
Expand Down
2 changes: 1 addition & 1 deletion storage/perfschema/pfs_column_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#define COL_SOURCE_SIZE 64

/** Size of the DIGEST columns. */
#define COL_DIGEST_SIZE 64
#define COL_DIGEST_SIZE 32

/**
Enum values for the TIMER_NAME columns.
Expand Down
6 changes: 3 additions & 3 deletions storage/perfschema/pfs_digest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ find_or_create_digest(PFS_thread *thread,
*/
PFS_digest_key hash_key;
memset(& hash_key, 0, sizeof(hash_key));
/* Compute MD5 Hash of the tokens received. */
compute_digest_md5(digest_storage, hash_key.m_md5);
memcpy((void*)& digest_storage->m_md5, &hash_key.m_md5, MD5_HASH_SIZE);
/* Comchpute digest hash of the tokens received. */
compute_digest_hash(digest_storage, hash_key.m_hash);
memcpy((void*)& digest_storage->m_hash, &hash_key.m_hash, DIGEST_HASH_SIZE);
/* Add the current schema to the key */
hash_key.m_schema_name_length= schema_name_length;
if (schema_name_length > 0)
Expand Down
6 changes: 3 additions & 3 deletions storage/perfschema/pfs_digest.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ extern ulong digest_lost;
struct PFS_thread;

/**
Structure to store a MD5 hash value (digest) for a statement.
Structure to store a hash value (digest) for a statement.
*/
struct PFS_digest_key
{
unsigned char m_md5[MD5_HASH_SIZE];
unsigned char m_hash[DIGEST_HASH_SIZE];
char m_schema_name[NAME_LEN];
uint m_schema_name_length;
};
Expand All @@ -54,7 +54,7 @@ struct PFS_ALIGNED PFS_statements_digest_stat
/** Internal lock. */
pfs_lock m_lock;

/** Digest Schema + MD5 Hash. */
/** Digest Schema + Digest Hash. */
PFS_digest_key m_digest_key;

/** Digest Storage. */
Expand Down
7 changes: 3 additions & 4 deletions storage/perfschema/table_events_statements.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "pfs_timer.h"
#include "sp_head.h" /* TYPE_ENUM_FUNCTION, ... */
#include "table_helper.h"
#include "my_md5.h"
#include "pfs_buffer_container.h"

THR_LOCK table_events_statements_current::m_table_lock;
Expand Down Expand Up @@ -368,10 +367,10 @@ void table_events_statements_common::make_row_part_2(const sql_digest_storage *d
if (safe_byte_count > 0 &&
safe_byte_count <= pfs_max_digest_length)
{
/* Generate the DIGEST string from the MD5 digest */
MD5_HASH_TO_STRING(digest->m_md5,
/* Generate the DIGEST string from the digest */
DIGEST_HASH_TO_STRING(digest->m_hash,
m_row.m_digest.m_digest);
m_row.m_digest.m_digest_length= MD5_HASH_TO_STRING_LENGTH;
m_row.m_digest.m_digest_length= DIGEST_HASH_TO_STRING_LENGTH;

/* Generate the DIGEST_TEXT string from the token array */
compute_digest_text(digest, &m_row.m_digest.m_digest_text);
Expand Down
6 changes: 3 additions & 3 deletions storage/perfschema/table_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ int PFS_digest_row::make_row(PFS_statements_digest_stat* pfs)
if (safe_byte_count > 0)
{
/*
Calculate digest from MD5 HASH collected to be shown as
Calculate digest from HASH collected to be shown as
DIGEST in this row.
*/
MD5_HASH_TO_STRING(pfs->m_digest_storage.m_md5, m_digest);
m_digest_length= MD5_HASH_TO_STRING_LENGTH;
DIGEST_HASH_TO_STRING(pfs->m_digest_storage.m_hash, m_digest);
m_digest_length= DIGEST_HASH_TO_STRING_LENGTH;

/*
Calculate digest_text information from the token array collected
Expand Down
9 changes: 5 additions & 4 deletions storage/perfschema/table_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@
#include "pfs_digest.h"

/*
Write MD5 hash value in a string to be used
Write XXH3 hash value in a string to be used
as DIGEST for the statement.
*/
#define MD5_HASH_TO_STRING(_hash, _str) \
#define DIGEST_HASH_TO_STRING(_hash, _str) \
sprintf(_str, "%02x%02x%02x%02x%02x%02x%02x%02x" \
"%02x%02x%02x%02x%02x%02x%02x%02x", \
_hash[0], _hash[1], _hash[2], _hash[3], \
_hash[4], _hash[5], _hash[6], _hash[7], \
_hash[8], _hash[9], _hash[10], _hash[11], \
_hash[12], _hash[13], _hash[14], _hash[15])

#define MD5_HASH_TO_STRING_LENGTH 32
/* XXH3_128bits = 16 bytes of binary = 128 printable characters */
#define DIGEST_HASH_TO_STRING_LENGTH 32

struct PFS_host;
struct PFS_user;
Expand Down Expand Up @@ -140,7 +141,7 @@ struct PFS_digest_row
/** Length in bytes of @c m_schema_name. */
uint m_schema_name_length;
/** Column DIGEST. */
char m_digest[COL_DIGEST_SIZE];
char m_digest[DIGEST_HASH_TO_STRING_LENGTH + 1];
/** Length in bytes of @c m_digest. */
uint m_digest_length;
/** Column DIGEST_TEXT. */
Expand Down
2 changes: 1 addition & 1 deletion storage/perfschema/unittest/pfs_server_stubs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ uint lower_case_table_names= 0;
CHARSET_INFO *files_charset_info= NULL;
CHARSET_INFO *system_charset_info= NULL;

void compute_digest_md5(const sql_digest_storage *, unsigned char *)
void compute_digest_hash(const sql_digest_storage *, unsigned char *)
{
}

Expand Down