Skip to content

Commit 551d2eb

Browse files
committed
Bug#14069132 : STATEMENT DIGESTS DUPLICATE CALL STATEMENTS OF THE SAME NORMALIZED FORM
Issue: During parsing of a call statement, tokens from sub statements were getting considered as well because of which tokens collection of 'call statement' was getting affected. So, due to these extra unwanted tokens, digest generated for call statement, was different from the further calls of same call statement where sub statements were not parsed again. Resolution: Restrict collection of token for only top-level statement. i.e. no instrumentation for sub-statements.
1 parent e3d4d8b commit 551d2eb

15 files changed

Lines changed: 272 additions & 40 deletions

mysql-test/suite/perfschema/include/digest_cleanup.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ DROP TABLE IF EXISTS t3;
88
DROP TABLE IF EXISTS t4;
99
DROP TABLE IF EXISTS t5;
1010
DROP TABLE IF EXISTS t6;
11+
DROP TABLE IF EXISTS t11;
12+
DROP TABLE IF EXISTS t12;
1113
DROP DATABASE IF EXISTS statements_digest;
1214
--enable_warnings

mysql-test/suite/perfschema/include/digest_execution.inc

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,40 @@ DROP DATABASE statements_digest_temp;
9191
# captured.
9292
# -----------------------------------------------------------------------
9393
--ERROR ER_NO_SUCH_TABLE
94-
SELECT 1 from t11;
95-
create table t11 (c char(4));
94+
SELECT 1 FROM no_such_table;
95+
CREATE TABLE dup_table (c char(4));
9696
--ERROR ER_TABLE_EXISTS_ERROR
97-
create table t11 (c char(4));
98-
insert into t11 values("MySQL");
99-
97+
CREATE TABLE dup_table (c char(4));
98+
DROP TABLE dup_table;
99+
INSERT INTO t11 VALUES("MySQL");
100100

101+
# -----------------------------------------------------------------------
102+
# Tests to show sub-statements for following statements are not
103+
# instrumented.
104+
# - Prepared Statements
105+
# - Stored Procedures/Functions.
106+
# - Table Triggers
107+
# -----------------------------------------------------------------------
108+
PREPARE stmt FROM "SELECT * FROM t12";
109+
EXECUTE stmt;
110+
EXECUTE stmt;
111+
DEALLOCATE PREPARE stmt;
112+
113+
DELIMITER //;
114+
CREATE PROCEDURE p1() BEGIN SELECT * FROM t12; END//
115+
DELIMITER ;//
116+
CALL p1();
117+
CALL p1();
118+
DROP PROCEDURE p1;
119+
120+
DELIMITER //;
121+
CREATE FUNCTION `func`(a INT, b INT) RETURNS int(11) RETURN a+b //
122+
DELIMITER ;//
123+
select func(3,4);
124+
select func(13,42);
125+
DROP FUNCTION func;
126+
127+
CREATE TRIGGER trg BEFORE INSERT ON t12 FOR EACH ROW SET @a:=1;
128+
INSERT INTO t12 VALUES ("abc");
129+
INSERT INTO t12 VALUES ("def");
130+
DROP TRIGGER trg;

mysql-test/suite/perfschema/include/digest_setup.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ CREATE TABLE t3(a int, b int);
1818
CREATE TABLE t4(a int, b int);
1919
CREATE TABLE t5(a int, b int, c int);
2020
CREATE TABLE t6(a int, b int, c int, d int);
21+
CREATE TABLE t11 (c CHAR(4));
22+
CREATE TABLE t12 (c CHAR(4));
2123
--enable_warnings
2224

