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
4 changes: 2 additions & 2 deletions mysql-test/include/check_digest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#

--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))
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;
Expand Down
8 changes: 4 additions & 4 deletions mysql-test/suite/perfschema/r/schema.result
Original file line number Diff line number Diff line change
Expand Up @@ -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).',
Expand Down Expand Up @@ -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).',
Expand Down Expand Up @@ -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).',
Expand Down Expand Up @@ -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.',
Expand Down
8 changes: 4 additions & 4 deletions mysql-test/suite/perfschema/r/table_schema.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions mysql-test/suite/sysschema/r/v_statement_analysis.result
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
4 changes: 2 additions & 2 deletions mysql-test/suite/sysschema/r/v_statements_with_sorting.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
6 changes: 3 additions & 3 deletions scripts/sys_schema/procedures/ps_trace_statement_digest.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 All @@ -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
Expand Down
18 changes: 13 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 <openssl/evp.h> // SHA256
#include "unireg.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sha2 is causing a compile error. Please fix that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sha2.h header exists locally on my machine, so following the mysql implementation worked fine for my local build. However, I switched to evp.h to ensure a consistent and portable header across different build environments.


#include "sql_string.h"
Expand Down Expand Up @@ -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);
}
}

/*
Expand Down
Loading
Loading