Skip to content

Commit

Permalink
Bug#21663578 INSTABILITY IN SYSSCHEMA.V_SCHEMA_TABLES_WITH_FULL_TABLE…
Browse files Browse the repository at this point in the history
…_SCANS

Added wait conditions for the underlying performance schema data to be updated.
  • Loading branch information
MarkLeith committed May 9, 2016
1 parent 1154594 commit a4ee5e6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 54 deletions.
Expand Up @@ -12,48 +12,40 @@ object_name varchar(64) YES NULL
rows_full_scanned bigint(20) unsigned NO NULL
latency bigint(20) unsigned NO NULL
SELECT * FROM sys.x$schema_tables_with_full_table_scans;
CREATE DATABASE v_schema_tables_with_full_table_scans;
CREATE TABLE v_schema_tables_with_full_table_scans.t (i BIGINT AUTO_INCREMENT PRIMARY KEY, j BIGINT) ENGINE = innodb;
INSERT INTO v_schema_tables_with_full_table_scans.t (j) VALUES (1), (2), (3);
INSERT INTO v_schema_tables_with_full_table_scans.t (j) (SELECT j*2 FROM v_schema_tables_with_full_table_scans.t);
INSERT INTO v_schema_tables_with_full_table_scans.t (j) (SELECT j*2 FROM v_schema_tables_with_full_table_scans.t);
INSERT INTO v_schema_tables_with_full_table_scans.t (j) (SELECT j*2 FROM v_schema_tables_with_full_table_scans.t);
INSERT INTO v_schema_tables_with_full_table_scans.t (j) (SELECT j*2 FROM v_schema_tables_with_full_table_scans.t);
INSERT INTO v_schema_tables_with_full_table_scans.t (j) (SELECT j*2 FROM v_schema_tables_with_full_table_scans.t);
INSERT INTO v_schema_tables_with_full_table_scans.t (j) (SELECT j*2 FROM v_schema_tables_with_full_table_scans.t);
INSERT INTO v_schema_tables_with_full_table_scans.t (j) (SELECT j*2 FROM v_schema_tables_with_full_table_scans.t);
INSERT INTO v_schema_tables_with_full_table_scans.t (j) (SELECT j*2 FROM v_schema_tables_with_full_table_scans.t);
CREATE TABLE test.t (i BIGINT AUTO_INCREMENT PRIMARY KEY, j BIGINT) ENGINE = innodb;
INSERT INTO test.t (j) VALUES (1), (2), (3);
INSERT INTO test.t (j) (SELECT j*2 FROM test.t);
INSERT INTO test.t (j) (SELECT j*2 FROM test.t);
INSERT INTO test.t (j) (SELECT j*2 FROM test.t);
INSERT INTO test.t (j) (SELECT j*2 FROM test.t);
INSERT INTO test.t (j) (SELECT j*2 FROM test.t);
INSERT INTO test.t (j) (SELECT j*2 FROM test.t);
INSERT INTO test.t (j) (SELECT j*2 FROM test.t);
INSERT INTO test.t (j) (SELECT j*2 FROM test.t);
CALL sys.ps_truncate_all_tables(false);
summary
Truncated 44 tables
SELECT i, j, RAND() FROM v_schema_tables_with_full_table_scans.t WHERE j = 12;
SELECT i, j, RAND() FROM test.t WHERE j = 12;
SELECT object_schema, object_name, rows_full_scanned FROM sys.schema_tables_with_full_table_scans;
object_schema object_name rows_full_scanned
v_schema_tables_with_full_table_scans t 768
test t 768
SELECT object_schema, object_name, rows_full_scanned FROM sys.x$schema_tables_with_full_table_scans;
object_schema object_name rows_full_scanned
v_schema_tables_with_full_table_scans t 768
SELECT i, j, RAND() FROM v_schema_tables_with_full_table_scans.t WHERE j = 12;
test t 768
SELECT i, j, RAND() FROM test.t WHERE j = 12;
SELECT object_schema, object_name, rows_full_scanned FROM sys.schema_tables_with_full_table_scans;
object_schema object_name rows_full_scanned
v_schema_tables_with_full_table_scans t 1536
test t 1536
SELECT object_schema, object_name, rows_full_scanned FROM sys.x$schema_tables_with_full_table_scans;
object_schema object_name rows_full_scanned
v_schema_tables_with_full_table_scans t 1536
SELECT * FROM v_schema_tables_with_full_table_scans.t WHERE i = 10;
test t 1536
SELECT * FROM test.t WHERE i = 10;
i j
10 4
SELECT object_schema, object_name, rows_full_scanned FROM sys.schema_tables_with_full_table_scans;
object_schema object_name rows_full_scanned
v_schema_tables_with_full_table_scans t 1536
test t 1536
SELECT object_schema, object_name, rows_full_scanned FROM sys.x$schema_tables_with_full_table_scans;
object_schema object_name rows_full_scanned
v_schema_tables_with_full_table_scans t 1536
DROP DATABASE v_schema_tables_with_full_table_scans;
DESC sys.x$schema_tables_with_full_table_scans;
Field Type Null Key Default Extra
object_schema varchar(64) YES NULL
object_name varchar(64) YES NULL
rows_full_scanned bigint(20) unsigned NO NULL
latency bigint(20) unsigned NO NULL
SELECT * FROM sys.x$schema_tables_with_full_table_scans;
test t 1536
DROP TABLE test.t;
Expand Up @@ -11,7 +11,6 @@ DESC sys.schema_tables_with_full_table_scans;
SELECT * FROM sys.schema_tables_with_full_table_scans;
--enable_result_log


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

