| 1 |
########### suite/sysschema/t/pr_ps_trace_statement_digest.test ############# |
| 2 |
# # |
| 3 |
# Testing of of the sys.ps_trace_statement_digest() procedure # |
| 4 |
# # |
| 5 |
# Creation: # |
| 6 |
# 2016-06-21 jkrogh Implement this test as part of # |
| 7 |
# Bug 23621189 PS_TRACE_STATEMENT_DIGEST FAILS AT EXPLAIN # |
| 8 |
# # |
| 9 |
############################################################################# |
| 10 |
|
| 11 |
# The ps_trace_statement_digest does not work with prepared statements |
| 12 |
# So disable this test with --ps-protocol |
| 13 |
-- source include/no_protocol.inc |
| 14 |
|
| 15 |
use test; |
| 16 |
|
| 17 |
# Get the thread id of this thread |
| 18 |
# Store it in a user variable as otherwise repeated calls to ps_current_thread_id() |
| 19 |
# will keep changing performance_schema.events_statements_history |
| 20 |
SET @threadid = ps_current_thread_id(); |
| 21 |
|
| 22 |
# Create a table |
| 23 |
CREATE TABLE t1 (id INT PRIMARY KEY, val int); |
| 24 |
|
| 25 |
# Get digest of an INSERT statement with a qualified table name |
| 26 |
INSERT INTO test.t1 VALUES (1, 9); |
| 27 |
SET @digest.insert = (SELECT DIGEST FROM performance_schema.events_statements_history WHERE THREAD_ID = @threadid AND SQL_TEXT LIKE 'INSERT INTO test.t1 VALUES (1, 9)'); |
| 28 |
|
| 29 |
# Get digest of an SELECT statement using the default schema |
| 30 |
SELECT * FROM t1; |
| 31 |
SET @digest.select = (SELECT DIGEST FROM performance_schema.events_statements_history WHERE THREAD_ID = @threadid AND SQL_TEXT LIKE 'SELECT * FROM t1'); |
| 32 |
|
| 33 |
# Get digets of a SHOW statement (doesn't support EXPLAIN) |
| 34 |
SHOW CREATE TABLE test.t1; |
| 35 |
SET @digest.show = (SELECT DIGEST FROM performance_schema.events_statements_history WHERE THREAD_ID = @threadid AND SQL_TEXT LIKE 'SHOW CREATE TABLE test.t1'); |
| 36 |
|
| 37 |
# Don't execute ps_trace_statement_digest() in the same schema as the queries |
| 38 |
# to monitor - to ensure we handle queries using the default schema. |
| 39 |
CREATE SCHEMA test_sys; |
| 40 |
use test_sys; |
| 41 |
|
| 42 |
# Only do sanity checks - no error should occur, but the actual output is non-deterministic |
| 43 |
--disable_result_log |
| 44 |
# Regular EXPLAINable SELECT with a qualified table name |
| 45 |
CALL sys.ps_trace_statement_digest(@digest.insert, 0.5, 0.1, FALSE, FALSE); |
| 46 |
# Table in query is not qualified and is not in the current default schema |
| 47 |
CALL sys.ps_trace_statement_digest(@digest.select, 0.5, 0.1, FALSE, FALSE); |
| 48 |
# SHOW queries doesn't work with EXPLAIN |
| 49 |
CALL sys.ps_trace_statement_digest(@digest.show , 0.5, 0.1, FALSE, FALSE); |
| 50 |
# Test that finding no queries works - the TRUE argument resets the P_S tables |
| 51 |
# used in ps_trace_statement_digest() |
| 52 |
CALL sys.ps_trace_statement_digest(@digest.insert, 0.5, 0.1, TRUE , FALSE); |
| 53 |
--enable_result_log |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
# Clean up |
| 58 |
use test; |
| 59 |
DROP SCHEMA test_sys; |
| 60 |
DROP TABLE t1; |
| 61 |
SET @threadid = NULL, |
| 62 |
@digest.insert = NULL, |
| 63 |
@digest.select = NULL, |
| 64 |
@digest.show = NULL; |
| 65 |
|