diff --git a/scripts/sys_schema/procedures/ps_trace_statement_digest.sql b/scripts/sys_schema/procedures/ps_trace_statement_digest.sql index 6ad01e4d8d856..f46c68d54e23d 100644 --- a/scripts/sys_schema/procedures/ps_trace_statement_digest.sql +++ b/scripts/sys_schema/procedures/ps_trace_statement_digest.sql @@ -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. diff --git a/sql/sql_digest.cc b/sql/sql_digest.cc index 36a6b398ad317..2f9557c427119 100644 --- a/sql/sql_digest.cc +++ b/sql/sql_digest.cc @@ -19,7 +19,7 @@ */ #include "mariadb.h" -#include "my_md5.h" +#include "../mysys/xxhash.h" #include "unireg.h" #include "sql_string.h" @@ -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)); } /* diff --git a/sql/sql_digest.h b/sql/sql_digest.h index cc786a3b6fa1e..a97d48c3f7a56 100644 --- a/sql/sql_digest.h +++ b/sql/sql_digest.h @@ -18,10 +18,11 @@ #include 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. @@ -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; /** @@ -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() @@ -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 { @@ -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. diff --git a/storage/perfschema/pfs_column_types.h b/storage/perfschema/pfs_column_types.h index 519c165b65b32..2b3af9ae0c8ad 100644 --- a/storage/perfschema/pfs_column_types.h +++ b/storage/perfschema/pfs_column_types.h @@ -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. diff --git a/storage/perfschema/pfs_digest.cc b/storage/perfschema/pfs_digest.cc index 296680c356fc0..3492303459dfe 100644 --- a/storage/perfschema/pfs_digest.cc +++ b/storage/perfschema/pfs_digest.cc @@ -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) diff --git a/storage/perfschema/pfs_digest.h b/storage/perfschema/pfs_digest.h index bec2c28ef5932..8e506be344b98 100644 --- a/storage/perfschema/pfs_digest.h +++ b/storage/perfschema/pfs_digest.h @@ -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; }; @@ -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. */ diff --git a/storage/perfschema/table_events_statements.cc b/storage/perfschema/table_events_statements.cc index 9ce5f4e8d2dd1..5f4f1ea663456 100644 --- a/storage/perfschema/table_events_statements.cc +++ b/storage/perfschema/table_events_statements.cc @@ -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; @@ -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); diff --git a/storage/perfschema/table_helper.cc b/storage/perfschema/table_helper.cc index dd5a765f4bf3b..2a258db973ed8 100644 --- a/storage/perfschema/table_helper.cc +++ b/storage/perfschema/table_helper.cc @@ -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 diff --git a/storage/perfschema/table_helper.h b/storage/perfschema/table_helper.h index 87572ef2525e9..b3c3bcad752ef 100644 --- a/storage/perfschema/table_helper.h +++ b/storage/perfschema/table_helper.h @@ -31,10 +31,10 @@ #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], \ @@ -42,7 +42,8 @@ _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; @@ -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. */ diff --git a/storage/perfschema/unittest/pfs_server_stubs.cc b/storage/perfschema/unittest/pfs_server_stubs.cc index 1ec84c2538efb..d5f7c217c1c27 100644 --- a/storage/perfschema/unittest/pfs_server_stubs.cc +++ b/storage/perfschema/unittest/pfs_server_stubs.cc @@ -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 *) { }