Debian Codegraph @

mysql-test/suite/sysschema/t/pr_ps_trace_statement_digest.test

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