File: pr_ps_trace_statement_digest.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (65 lines) | stat: -rw-r--r-- 2,986 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
########### suite/sysschema/t/pr_ps_trace_statement_digest.test #############
#                                                                           #
# Testing of of the sys.ps_trace_statement_digest() procedure               #
#                                                                           #
# Creation:                                                                 #
# 2016-06-21 jkrogh Implement this test as part of                          #
#                   Bug 23621189 PS_TRACE_STATEMENT_DIGEST FAILS AT EXPLAIN #
#                                                                           #
#############################################################################

# The ps_trace_statement_digest does not work with prepared statements
# So disable this test with --ps-protocol
-- source include/no_protocol.inc

use test;

# Get the thread id of this thread
# Store it in a user variable as otherwise repeated calls to ps_current_thread_id()
# will keep changing performance_schema.events_statements_history
SET @threadid = ps_current_thread_id();

# Create a table
CREATE TABLE t1 (id INT PRIMARY KEY, val int);

# Get digest of an INSERT statement with a qualified table name
INSERT INTO test.t1 VALUES (1, 9);
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)');

# Get digest of an SELECT statement using the default schema
SELECT * FROM t1;
SET @digest.select = (SELECT DIGEST FROM performance_schema.events_statements_history WHERE THREAD_ID = @threadid AND SQL_TEXT LIKE 'SELECT * FROM t1');

# Get digets of a SHOW statement (doesn't support EXPLAIN)
SHOW CREATE TABLE test.t1;
SET @digest.show = (SELECT DIGEST FROM performance_schema.events_statements_history WHERE THREAD_ID = @threadid AND SQL_TEXT LIKE 'SHOW CREATE TABLE test.t1');

# Don't execute ps_trace_statement_digest() in the same schema as the queries
# to monitor - to ensure we handle queries using the default schema.
CREATE SCHEMA test_sys;
use test_sys;

# Only do sanity checks - no error should occur, but the actual output is non-deterministic
--disable_result_log
# Regular EXPLAINable SELECT with a qualified table name
CALL sys.ps_trace_statement_digest(@digest.insert, 0.5, 0.1, FALSE, FALSE);
# Table in query is not qualified and is not in the current default schema
CALL sys.ps_trace_statement_digest(@digest.select, 0.5, 0.1, FALSE, FALSE);
# SHOW queries doesn't work with EXPLAIN
CALL sys.ps_trace_statement_digest(@digest.show  , 0.5, 0.1, FALSE, FALSE);
# Test that finding no queries works - the TRUE argument resets the P_S tables
# used in ps_trace_statement_digest()
CALL sys.ps_trace_statement_digest(@digest.insert, 0.5, 0.1, TRUE , FALSE);
--enable_result_log



# Clean up
use test;
DROP SCHEMA test_sys;
DROP TABLE t1;
SET @threadid      = NULL,
    @digest.insert = NULL,
    @digest.select = NULL,
    @digest.show   = NULL;