Expand All @@ -21,27 +20,25 @@ SELECT * FROM sys.x$schema_tables_with_full_table_scans;
--enable_result_log

# Create a dummy table, force some full table scans, verify the results
CREATE DATABASE v_schema_tables_with_full_table_scans;

CREATE TABLE v_schema_tables_with_full_table_scans.t (i BIGINT AUTO_INCREMENT PRIMARY KEY, j BIGINT) ENGINE = innodb;
CREATE TABLE test.t (i BIGINT AUTO_INCREMENT PRIMARY KEY, j BIGINT) ENGINE = innodb;

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

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

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

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

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

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

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

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

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

# The table should now have 768 rows

Expand All @@ -51,40 +48,39 @@ 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_schema_tables_with_full_table_scans.t WHERE j = 12;
SELECT i, j, RAND() FROM test.t WHERE j = 12;
--enable_result_log

# Ensure the base performance schema data is aggregated first
--let $wait_condition= SELECT COUNT_STAR = 768 FROM performance_schema.table_io_waits_summary_by_index_usage WHERE object_schema = 'test' AND object_name = 't' AND index_name IS NULL
--source include/wait_condition.inc

# Now verify the table shows up in the views with the right row count (should be 768)
SELECT object_schema, object_name, rows_full_scanned FROM sys.schema_tables_with_full_table_scans;

SELECT object_schema, object_name, rows_full_scanned FROM sys.x$schema_tables_with_full_table_scans;

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

# Again ensure the base performance schema data is aggregated first
--let $wait_condition= SELECT COUNT_STAR = 1536 FROM performance_schema.table_io_waits_summary_by_index_usage WHERE object_schema = 'test' AND object_name = 't' AND index_name IS NULL
--source include/wait_condition.inc

# Now verify that double the amount of rows in the table should be shown as scanned (should be 1536)
SELECT object_schema, object_name, rows_full_scanned FROM sys.schema_tables_with_full_table_scans;

SELECT object_schema, object_name, rows_full_scanned FROM sys.x$schema_tables_with_full_table_scans;

# Do a point lookup
SELECT * FROM v_schema_tables_with_full_table_scans.t WHERE i = 10;
SELECT * FROM test.t WHERE i = 10;

# The number of rows scanned should not have changed (should still be 1536)
SELECT object_schema, object_name, rows_full_scanned FROM sys.schema_tables_with_full_table_scans;

SELECT object_schema, object_name, rows_full_scanned FROM sys.x$schema_tables_with_full_table_scans;

# Cleanup
DROP DATABASE v_schema_tables_with_full_table_scans;

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

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

DROP TABLE test.t;

0 comments on commit a4ee5e6

Please sign in to comment.