diff --git a/mysql-test/include/check_digest.inc b/mysql-test/include/check_digest.inc index 9e5d6cccc8b6d..83c5ead57abb8 100644 --- a/mysql-test/include/check_digest.inc +++ b/mysql-test/include/check_digest.inc @@ -3,7 +3,7 @@ # --disable_query_log -create table test._digests(d varchar(32) primary key); +create table test._digests(d varchar(64) primary key); delimiter ~~; create function test.check_digest(digest varchar(255)) @@ -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) != 64 or digest is null then return 0; end if; select exists (select d from test._digests where d = digest) into digest_exists; diff --git a/mysql-test/suite/perfschema/r/schema.result b/mysql-test/suite/perfschema/r/schema.result index d68e70e4602bd..b4d3c3346275d 100644 --- a/mysql-test/suite/perfschema/r/schema.result +++ b/mysql-test/suite/perfschema/r/schema.result @@ -217,7 +217,7 @@ events_statements_current CREATE TABLE `events_statements_current` ( `TIMER_WAIT` bigint(20) unsigned DEFAULT NULL COMMENT 'Value in picoseconds of the event''s duration or NULL if the event has not ended or timing is not collected.', `LOCK_TIME` bigint(20) unsigned NOT NULL COMMENT 'Time in picoseconds spent waiting for locks. The time is calculated in microseconds but stored in picoseconds for compatibility with other timings.', `SQL_TEXT` longtext DEFAULT NULL COMMENT 'The SQL statement, or NULL if the command is not associated with an SQL statement.', - `DIGEST` varchar(32) DEFAULT NULL COMMENT 'Statement digest.', + `DIGEST` varchar(64) DEFAULT NULL COMMENT 'Statement digest.', `DIGEST_TEXT` longtext DEFAULT NULL COMMENT 'Statement digest text.', `CURRENT_SCHEMA` varchar(64) DEFAULT NULL COMMENT 'Statement''s default database for the statement, or NULL if there was none.', `OBJECT_TYPE` varchar(64) DEFAULT NULL COMMENT 'NULL for top level statements. The parent statement object type for nested statements (stored programs).', @@ -262,7 +262,7 @@ events_statements_history CREATE TABLE `events_statements_history` ( `TIMER_WAIT` bigint(20) unsigned DEFAULT NULL COMMENT 'Value in picoseconds of the event''s duration or NULL if the event has not ended or timing is not collected.', `LOCK_TIME` bigint(20) unsigned NOT NULL COMMENT 'Time in picoseconds spent waiting for locks. The time is calculated in microseconds but stored in picoseconds for compatibility with other timings.', `SQL_TEXT` longtext DEFAULT NULL COMMENT 'The SQL statement, or NULL if the command is not associated with an SQL statement.', - `DIGEST` varchar(32) DEFAULT NULL COMMENT 'Statement digest.', + `DIGEST` varchar(64) DEFAULT NULL COMMENT 'Statement digest.', `DIGEST_TEXT` longtext DEFAULT NULL COMMENT 'Statement digest text.', `CURRENT_SCHEMA` varchar(64) DEFAULT NULL COMMENT 'Statement''s default database for the statement, or NULL if there was none.', `OBJECT_TYPE` varchar(64) DEFAULT NULL COMMENT 'NULL for top level statements. The parent statement object type for nested statements (stored programs).', @@ -307,7 +307,7 @@ events_statements_history_long CREATE TABLE `events_statements_history_long` ( `TIMER_WAIT` bigint(20) unsigned DEFAULT NULL COMMENT 'Value in picoseconds of the event''s duration or NULL if the event has not ended or timing is not collected.', `LOCK_TIME` bigint(20) unsigned NOT NULL COMMENT 'Time in picoseconds spent waiting for locks. The time is calculated in microseconds but stored in picoseconds for compatibility with other timings.', `SQL_TEXT` longtext DEFAULT NULL COMMENT 'The SQL statement, or NULL if the command is not associated with an SQL statement.', - `DIGEST` varchar(32) DEFAULT NULL COMMENT 'Statement digest.', + `DIGEST` varchar(64) DEFAULT NULL COMMENT 'Statement digest.', `DIGEST_TEXT` longtext DEFAULT NULL COMMENT 'Statement digest text.', `CURRENT_SCHEMA` varchar(64) DEFAULT NULL COMMENT 'Statement''s default database for the statement, or NULL if there was none.', `OBJECT_TYPE` varchar(64) DEFAULT NULL COMMENT 'NULL for top level statements. The parent statement object type for nested statements (stored programs).', @@ -343,7 +343,7 @@ show create table events_statements_summary_by_digest; Table Create Table events_statements_summary_by_digest CREATE TABLE `events_statements_summary_by_digest` ( `SCHEMA_NAME` varchar(64) DEFAULT NULL COMMENT 'Database name. Records are summarised together with DIGEST.', - `DIGEST` varchar(32) DEFAULT NULL COMMENT 'Performance Schema digest. Records are summarised together with SCHEMA NAME.', + `DIGEST` varchar(64) DEFAULT NULL COMMENT 'Performance Schema digest. Records are summarised together with SCHEMA NAME.', `DIGEST_TEXT` longtext DEFAULT NULL COMMENT 'The unhashed form of the digest.', `COUNT_STAR` bigint(20) unsigned NOT NULL COMMENT 'Number of summarized events', `SUM_TIMER_WAIT` bigint(20) unsigned NOT NULL COMMENT 'Total wait time of the summarized events that are timed.', diff --git a/mysql-test/suite/perfschema/r/table_schema.result b/mysql-test/suite/perfschema/r/table_schema.result index 5453bda578b9d..a1959dd7fa140 100644 --- a/mysql-test/suite/perfschema/r/table_schema.result +++ b/mysql-test/suite/perfschema/r/table_schema.result @@ -88,7 +88,7 @@ def performance_schema events_statements_current TIMER_END 7 NULL YES bigint NUL def performance_schema events_statements_current TIMER_WAIT 8 NULL YES bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Value in picoseconds of the event's duration or NULL if the event has not ended or timing is not collected. NEVER NULL NO NO def performance_schema events_statements_current LOCK_TIME 9 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Time in picoseconds spent waiting for locks. The time is calculated in microseconds but stored in picoseconds for compatibility with other timings. NEVER NULL NO NO def performance_schema events_statements_current SQL_TEXT 10 NULL YES longtext 4294967295 4294967295 NULL NULL NULL utf8mb3 utf8mb3_general_ci longtext select,insert,update,references The SQL statement, or NULL if the command is not associated with an SQL statement. NEVER NULL NO NO -def performance_schema events_statements_current DIGEST 11 NULL YES varchar 32 96 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(32) select,insert,update,references Statement digest. NEVER NULL NO NO +def performance_schema events_statements_current DIGEST 11 NULL YES varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select,insert,update,references Statement digest. NEVER NULL NO NO def performance_schema events_statements_current DIGEST_TEXT 12 NULL YES longtext 4294967295 4294967295 NULL NULL NULL utf8mb3 utf8mb3_general_ci longtext select,insert,update,references Statement digest text. NEVER NULL NO NO def performance_schema events_statements_current CURRENT_SCHEMA 13 NULL YES varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select,insert,update,references Statement's default database for the statement, or NULL if there was none. NEVER NULL NO NO def performance_schema events_statements_current OBJECT_TYPE 14 NULL YES varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select,insert,update,references NULL for top level statements. The parent statement object type for nested statements (stored programs). NEVER NULL NO NO @@ -129,7 +129,7 @@ def performance_schema events_statements_history TIMER_END 7 NULL YES bigint NUL def performance_schema events_statements_history TIMER_WAIT 8 NULL YES bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Value in picoseconds of the event's duration or NULL if the event has not ended or timing is not collected. NEVER NULL NO NO def performance_schema events_statements_history LOCK_TIME 9 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Time in picoseconds spent waiting for locks. The time is calculated in microseconds but stored in picoseconds for compatibility with other timings. NEVER NULL NO NO def performance_schema events_statements_history SQL_TEXT 10 NULL YES longtext 4294967295 4294967295 NULL NULL NULL utf8mb3 utf8mb3_general_ci longtext select,insert,update,references The SQL statement, or NULL if the command is not associated with an SQL statement. NEVER NULL NO NO -def performance_schema events_statements_history DIGEST 11 NULL YES varchar 32 96 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(32) select,insert,update,references Statement digest. NEVER NULL NO NO +def performance_schema events_statements_history DIGEST 11 NULL YES varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select,insert,update,references Statement digest. NEVER NULL NO NO def performance_schema events_statements_history DIGEST_TEXT 12 NULL YES longtext 4294967295 4294967295 NULL NULL NULL utf8mb3 utf8mb3_general_ci longtext select,insert,update,references Statement digest text. NEVER NULL NO NO def performance_schema events_statements_history CURRENT_SCHEMA 13 NULL YES varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select,insert,update,references Statement's default database for the statement, or NULL if there was none. NEVER NULL NO NO def performance_schema events_statements_history OBJECT_TYPE 14 NULL YES varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select,insert,update,references NULL for top level statements. The parent statement object type for nested statements (stored programs). NEVER NULL NO NO @@ -170,7 +170,7 @@ def performance_schema events_statements_history_long TIMER_END 7 NULL YES bigin def performance_schema events_statements_history_long TIMER_WAIT 8 NULL YES bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Value in picoseconds of the event's duration or NULL if the event has not ended or timing is not collected. NEVER NULL NO NO def performance_schema events_statements_history_long LOCK_TIME 9 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Time in picoseconds spent waiting for locks. The time is calculated in microseconds but stored in picoseconds for compatibility with other timings. NEVER NULL NO NO def performance_schema events_statements_history_long SQL_TEXT 10 NULL YES longtext 4294967295 4294967295 NULL NULL NULL utf8mb3 utf8mb3_general_ci longtext select,insert,update,references The SQL statement, or NULL if the command is not associated with an SQL statement. NEVER NULL NO NO -def performance_schema events_statements_history_long DIGEST 11 NULL YES varchar 32 96 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(32) select,insert,update,references Statement digest. NEVER NULL NO NO +def performance_schema events_statements_history_long DIGEST 11 NULL YES varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select,insert,update,references Statement digest. NEVER NULL NO NO def performance_schema events_statements_history_long DIGEST_TEXT 12 NULL YES longtext 4294967295 4294967295 NULL NULL NULL utf8mb3 utf8mb3_general_ci longtext select,insert,update,references Statement digest text. NEVER NULL NO NO def performance_schema events_statements_history_long CURRENT_SCHEMA 13 NULL YES varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select,insert,update,references Statement's default database for the statement, or NULL if there was none. NEVER NULL NO NO def performance_schema events_statements_history_long OBJECT_TYPE 14 NULL YES varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select,insert,update,references NULL for top level statements. The parent statement object type for nested statements (stored programs). NEVER NULL NO NO @@ -229,7 +229,7 @@ def performance_schema events_statements_summary_by_account_by_event_name SUM_SO def performance_schema events_statements_summary_by_account_by_event_name SUM_NO_INDEX_USED 26 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Sum of the NO_INDEX_USED column in the events_statements_current table. NEVER NULL NO NO def performance_schema events_statements_summary_by_account_by_event_name SUM_NO_GOOD_INDEX_USED 27 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Sum of the NO_GOOD_INDEX_USED column in the events_statements_current table. NEVER NULL NO NO def performance_schema events_statements_summary_by_digest SCHEMA_NAME 1 NULL YES varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select,insert,update,references Database name. Records are summarised together with DIGEST. NEVER NULL NO NO -def performance_schema events_statements_summary_by_digest DIGEST 2 NULL YES varchar 32 96 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(32) select,insert,update,references Performance Schema digest. Records are summarised together with SCHEMA NAME. NEVER NULL NO NO +def performance_schema events_statements_summary_by_digest DIGEST 2 NULL YES varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select,insert,update,references Performance Schema digest. Records are summarised together with SCHEMA NAME. NEVER NULL NO NO def performance_schema events_statements_summary_by_digest DIGEST_TEXT 3 NULL YES longtext 4294967295 4294967295 NULL NULL NULL utf8mb3 utf8mb3_general_ci longtext select,insert,update,references The unhashed form of the digest. NEVER NULL NO NO def performance_schema events_statements_summary_by_digest COUNT_STAR 4 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Number of summarized events NEVER NULL NO NO def performance_schema events_statements_summary_by_digest SUM_TIMER_WAIT 5 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(20) unsigned select,insert,update,references Total wait time of the summarized events that are timed. NEVER NULL NO NO diff --git a/mysql-test/suite/sysschema/r/v_statement_analysis.result b/mysql-test/suite/sysschema/r/v_statement_analysis.result index 510e17d6d7add..aaf9467bd26ef 100644 --- a/mysql-test/suite/sysschema/r/v_statement_analysis.result +++ b/mysql-test/suite/sysschema/r/v_statement_analysis.result @@ -20,7 +20,7 @@ tmp_tables bigint(20) unsigned NO NULL tmp_disk_tables bigint(20) unsigned NO NULL rows_sorted bigint(20) unsigned NO NULL sort_merge_passes bigint(20) unsigned NO NULL -digest varchar(32) YES NULL +digest varchar(64) YES NULL first_seen timestamp NO 0000-00-00 00:00:00 last_seen timestamp NO 0000-00-00 00:00:00 SELECT * FROM sys.statement_analysis; @@ -46,7 +46,7 @@ tmp_tables bigint(20) unsigned NO NULL tmp_disk_tables bigint(20) unsigned NO NULL rows_sorted bigint(20) unsigned NO NULL sort_merge_passes bigint(20) unsigned NO NULL -digest varchar(32) YES NULL +digest varchar(64) YES NULL first_seen timestamp NO 0000-00-00 00:00:00 last_seen timestamp NO 0000-00-00 00:00:00 SELECT * FROM sys.x$statement_analysis; diff --git a/mysql-test/suite/sysschema/r/v_statements_with_errors_or_warnings.result b/mysql-test/suite/sysschema/r/v_statements_with_errors_or_warnings.result index 250f4ec1f4cb7..5c9286737a217 100644 --- a/mysql-test/suite/sysschema/r/v_statements_with_errors_or_warnings.result +++ b/mysql-test/suite/sysschema/r/v_statements_with_errors_or_warnings.result @@ -9,7 +9,7 @@ warnings bigint(20) unsigned NO NULL warning_pct decimal(27,4) NO 0.0000 first_seen timestamp NO 0000-00-00 00:00:00 last_seen timestamp NO 0000-00-00 00:00:00 -digest varchar(32) YES NULL +digest varchar(64) YES NULL SELECT * FROM sys.statements_with_errors_or_warnings; DESC sys.x$statements_with_errors_or_warnings; Field Type Null Key Default Extra @@ -22,5 +22,5 @@ warnings bigint(20) unsigned NO NULL warning_pct decimal(27,4) NO 0.0000 first_seen timestamp NO 0000-00-00 00:00:00 last_seen timestamp NO 0000-00-00 00:00:00 -digest varchar(32) YES NULL +digest varchar(64) YES NULL SELECT * FROM sys.x$statements_with_errors_or_warnings; diff --git a/mysql-test/suite/sysschema/r/v_statements_with_full_table_scans.result b/mysql-test/suite/sysschema/r/v_statements_with_full_table_scans.result index f543c8adfcca5..9472dca69b4b9 100644 --- a/mysql-test/suite/sysschema/r/v_statements_with_full_table_scans.result +++ b/mysql-test/suite/sysschema/r/v_statements_with_full_table_scans.result @@ -13,7 +13,7 @@ rows_sent_avg decimal(21,0) unsigned YES NULL rows_examined_avg decimal(21,0) unsigned YES NULL first_seen timestamp NO 0000-00-00 00:00:00 last_seen timestamp NO 0000-00-00 00:00:00 -digest varchar(32) YES NULL +digest varchar(64) YES NULL SELECT * FROM sys.statements_with_full_table_scans; DESC sys.x$statements_with_full_table_scans; Field Type Null Key Default Extra @@ -30,7 +30,7 @@ rows_sent_avg decimal(21,0) unsigned YES NULL rows_examined_avg decimal(21,0) unsigned YES NULL first_seen timestamp NO 0000-00-00 00:00:00 last_seen timestamp NO 0000-00-00 00:00:00 -digest varchar(32) YES NULL +digest varchar(64) YES NULL SELECT * FROM sys.x$statements_with_full_table_scans; CREATE DATABASE v_statements_with_full_table_scans; CREATE TABLE v_statements_with_full_table_scans.t (i BIGINT AUTO_INCREMENT PRIMARY KEY, j BIGINT) ENGINE = innodb; diff --git a/mysql-test/suite/sysschema/r/v_statements_with_runtimes_in_95th_percentile.result b/mysql-test/suite/sysschema/r/v_statements_with_runtimes_in_95th_percentile.result index 90ea51a424bc1..17e4aaacb4bff 100644 --- a/mysql-test/suite/sysschema/r/v_statements_with_runtimes_in_95th_percentile.result +++ b/mysql-test/suite/sysschema/r/v_statements_with_runtimes_in_95th_percentile.result @@ -15,7 +15,7 @@ rows_examined bigint(20) unsigned NO NULL rows_examined_avg decimal(21,0) NO 0 first_seen timestamp NO 0000-00-00 00:00:00 last_seen timestamp NO 0000-00-00 00:00:00 -digest varchar(32) YES NULL +digest varchar(64) YES NULL SELECT * FROM sys.statements_with_runtimes_in_95th_percentile; DESC sys.x$statements_with_runtimes_in_95th_percentile; Field Type Null Key Default Extra @@ -34,5 +34,5 @@ rows_examined bigint(20) unsigned NO NULL rows_examined_avg decimal(21,0) NO 0 first_seen timestamp NO 0000-00-00 00:00:00 last_seen timestamp NO 0000-00-00 00:00:00 -digest varchar(32) YES NULL +digest varchar(64) YES NULL SELECT * FROM sys.x$statements_with_runtimes_in_95th_percentile; diff --git a/mysql-test/suite/sysschema/r/v_statements_with_sorting.result b/mysql-test/suite/sysschema/r/v_statements_with_sorting.result index b3a715731a4fc..cd50641b7d55a 100644 --- a/mysql-test/suite/sysschema/r/v_statements_with_sorting.result +++ b/mysql-test/suite/sysschema/r/v_statements_with_sorting.result @@ -12,7 +12,7 @@ rows_sorted bigint(20) unsigned NO NULL avg_rows_sorted decimal(21,0) NO 0 first_seen timestamp NO 0000-00-00 00:00:00 last_seen timestamp NO 0000-00-00 00:00:00 -digest varchar(32) YES NULL +digest varchar(64) YES NULL SELECT * FROM sys.statements_with_sorting; DESC sys.x$statements_with_sorting; Field Type Null Key Default Extra @@ -28,5 +28,5 @@ rows_sorted bigint(20) unsigned NO NULL avg_rows_sorted decimal(21,0) NO 0 first_seen timestamp NO 0000-00-00 00:00:00 last_seen timestamp NO 0000-00-00 00:00:00 -digest varchar(32) YES NULL +digest varchar(64) YES NULL SELECT * FROM sys.x$statements_with_sorting; diff --git a/mysql-test/suite/sysschema/r/v_statements_with_temp_tables.result b/mysql-test/suite/sysschema/r/v_statements_with_temp_tables.result index 73ea1ae00c2e2..fcab1f642288d 100644 --- a/mysql-test/suite/sysschema/r/v_statements_with_temp_tables.result +++ b/mysql-test/suite/sysschema/r/v_statements_with_temp_tables.result @@ -10,7 +10,7 @@ avg_tmp_tables_per_query decimal(21,0) NO 0 tmp_tables_to_disk_pct decimal(24,0) NO 0 first_seen timestamp NO 0000-00-00 00:00:00 last_seen timestamp NO 0000-00-00 00:00:00 -digest varchar(32) YES NULL +digest varchar(64) YES NULL SELECT * FROM sys.statements_with_temp_tables; DESC sys.x$statements_with_temp_tables; Field Type Null Key Default Extra @@ -24,5 +24,5 @@ avg_tmp_tables_per_query decimal(21,0) NO 0 tmp_tables_to_disk_pct decimal(24,0) NO 0 first_seen timestamp NO 0000-00-00 00:00:00 last_seen timestamp NO 0000-00-00 00:00:00 -digest varchar(32) YES NULL +digest varchar(64) YES NULL SELECT * FROM sys.x$statements_with_temp_tables; diff --git a/scripts/sys_schema/procedures/ps_trace_statement_digest.sql b/scripts/sys_schema/procedures/ps_trace_statement_digest.sql index 6ad01e4d8d856..5863d04a5ed42 100644 --- a/scripts/sys_schema/procedures/ps_trace_statement_digest.sql +++ b/scripts/sys_schema/procedures/ps_trace_statement_digest.sql @@ -18,7 +18,7 @@ DROP PROCEDURE IF EXISTS ps_trace_statement_digest; DELIMITER $$ CREATE DEFINER='mariadb.sys'@'localhost' PROCEDURE ps_trace_statement_digest ( - IN in_digest VARCHAR(32), + IN in_digest VARCHAR(64), IN in_runtime INT, IN in_interval DECIMAL(2,2), IN in_start_fresh BOOLEAN, @@ -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. @@ -55,7 +55,7 @@ CREATE DEFINER='mariadb.sys'@'localhost' PROCEDURE ps_trace_statement_digest ( Parameters ----------- - in_digest (VARCHAR(32)): + in_digest (VARCHAR(64)): The statement digest identifier you would like to analyze in_runtime (INT): The number of seconds to run analysis for diff --git a/sql/sql_digest.cc b/sql/sql_digest.cc index 36a6b398ad317..0b70231802be8 100644 --- a/sql/sql_digest.cc +++ b/sql/sql_digest.cc @@ -19,7 +19,7 @@ */ #include "mariadb.h" -#include "my_md5.h" +#include // SHA256 #include "unireg.h" #include "sql_string.h" @@ -157,11 +157,19 @@ 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); + static_assert(DIGEST_HASH_SIZE == SHA256_DIGEST_LENGTH, + "DIGEST is no longer SHA256, fix compute_digest_hash()"); + unsigned int hash_len = 0; + EVP_MD_CTX *mdctx = EVP_MD_CTX_new(); + if (mdctx != NULL) { + if (EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL)) { + EVP_DigestUpdate(mdctx, digest_storage->m_token_array, digest_storage->m_byte_count); + EVP_DigestFinal_ex(mdctx, hash, &hash_len); + } + EVP_MD_CTX_free(mdctx); + } } /* diff --git a/sql/sql_digest.h b/sql/sql_digest.h index cc786a3b6fa1e..6d6b0ffd33367 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 32 + /** 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_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_esms_by_digest.cc b/storage/perfschema/table_esms_by_digest.cc index 398300bcd5d86..9035f6f23cc14 100644 --- a/storage/perfschema/table_esms_by_digest.cc +++ b/storage/perfschema/table_esms_by_digest.cc @@ -59,7 +59,7 @@ table_esms_by_digest::m_share= &m_table_lock, { C_STRING_WITH_LEN("CREATE TABLE events_statements_summary_by_digest(" "SCHEMA_NAME VARCHAR(64) comment 'Database name. Records are summarised together with DIGEST.'," - "DIGEST VARCHAR(32) comment 'Performance Schema digest. Records are summarised together with SCHEMA NAME.'," + "DIGEST VARCHAR(64) comment 'Performance Schema digest. Records are summarised together with SCHEMA NAME.'," "DIGEST_TEXT LONGTEXT comment 'The unhashed form of the digest.'," "COUNT_STAR BIGINT unsigned not null comment 'Number of summarized events'," "SUM_TIMER_WAIT BIGINT unsigned not null comment 'Total wait time of the summarized events that are timed.'," diff --git a/storage/perfschema/table_events_statements.cc b/storage/perfschema/table_events_statements.cc index 9ce5f4e8d2dd1..ea69edc89063a 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; @@ -66,7 +65,7 @@ table_events_statements_current::m_share= "TIMER_WAIT BIGINT unsigned comment 'Value in picoseconds of the event''s duration or NULL if the event has not ended or timing is not collected.'," "LOCK_TIME bigint unsigned not null comment 'Time in picoseconds spent waiting for locks. The time is calculated in microseconds but stored in picoseconds for compatibility with other timings.'," "SQL_TEXT LONGTEXT comment 'The SQL statement, or NULL if the command is not associated with an SQL statement.'," - "DIGEST VARCHAR(32) comment 'Statement digest.'," + "DIGEST VARCHAR(64) comment 'Statement digest.'," "DIGEST_TEXT LONGTEXT comment 'Statement digest text.'," "CURRENT_SCHEMA VARCHAR(64) comment 'Statement''s default database for the statement, or NULL if there was none.'," "OBJECT_TYPE VARCHAR(64) comment 'NULL for top level statements. The parent statement object type for nested statements (stored programs).'," @@ -131,7 +130,7 @@ table_events_statements_history::m_share= "TIMER_WAIT BIGINT unsigned comment 'Value in picoseconds of the event''s duration or NULL if the event has not ended or timing is not collected.'," "LOCK_TIME bigint unsigned not null comment 'Time in picoseconds spent waiting for locks. The time is calculated in microseconds but stored in picoseconds for compatibility with other timings.'," "SQL_TEXT LONGTEXT comment 'The SQL statement, or NULL if the command is not associated with an SQL statement.'," - "DIGEST VARCHAR(32) comment 'Statement digest.'," + "DIGEST VARCHAR(64) comment 'Statement digest.'," "DIGEST_TEXT LONGTEXT comment 'Statement digest text.'," "CURRENT_SCHEMA VARCHAR(64) comment 'Statement''s default database for the statement, or NULL if there was none.'," "OBJECT_TYPE VARCHAR(64) comment 'NULL for top level statements. The parent statement object type for nested statements (stored programs).'," @@ -196,7 +195,7 @@ table_events_statements_history_long::m_share= "TIMER_WAIT BIGINT unsigned comment 'Value in picoseconds of the event''s duration or NULL if the event has not ended or timing is not collected.'," "LOCK_TIME bigint unsigned not null comment 'Time in picoseconds spent waiting for locks. The time is calculated in microseconds but stored in picoseconds for compatibility with other timings.'," "SQL_TEXT LONGTEXT comment 'The SQL statement, or NULL if the command is not associated with an SQL statement.'," - "DIGEST VARCHAR(32) comment 'Statement digest.'," + "DIGEST VARCHAR(64) comment 'Statement digest.'," "DIGEST_TEXT LONGTEXT comment 'Statement digest text.'," "CURRENT_SCHEMA VARCHAR(64) comment 'Statement''s default database for the statement, or NULL if there was none.'," "OBJECT_TYPE VARCHAR(64) comment 'NULL for top level statements. The parent statement object type for nested statements (stored programs).'," @@ -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..c5f2946ae41df 100644 --- a/storage/perfschema/table_helper.h +++ b/storage/perfschema/table_helper.h @@ -31,18 +31,27 @@ #include "pfs_digest.h" /* - Write MD5 hash value in a string to be used + Write SHA-256 hash value in a string to be used as DIGEST for the statement. */ -#define MD5_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 +#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" \ + "%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], \ + _hash[16], _hash[17], _hash[18], _hash[19], \ + _hash[20], _hash[21], _hash[22], _hash[23], \ + _hash[24], _hash[25], _hash[26], _hash[27], \ + _hash[28], _hash[29], _hash[30], _hash[31] \ + ) + +/* SHA-256 = 32 bytes of binary = 64 printable characters */ +#define DIGEST_HASH_TO_STRING_LENGTH 64 struct PFS_host; struct PFS_user; @@ -140,7 +149,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 *) { }