mysql-test/suite/perfschema/r/digest_table_full.result

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ CREATE TABLE t3(a int, b int);
99
CREATE TABLE t4(a int, b int);
1010
CREATE TABLE t5(a int, b int, c int);
1111
CREATE TABLE t6(a int, b int, c int, d int);
12+
CREATE TABLE t11 (c CHAR(4));
13+
CREATE TABLE t12 (c CHAR(4));
1214
TRUNCATE TABLE performance_schema.events_statements_summary_by_digest;
1315
####################################
1416
# EXECUTION
@@ -71,21 +73,46 @@ CREATE SCHEMA statements_digest_temp;
7173
DROP SCHEMA statements_digest_temp;
7274
CREATE DATABASE statements_digest_temp;
7375
DROP DATABASE statements_digest_temp;
74-
SELECT 1 from t11;
75-
ERROR 42S02: Table 'statements_digest.t11' doesn't exist
76-
create table t11 (c char(4));
77-
create table t11 (c char(4));
78-
ERROR 42S01: Table 't11' already exists
79-
insert into t11 values("MySQL");
76+
SELECT 1 FROM no_such_table;
77+
ERROR 42S02: Table 'statements_digest.no_such_table' doesn't exist
78+
CREATE TABLE dup_table (c char(4));
79+
CREATE TABLE dup_table (c char(4));
80+
ERROR 42S01: Table 'dup_table' already exists
81+
DROP TABLE dup_table;
82+
INSERT INTO t11 VALUES("MySQL");
8083
Warnings:
8184
Warning 1265 Data truncated for column 'c' at row 1
85+
PREPARE stmt FROM "SELECT * FROM t12";
86+
EXECUTE stmt;
87+
c
88+
EXECUTE stmt;
89+
c
90+
DEALLOCATE PREPARE stmt;
91+
CREATE PROCEDURE p1() BEGIN SELECT * FROM t12; END//
92+
CALL p1();
93+
c
94+
CALL p1();
95+
c
96+
DROP PROCEDURE p1;
97+
CREATE FUNCTION `func`(a INT, b INT) RETURNS int(11) RETURN a+b //
98+
select func(3,4);
99+
func(3,4)
100+
7
101+
select func(13,42);
102+
func(13,42)
103+
55
104+
DROP FUNCTION func;
105+
CREATE TRIGGER trg BEFORE INSERT ON t12 FOR EACH ROW SET @a:=1;
106+
INSERT INTO t12 VALUES ("abc");
107+
INSERT INTO t12 VALUES ("def");
108+
DROP TRIGGER trg;
82109
####################################
83110
# QUERYING PS STATEMENT DIGEST
84111
####################################
85112
SELECT DIGEST, DIGEST_TEXT, COUNT_STAR, SUM_ROWS_AFFECTED, SUM_WARNINGS,
86113
SUM_ERRORS FROM performance_schema.events_statements_summary_by_digest;
87114
DIGEST DIGEST_TEXT COUNT_STAR SUM_ROWS_AFFECTED SUM_WARNINGS SUM_ERRORS
88-
NULL NULL 38 30 1 2
115+
NULL NULL 55 32 1 2
89116
6c4650f18d00d7f69763f7c1836e872e TRUNCATE TABLE performance_schema . events_statements_summary_by_digest 1 0 0 0
90117
SHOW VARIABLES LIKE "performance_schema_digests_size";
91118
Variable_name Value
@@ -102,4 +129,6 @@ DROP TABLE IF EXISTS t3;
102129
DROP TABLE IF EXISTS t4;
103130
DROP TABLE IF EXISTS t5;
104131
DROP TABLE IF EXISTS t6;
132+
DROP TABLE IF EXISTS t11;
133+
DROP TABLE IF EXISTS t12;
105134
DROP DATABASE IF EXISTS statements_digest;

mysql-test/suite/perfschema/r/start_server_no_digests.result

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ CREATE TABLE t3(a int, b int);
99
CREATE TABLE t4(a int, b int);
1010
CREATE TABLE t5(a int, b int, c int);
1111
CREATE TABLE t6(a int, b int, c int, d int);
12+
CREATE TABLE t11 (c CHAR(4));
13+
CREATE TABLE t12 (c CHAR(4));
1214
TRUNCATE TABLE performance_schema.events_statements_summary_by_digest;
1315
####################################
1416
# EXECUTION
@@ -71,14 +73,39 @@ CREATE SCHEMA statements_digest_temp;
7173
DROP SCHEMA statements_digest_temp;
7274
CREATE DATABASE statements_digest_temp;
7375
DROP DATABASE statements_digest_temp;
74-
SELECT 1 from t11;
75-
ERROR 42S02: Table 'statements_digest.t11' doesn't exist
76-
create table t11 (c char(4));
77-
create table t11 (c char(4));
78-
ERROR 42S01: Table 't11' already exists
79-
insert into t11 values("MySQL");
76+
SELECT 1 FROM no_such_table;
77+
ERROR 42S02: Table 'statements_digest.no_such_table' doesn't exist
78+
CREATE TABLE dup_table (c char(4));
79+
CREATE TABLE dup_table (c char(4));
80+
ERROR 42S01: Table 'dup_table' already exists
81+
DROP TABLE dup_table;
82+
INSERT INTO t11 VALUES("MySQL");
8083
Warnings:
8184
Warning 1265 Data truncated for column 'c' at row 1
85+
PREPARE stmt FROM "SELECT * FROM t12";
86+
EXECUTE stmt;
87+
c
88+
EXECUTE stmt;
89+
c
90+
DEALLOCATE PREPARE stmt;
91+
CREATE PROCEDURE p1() BEGIN SELECT * FROM t12; END//
92+
CALL p1();
93+
c
94+
CALL p1();
95+
c
96+
DROP PROCEDURE p1;
97+
CREATE FUNCTION `func`(a INT, b INT) RETURNS int(11) RETURN a+b //
98+
select func(3,4);
99+
func(3,4)
100+
7
101+
select func(13,42);
102+
func(13,42)
103+
55
104+
DROP FUNCTION func;
105+
CREATE TRIGGER trg BEFORE INSERT ON t12 FOR EACH ROW SET @a:=1;
106+
INSERT INTO t12 VALUES ("abc");
107+
INSERT INTO t12 VALUES ("def");
108+
DROP TRIGGER trg;
82109
####################################
83110
# QUERYING PS STATEMENT DIGEST
84111
####################################
@@ -100,4 +127,6 @@ DROP TABLE IF EXISTS t3;
100127
DROP TABLE IF EXISTS t4;
101128
DROP TABLE IF EXISTS t5;
102129
DROP TABLE IF EXISTS t6;
130+
DROP TABLE IF EXISTS t11;
131+
DROP TABLE IF EXISTS t12;
103132
DROP DATABASE IF EXISTS statements_digest;

