File: v_statements_with_full_table_scans.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 (87 lines) | stat: -rw-r--r-- 4,108 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
-- source ../include/ps_truncate_all_tables.inc
# Performance schema tracks prepared statements separately, and does not 
# yet have a summary view that we can use for this view.
# Until then, we disable this test with --ps-protocol
# Test requires: sp-protocol/ps-protocol/view-protocol/cursor-protocol disabled
-- source include/no_protocol.inc

# Tests for sys schema
# Verify the sys.statements_with_full_table_scans view

# Ensure structure changes don't slip in
DESC sys.statements_with_full_table_scans;

# Make sure view select does not error, but ignore results
--disable_result_log
SELECT * FROM sys.statements_with_full_table_scans;
--enable_result_log


# Ensure structure changes don't slip in
DESC sys.x$statements_with_full_table_scans;

# Make sure view select does not error, but ignore results
--disable_result_log
SELECT * FROM sys.x$statements_with_full_table_scans;
--enable_result_log

# Create a dummy table, force some full table scans, verify the results
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;

INSERT INTO v_statements_with_full_table_scans.t (j) VALUES (1), (2), (3);

INSERT INTO v_statements_with_full_table_scans.t (j) (SELECT j*2 FROM v_statements_with_full_table_scans.t);

INSERT INTO v_statements_with_full_table_scans.t (j) (SELECT j*2 FROM v_statements_with_full_table_scans.t);

INSERT INTO v_statements_with_full_table_scans.t (j) (SELECT j*2 FROM v_statements_with_full_table_scans.t);

INSERT INTO v_statements_with_full_table_scans.t (j) (SELECT j*2 FROM v_statements_with_full_table_scans.t);

INSERT INTO v_statements_with_full_table_scans.t (j) (SELECT j*2 FROM v_statements_with_full_table_scans.t);

INSERT INTO v_statements_with_full_table_scans.t (j) (SELECT j*2 FROM v_statements_with_full_table_scans.t);

INSERT INTO v_statements_with_full_table_scans.t (j) (SELECT j*2 FROM v_statements_with_full_table_scans.t);

INSERT INTO v_statements_with_full_table_scans.t (j) (SELECT j*2 FROM v_statements_with_full_table_scans.t);

# The table should now have 768 rows

# Now truncate the P_S tables, to get fresh results
CALL sys.ps_truncate_all_tables(false);

# Following returns 28 rows, but should full scan as j has no index
# Using RAND() to force no query caching, so ignore results, they are not important
--disable_result_log
SELECT i, j, RAND() FROM v_statements_with_full_table_scans.t WHERE j = 12;
--enable_result_log

# Now verify the statement shows up in the views with the right row count (should be 768)
SELECT db, query, rows_examined FROM sys.statements_with_full_table_scans WHERE query LIKE '%v_statements_with_full_table_scans%' ORDER BY rows_examined DESC;

SELECT db, query, rows_examined FROM sys.x$statements_with_full_table_scans WHERE query LIKE '%v_statements_with_full_table_scans%' ORDER BY rows_examined DESC;

# Scan again
--disable_result_log
SELECT i, j, RAND() FROM v_statements_with_full_table_scans.t WHERE j = 12;
--enable_result_log

# Now verify that double the amount of rows for the statement should be shown as scanned (should be 1536)
SELECT db, query, rows_examined FROM sys.statements_with_full_table_scans WHERE query LIKE '%v_statements_with_full_table_scans%' ORDER BY rows_examined DESC;

SELECT db, query, rows_examined FROM sys.x$statements_with_full_table_scans WHERE query LIKE '%v_statements_with_full_table_scans%' ORDER BY rows_examined DESC;

# Do a point lookup
--skip_if_hypergraph  # Does not support indexes yet, so it would show up in the list.
SELECT * FROM v_statements_with_full_table_scans.t WHERE i = 10;

# The number of rows scanned should not have changed (should still be 1536)
SELECT db, query, rows_examined FROM sys.statements_with_full_table_scans WHERE query LIKE '%v_statements_with_full_table_scans%' ORDER BY rows_examined DESC;

SELECT db, query, rows_examined FROM sys.x$statements_with_full_table_scans WHERE query LIKE '%v_statements_with_full_table_scans%' ORDER BY rows_examined DESC;

# Cleanup
DROP DATABASE v_statements_with_full_table_scans;