From: Mayank Prasad Date: December 28 2011 3:58pm Subject: bzr push into mysql-trunk-wl5767 branch (mayank.prasad:3408 to 3409) WL#5767 List-Archive: http://lists.mysql.com/commits/142267 Message-Id: <201112281558.pBSFwxG7002471@acsmt357.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3409 Mayank Prasad 2011-12-28 WL#5767: Performance Schema, Statements Digest Details: - Addressed code review comment from Marc - Added a test case for Statement Digest added: mysql-test/suite/perfschema/r/statements_digest.result mysql-test/suite/perfschema/t/statements_digest.test modified: storage/perfschema/pfs_digest.cc 3408 Mayank Prasad 2011-12-28 WL#5767 : Statement Digest, Performance Schema Details: - Added code to REDUCE tokens (i.e. normalization). modified: storage/perfschema/gen_pfs_lex_token.cc storage/perfschema/pfs_digest.cc === added file 'mysql-test/suite/perfschema/r/statements_digest.result' --- a/mysql-test/suite/perfschema/r/statements_digest.result 1970-01-01 00:00:00 +0000 +++ b/mysql-test/suite/perfschema/r/statements_digest.result 2011-12-28 15:56:31 +0000 @@ -0,0 +1,69 @@ +#################################### +# SETUP +#################################### +create database statements_digest; +use statements_digest; +create table t1(a int); +create table t2(a int); +create table t3(a int, b int); +create table t4(a int, b int); +create table t5(a int, b int, c int); +#################################### +# EXECUTION +#################################### +update performance_schema.setup_consumers +set enabled='YES' where name='statements_digest'; +select 1 from t1; +1 +select 1,2 from t1; +1 2 +select 1, 2, 3, 4 from t1; +1 2 3 4 +select 1 from t2; +1 +select 1,2 from t2; +1 2 +select 1, 2, 3, 4 from t2; +1 2 3 4 +insert into t1 values (1); +insert into t2 values (1); +insert into t3 values (1, 2); +insert into t4 values (1, 2); +insert into t5 values (1, 2, 3); +insert into t1 values (1), (2), (3); +insert into t1 values (1), (2), (3), (4); +insert into t3 values (1, 2), (3, 4), (5, 6); +insert into t5 values (1, 2, 3), (4, 5, 6), (7, 8, 9); +#################################### +# QUERYING PS STATEMENT DIGEST +#################################### +use performance_schema; +select DIGEST, DIGEST_TEXT, COUNT_STAR from events_statements_summary_by_digest; +DIGEST DIGEST_TEXT COUNT_STAR +d653d1281782b5e6 SHOW SLAVE STATUS 1 +09f222399f1ff5cc SELECT # = # 1 +169ffc24ec704d77 CREATE DEFINER = ID @ ID PROCEDURE ID ( ) BEGIN IF ( ( SELECT COUNT ( * ) FROM ID . ID WHERE ENGINE = # AND ID = # ) = # ) THEN BEGIN BEGIN DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END ; SELECT * FROM ID . ID WHERE ID = # ORDER BY NAME ; END ; SELECT * FROM ID . ID ORDER BY NAME ; SELECT * FROM ID . ID ORDER BY SYSTEM_USER , HOST ; SELECT * FROM ID . ID ORDER BY ID , ID , ID ; END ; END IF ; END 2 +4b76d252a0165dc8 SELECT ID ( ) LIKE # AS # 1 +9f5fb719d3e76d05 SELECT COUNT ( * ) FROM ID . ID WHERE ( ID = # OR ID = # ) AND ENGINE = # 1 +5057d979ab43ca33 CREATE SCHEMA ID 1 +e465b463797ef48f USE ID 2 +6bd5a0ecf894b7da CREATE TABLE ID ( ID INTEGER ) 2 +8ac419795130a28b CREATE TABLE ID ( ID INTEGER , ID INTEGER ) 2 +0e486b6cac8061e8 CREATE TABLE ID ( ID INTEGER , ID INTEGER , ID INTEGER ) 1 +5c8520ef69799e72 UPDATE ID . ID SET ID = # WHERE NAME = # 1 +89098056976d499b SELECT # FROM ID 2 +67d4fdbc91c296f6 SELECT #,# FROM ID 4 +fcca45f32a578e33 INSERT INTO ID VALUES (#) 2 +de4735d2ec38cc75 INSERT INTO ID VALUES (#,#) 3 +aefa0a1987e628a2 INSERT INTO ID VALUES (#),(#) 2 +078fc2c78d15c811 INSERT INTO ID VALUES (#,#),(#,#) 2 +#################################### +# CLEANUP +#################################### +use statements_digest; +drop table if exists t1; +drop table if exists t2; +drop table if exists t3; +drop table if exists t4; +drop table if exists t5; +drop database if exists statements_digest; === added file 'mysql-test/suite/perfschema/t/statements_digest.test' --- a/mysql-test/suite/perfschema/t/statements_digest.test 1970-01-01 00:00:00 +0000 +++ b/mysql-test/suite/perfschema/t/statements_digest.test 2011-12-28 15:56:31 +0000 @@ -0,0 +1,79 @@ +# ---------------------------------------------------- +# Tests for the performance schema statement Digests. +# ---------------------------------------------------- + +--source include/not_embedded.inc +--source include/have_perfschema.inc + +--echo #################################### +--echo # SETUP +--echo #################################### +# Database setup +--disable_warnings +create database statements_digest; +--enable_warnings +use statements_digest; + +# Table set up for queries +--disable_warnings +create table t1(a int); +create table t2(a int); +create table t3(a int, b int); +create table t4(a int, b int); +create table t5(a int, b int, c int); +--enable_warnings + +--echo #################################### +--echo # EXECUTION +--echo #################################### +# Enable statements_digest consumer +update performance_schema.setup_consumers + set enabled='YES' where name='statements_digest'; + +# SQL Queries to test normalizations +select 1 from t1; +select 1,2 from t1; +select 1, 2, 3, 4 from t1; +select 1 from t2; +select 1,2 from t2; +select 1, 2, 3, 4 from t2; + +# (NUM) => (#) +insert into t1 values (1); +insert into t2 values (1); + +# (NUM,NUM) => (#,#) +insert into t3 values (1, 2); +insert into t4 values (1, 2); +# (NUM,NUM,NUM) => (#,#) +insert into t5 values (1, 2, 3); + +# (NUM),(NUM) => (#),(#) +insert into t1 values (1), (2), (3); +# (NUM),(NUM),(NUM) => (#),(#) +insert into t1 values (1), (2), (3), (4); + +# (NUM,NUM),(NUM,NUM) => (#,#),(#,#) +insert into t3 values (1, 2), (3, 4), (5, 6); +# (NUM,NUM,NUM),(NUM,NUM,NUM),(NUM,NUM,NUM) => (#,#),(#,#) +insert into t5 values (1, 2, 3), (4, 5, 6), (7, 8, 9); + +--echo #################################### +--echo # QUERYING PS STATEMENT DIGEST +--echo #################################### + +use performance_schema; +select DIGEST, DIGEST_TEXT, COUNT_STAR from events_statements_summary_by_digest; + +--echo #################################### +--echo # CLEANUP +--echo #################################### +use statements_digest; +--disable_warnings +drop table if exists t1; +drop table if exists t2; +drop table if exists t3; +drop table if exists t4; +drop table if exists t5; +drop database if exists statements_digest; +--enable_warnings === modified file 'storage/perfschema/pfs_digest.cc' --- a/storage/perfschema/pfs_digest.cc 2011-12-28 12:40:43 +0000 +++ b/storage/perfschema/pfs_digest.cc 2011-12-28 15:56:31 +0000 @@ -466,20 +466,13 @@ void pfs_digest_add_token_v1(PSI_digest_ digest_storage->m_token_count-= 1; token= TOK_PFS_ROW_POSSIBLE_SINGLE_VALUE; } - else if((current[-2] == TOK_PFS_ROW_POSSIBLE_SINGLE_VALUE) && + else if((current[-2] == TOK_PFS_ROW_POSSIBLE_SINGLE_VALUE || + current[-2] == TOK_PFS_ROW_POSSIBLE_MULTIPLE_VALUE) && (current[-1] == ',')) { /* REDUCE: "(#" , "#" => "(#,#" - */ - digest_storage->m_token_count-= 2; - token= TOK_PFS_ROW_POSSIBLE_MULTIPLE_VALUE; - } - else if((current[-2] == TOK_PFS_ROW_POSSIBLE_MULTIPLE_VALUE) && - (current[-1] == ',')) - { - /* REDUCE: "(#,#" , "#" => "(#,#" */ @@ -491,50 +484,60 @@ void pfs_digest_add_token_v1(PSI_digest_ } case ')': { - if(current[-1] == TOK_PFS_ROW_POSSIBLE_SINGLE_VALUE) - { - /* - REDUCE: - "(#" , ")" => "(#)" - */ - digest_storage->m_token_count-= 1; - token= TOK_PFS_ROW_SINGLE_VALUE; - - if((current[-3] == TOK_PFS_ROW_SINGLE_VALUE || - current[-3] == TOK_PFS_ROW_SINGLE_VALUE_LIST) && - (current[-2] == ',')) - { + if (digest_storage->m_token_count > 0) + { + if(current[-1] == TOK_PFS_ROW_POSSIBLE_SINGLE_VALUE) + { /* REDUCE: - "(#)" , "(#)" => "(#),(#)" - REDUCE: - "(#),(#)" , "(#)" => "(#),(#)" + "(#" , ")" => "(#)" */ - digest_storage->m_token_count-= 2; - token= TOK_PFS_ROW_SINGLE_VALUE_LIST; + digest_storage->m_token_count-= 1; + token= TOK_PFS_ROW_SINGLE_VALUE; + + if (digest_storage->m_token_count >= 2) + { + if((current[-3] == TOK_PFS_ROW_SINGLE_VALUE || + current[-3] == TOK_PFS_ROW_SINGLE_VALUE_LIST) && + (current[-2] == ',')) + { + /* + REDUCE: + "(#)" , "(#)" => "(#),(#)" + REDUCE: + "(#),(#)" , "(#)" => "(#),(#)" + */ + digest_storage->m_token_count-= 2; + token= TOK_PFS_ROW_SINGLE_VALUE_LIST; + } + } } - } - - else if(current[-1] == TOK_PFS_ROW_POSSIBLE_MULTIPLE_VALUE) - { - /* - REDUCE: - "(#,#" , ")" => "(#,#)" - */ - digest_storage->m_token_count-= 1; - token= TOK_PFS_ROW_MULTIPLE_VALUE; - if((current[-3] == TOK_PFS_ROW_MULTIPLE_VALUE || - current[-3] == TOK_PFS_ROW_MULTIPLE_VALUE_LIST) && - (current[-2] == ',')) + + else if(current[-1] == TOK_PFS_ROW_POSSIBLE_MULTIPLE_VALUE) { /* REDUCE: - "(#,#)" , "(#,#)" ) => "(#,#),(#,#)" - REDUCE: - "(#,#),(#,#)" , "(#,#)" ) => "(#,#),(#,#)" + "(#,#" , ")" => "(#,#)" */ - digest_storage->m_token_count-= 2; - token= TOK_PFS_ROW_MULTIPLE_VALUE_LIST; + digest_storage->m_token_count-= 1; + token= TOK_PFS_ROW_MULTIPLE_VALUE; + + if (digest_storage->m_token_count >= 2) + { + if((current[-3] == TOK_PFS_ROW_MULTIPLE_VALUE || + current[-3] == TOK_PFS_ROW_MULTIPLE_VALUE_LIST) && + (current[-2] == ',')) + { + /* + REDUCE: + "(#,#)" , "(#,#)" ) => "(#,#),(#,#)" + REDUCE: + "(#,#),(#,#)" , "(#,#)" ) => "(#,#),(#,#)" + */ + digest_storage->m_token_count-= 2; + token= TOK_PFS_ROW_MULTIPLE_VALUE_LIST; + } + } } } break; No bundle (reason: useless for push emails).