mysql-test/suite/perfschema/r/statement_digest.result

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ CREATE TABLE t3(a int, b int);
99
CREATE TABLE t4(a int, b int);
1010
CREATE TABLE t5(a int, b int, c int);
1111
CREATE TABLE t6(a int, b int, c int, d int);
12+
CREATE TABLE t11 (c CHAR(4));
13+
CREATE TABLE t12 (c CHAR(4));
1214
TRUNCATE TABLE performance_schema.events_statements_summary_by_digest;
1315
####################################
1416
# EXECUTION
@@ -71,14 +73,39 @@ CREATE SCHEMA statements_digest_temp;
7173
DROP SCHEMA statements_digest_temp;
7274
CREATE DATABASE statements_digest_temp;
7375
DROP DATABASE statements_digest_temp;
74-
SELECT 1 from t11;
75-
ERROR 42S02: Table 'statements_digest.t11' doesn't exist
76-
create table t11 (c char(4));
77-
create table t11 (c char(4));
78-
ERROR 42S01: Table 't11' already exists
79-
insert into t11 values("MySQL");
76+
SELECT 1 FROM no_such_table;
77+
ERROR 42S02: Table 'statements_digest.no_such_table' doesn't exist
78+
CREATE TABLE dup_table (c char(4));
79+
CREATE TABLE dup_table (c char(4));
80+
ERROR 42S01: Table 'dup_table' already exists
81+
DROP TABLE dup_table;
82+
INSERT INTO t11 VALUES("MySQL");
8083
Warnings:
8184
Warning 1265 Data truncated for column 'c' at row 1
85+
PREPARE stmt FROM "SELECT * FROM t12";
86+
EXECUTE stmt;
87+
c
88+
EXECUTE stmt;
89+
c
90+
DEALLOCATE PREPARE stmt;
91+
CREATE PROCEDURE p1() BEGIN SELECT * FROM t12; END//
92+
CALL p1();
93+
c
94+
CALL p1();
95+
c
96+
DROP PROCEDURE p1;
97+
CREATE FUNCTION `func`(a INT, b INT) RETURNS int(11) RETURN a+b //
98+
select func(3,4);
99+
func(3,4)
100+
7
101+
select func(13,42);
102+
func(13,42)
103+
55
104+
DROP FUNCTION func;
105+
CREATE TRIGGER trg BEFORE INSERT ON t12 FOR EACH ROW SET @a:=1;
106+
INSERT INTO t12 VALUES ("abc");
107+
INSERT INTO t12 VALUES ("def");
108+
DROP TRIGGER trg;
82109
####################################
83110
# QUERYING PS STATEMENT DIGEST
84111
####################################
@@ -105,10 +132,23 @@ bcb3fc3aa0ea73f20809e6525d41b95b SELECT ? + ? 3 0 0 0
105132
651e639ea4fee3b3dbee7f6f9fd44ca0 SELECT ? 1 0 0 0
106133
7d2a54e6edd2117b661078941415d492 CREATE SCHEMA statements_digest_temp 2 2 0 0
107134
131870b25daddd214b5c200444364bd2 DROP SCHEMA statements_digest_temp 2 0 0 0
108-
249a5f8b104c00dedcc50d71449bba0d SELECT ? FROM t11 1 0 0 1
109-
72c49981fce5ac1ee4f4877119b825f5 CREATE TABLE t11 ( c CHARACTER (?) ) 2 0 0 1
135+
b0fd38c8c8ba0c583fbb4ba8f1700913 SELECT ? FROM no_such_table 1 0 0 1
136+
82405affe63462139756f46ea36e519d CREATE TABLE dup_table ( c CHARACTER (?) ) 2 0 0 1
137+
de657b9e0f2a65bbbfe94547ebcfebe5 DROP TABLE dup_table 1 0 0 0
110138
21ccf832feb3cd3581d472f7225ec046 INSERT INTO t11 VALUES (?) 1 1 1 0
111139
1965b72c3916198861e7286faeece568 SHOW WARNINGS 1 0 0 0
140+
9e2523c476f7dadd9300cceb882f434b PREPARE stmt FROM ? 1 0 0 0
141+
6d8939f45fc7420164ce88e58a78968e EXECUTE stmt 2 0 0 0
142+
3233cf3d73bf0cd5c5cc69fab5b30ddf DEALLOCATE PREPARE stmt 1 0 0 0
143+
c11611c72fd535d2491e30c92a46dba2 CREATE PROCEDURE p1 ( ) BEGIN SELECT * FROM t12 ; END 1 0 0 0
144+
594360f7221c898fb58af64d2867dea5 CALL p1 ( ) 2 0 0 0
145+
ec4a8c0368967dd4d9e4979d63204870 DROP PROCEDURE p1 1 0 0 0
146+
22af63e8a85ae33a51d39946fa74c537 CREATE FUNCTION `func` ( a INTEGER , b INTEGER ) RETURNS INTEGER (?) RETURN a + b 1 0 0 0
147+
c08a61e1b30bd73d60a0291fbf80cff0 SELECT func (...) 2 0 0 0
148+
3df78ea379365800dd19ab9e35c7f8a5 DROP FUNCTION func 1 0 0 0
149+
5499b14bde826af68fdf34c3c1310f47 CREATE TRIGGER trg BEFORE INSERT ON t12 FOR EACH ROW SET @ ? := ? 1 0 0 0
150+
8ec19a492733284c1444a7a804286800 INSERT INTO t12 VALUES (?) 2 2 0 0
151+
25abe6e665794bc331965c048ea0bf5e DROP TRIGGER trg 1 0 0 0
112152
####################################
113153
# CLEANUP
114154
####################################
@@ -118,4 +158,6 @@ DROP TABLE IF EXISTS t3;
118158
DROP TABLE IF EXISTS t4;
119159
DROP TABLE IF EXISTS t5;
120160
DROP TABLE IF EXISTS t6;
161+
DROP TABLE IF EXISTS t11;
162+
DROP TABLE IF EXISTS t12;
121163
DROP DATABASE IF EXISTS statements_digest;

mysql-test/suite/perfschema/r/statement_digest_consumers.result

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ CREATE TABLE t3(a int, b int);
99
CREATE TABLE t4(a int, b int);
1010
CREATE TABLE t5(a int, b int, c int);
1111
CREATE TABLE t6(a int, b int, c int, d int);
12+
CREATE TABLE t11 (c CHAR(4));
13+
CREATE TABLE t12 (c CHAR(4));
1214
SELECT * FROM performance_schema.setup_consumers;
1315
NAME ENABLED
1416
events_stages_current YES
@@ -85,14 +87,39 @@ CREATE SCHEMA statements_digest_temp;
8587
DROP SCHEMA statements_digest_temp;
8688
CREATE DATABASE statements_digest_temp;
8789
DROP DATABASE statements_digest_temp;
88-
SELECT 1 from t11;
89-
ERROR 42S02: Table 'statements_digest.t11' doesn't exist
90-
create table t11 (c char(4));
91-
create table t11 (c char(4));
92-
ERROR 42S01: Table 't11' already exists
93-
insert into t11 values("MySQL");
90+
SELECT 1 FROM no_such_table;
91+
ERROR 42S02: Table 'statements_digest.no_such_table' doesn't exist
92+
CREATE TABLE dup_table (c char(4));
93+
CREATE TABLE dup_table (c char(4));
94+
ERROR 42S01: Table 'dup_table' already exists
95+
DROP TABLE dup_table;
96+
INSERT INTO t11 VALUES("MySQL");
9497
Warnings:
9598
Warning 1265 Data truncated for column 'c' at row 1
99+
PREPARE stmt FROM "SELECT * FROM t12";
100+
EXECUTE stmt;
101+
c
102+
EXECUTE stmt;
103+
c
104+
DEALLOCATE PREPARE stmt;
105+
CREATE PROCEDURE p1() BEGIN SELECT * FROM t12; END//
106+
CALL p1();
107+
c
108+
CALL p1();
109+
c
110+
DROP PROCEDURE p1;
111+
CREATE FUNCTION `func`(a INT, b INT) RETURNS int(11) RETURN a+b //
112+
select func(3,4);
113+
func(3,4)
114+
7
115+
select func(13,42);
116+
func(13,42)
117+
55
118+
DROP FUNCTION func;
119+
CREATE TRIGGER trg BEFORE INSERT ON t12 FOR EACH ROW SET @a:=1;
120+
INSERT INTO t12 VALUES ("abc");
121+
INSERT INTO t12 VALUES ("def");
122+
DROP TRIGGER trg;
96123
####################################
97124
# QUERYING PS STATEMENT DIGEST
98125
####################################
@@ -118,10 +145,23 @@ bcb3fc3aa0ea73f20809e6525d41b95b SELECT ? + ? 3
118145
651e639ea4fee3b3dbee7f6f9fd44ca0 SELECT ? 1
119146
7d2a54e6edd2117b661078941415d492 CREATE SCHEMA statements_digest_temp 2
120147
131870b25daddd214b5c200444364bd2 DROP SCHEMA statements_digest_temp 2
121-
249a5f8b104c00dedcc50d71449bba0d SELECT ? FROM t11 1
122-
72c49981fce5ac1ee4f4877119b825f5 CREATE TABLE t11 ( c CHARACTER (?) ) 2
148+
b0fd38c8c8ba0c583fbb4ba8f1700913 SELECT ? FROM no_such_table 1
149+
82405affe63462139756f46ea36e519d CREATE TABLE dup_table ( c CHARACTER (?) ) 2
150+
de657b9e0f2a65bbbfe94547ebcfebe5 DROP TABLE dup_table 1
123151
21ccf832feb3cd3581d472f7225ec046 INSERT INTO t11 VALUES (?) 1
124152
1965b72c3916198861e7286faeece568 SHOW WARNINGS 1
153+
9e2523c476f7dadd9300cceb882f434b PREPARE stmt FROM ? 1
154+
6d8939f45fc7420164ce88e58a78968e EXECUTE stmt 2
155+
3233cf3d73bf0cd5c5cc69fab5b30ddf DEALLOCATE PREPARE stmt 1
156+
c11611c72fd535d2491e30c92a46dba2 CREATE PROCEDURE p1 ( ) BEGIN SELECT * FROM t12 ; END 1
157+
594360f7221c898fb58af64d2867dea5 CALL p1 ( ) 2
158+
ec4a8c0368967dd4d9e4979d63204870 DROP PROCEDURE p1 1
159+
22af63e8a85ae33a51d39946fa74c537 CREATE FUNCTION `func` ( a INTEGER , b INTEGER ) RETURNS INTEGER (?) RETURN a + b 1
160+
c08a61e1b30bd73d60a0291fbf80cff0 SELECT func (...) 2
161+
3df78ea379365800dd19ab9e35c7f8a5 DROP FUNCTION func 1
162+
5499b14bde826af68fdf34c3c1310f47 CREATE TRIGGER trg BEFORE INSERT ON t12 FOR EACH ROW SET @ ? := ? 1
163+
8ec19a492733284c1444a7a804286800 INSERT INTO t12 VALUES (?) 2
164+
25abe6e665794bc331965c048ea0bf5e DROP TRIGGER trg 1
125165
SELECT digest, digest_text FROM performance_schema.events_statements_current;
126166
digest digest_text
127167
####################################
@@ -133,4 +173,6 @@ DROP TABLE IF EXISTS t3;
133173
DROP TABLE IF EXISTS t4;
134174
DROP TABLE IF EXISTS t5;
135175
DROP TABLE IF EXISTS t6;
176+
DROP TABLE IF EXISTS t11;
177+
DROP TABLE IF EXISTS t12;
136178
DROP DATABASE IF EXISTS statements_digest;

0 commit comments

Comments
 (0)