From 70fd13346d4a3c92d005d6cc71f8a19743d98e94 Mon Sep 17 00:00:00 2001
From: Marc Alff <marc.alff@oracle.com>
Date: Thu, 10 Mar 2011 13:02:28 +0100
Subject: [PATCH] Reworked the test case to be more robust.

---
 mysql-test/suite/perfschema/r/relaylog.result | 147 ++++++++++++------
 mysql-test/suite/perfschema/t/relaylog.test   |  93 ++++++++---
 2 files changed, 173 insertions(+), 67 deletions(-)

diff --git a/mysql-test/suite/perfschema/r/relaylog.result b/mysql-test/suite/perfschema/r/relaylog.result
index 1ec9f4f4b29..079d1e482b2 100644
--- a/mysql-test/suite/perfschema/r/relaylog.result
+++ b/mysql-test/suite/perfschema/r/relaylog.result
@@ -9,33 +9,55 @@ Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 slave-bin.000001	#	Query	#	#	use `test`; create table test.t1(a int)
 slave-bin.000001	#	Query	#	#	use `test`; DROP TABLE `t1` /* generated by server */
 "============ Performance schema on master ============"
-select * from performance_schema.file_summary_by_instance
+select
+substring(file_name, locate("master-", file_name)) as FILE_NAME,
+EVENT_NAME,
+if (count_read > 0, "MANY", "NONE") as COUNT_READ,
+if (count_write > 0,"MANY", "NONE") as COUNT_WRITE,
+if (sum_number_of_bytes_read > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_READ,
+if (sum_number_of_bytes_write > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_WRITE
+from performance_schema.file_summary_by_instance
 where file_name like "%master-%" order by file_name;
 FILE_NAME	EVENT_NAME	COUNT_READ	COUNT_WRITE	SUM_NUMBER_OF_BYTES_READ	SUM_NUMBER_OF_BYTES_WRITE
-[DATADIR]master-bin.000001	wait/io/file/sql/binlog	6	4	221	329
-[DATADIR]master-bin.index	wait/io/file/sql/binlog_index	0	2	0	40
+master-bin.000001	wait/io/file/sql/binlog	MANY	MANY	MANY	MANY
+master-bin.index	wait/io/file/sql/binlog_index	NONE	MANY	NONE	MANY
 select * from performance_schema.file_summary_by_instance
 where file_name like "%slave-%" order by file_name;
 FILE_NAME	EVENT_NAME	COUNT_READ	COUNT_WRITE	SUM_NUMBER_OF_BYTES_READ	SUM_NUMBER_OF_BYTES_WRITE
 "Expect a master binlog + binlog_index"
-select * from performance_schema.file_summary_by_instance
+select
+substring(file_name, locate("master-", file_name)) as FILE_NAME,
+EVENT_NAME,
+if (count_read > 0, "MANY", "NONE") as COUNT_READ,
+if (count_write > 0,"MANY", "NONE") as COUNT_WRITE,
+if (sum_number_of_bytes_read > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_READ,
+if (sum_number_of_bytes_write > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_WRITE
+from performance_schema.file_summary_by_instance
 where event_name like "%binlog%" order by file_name;
 FILE_NAME	EVENT_NAME	COUNT_READ	COUNT_WRITE	SUM_NUMBER_OF_BYTES_READ	SUM_NUMBER_OF_BYTES_WRITE
-[DATADIR]master-bin.000001	wait/io/file/sql/binlog	6	4	221	329
-[DATADIR]master-bin.index	wait/io/file/sql/binlog_index	0	2	0	40
-select * from performance_schema.file_summary_by_event_name
+master-bin.000001	wait/io/file/sql/binlog	MANY	MANY	MANY	MANY
+master-bin.index	wait/io/file/sql/binlog_index	NONE	MANY	NONE	MANY
+select
+EVENT_NAME,
+if (count_read > 0, "MANY", "NONE") as COUNT_READ,
+if (count_write > 0,"MANY", "NONE") as COUNT_WRITE,
+if (sum_number_of_bytes_read > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_READ,
+if (sum_number_of_bytes_write > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_WRITE
+from performance_schema.file_summary_by_event_name
 where event_name like "%binlog%" order by event_name;
 EVENT_NAME	COUNT_READ	COUNT_WRITE	SUM_NUMBER_OF_BYTES_READ	SUM_NUMBER_OF_BYTES_WRITE
-wait/io/file/sql/binlog	6	4	221	329
-wait/io/file/sql/binlog_index	0	2	0	40
-select event_name, count_star
+wait/io/file/sql/binlog	MANY	MANY	MANY	MANY
+wait/io/file/sql/binlog_index	NONE	MANY	NONE	MANY
+select
+EVENT_NAME,
+if (count_star > 0, "MANY", "NONE") as COUNT_STAR
 from performance_schema.events_waits_summary_global_by_event_name
 where event_name like "%MYSQL_BIN_LOG%" order by event_name;
-event_name	count_star
-wait/synch/cond/sql/MYSQL_BIN_LOG::COND_prep_xids	0
-wait/synch/cond/sql/MYSQL_BIN_LOG::update_cond	1
-wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_index	3
-wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_prep_xids	0
+EVENT_NAME	COUNT_STAR
+wait/synch/cond/sql/MYSQL_BIN_LOG::COND_prep_xids	NONE
+wait/synch/cond/sql/MYSQL_BIN_LOG::update_cond	MANY
+wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_index	MANY
+wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_prep_xids	NONE
 "Expect no slave relay log"
 select * from performance_schema.file_summary_by_instance
 where event_name like "%relaylog%" order by file_name;
@@ -54,49 +76,86 @@ wait/synch/mutex/sql/MYSQL_RELAY_LOG::LOCK_index	0	0	0	0	0
 select * from performance_schema.file_summary_by_instance
 where file_name like "%master-%" order by file_name;
 FILE_NAME	EVENT_NAME	COUNT_READ	COUNT_WRITE	SUM_NUMBER_OF_BYTES_READ	SUM_NUMBER_OF_BYTES_WRITE
-select * from performance_schema.file_summary_by_instance
+select
+substring(file_name, locate("slave-", file_name)) as FILE_NAME,
+EVENT_NAME,
+if (count_read > 0, "MANY", "NONE") as COUNT_READ,
+if (count_write > 0,"MANY", "NONE") as COUNT_WRITE,
+if (sum_number_of_bytes_read > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_READ,
+if (sum_number_of_bytes_write > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_WRITE
+from performance_schema.file_summary_by_instance
 where file_name like "%slave-%" order by file_name;
 FILE_NAME	EVENT_NAME	COUNT_READ	COUNT_WRITE	SUM_NUMBER_OF_BYTES_READ	SUM_NUMBER_OF_BYTES_WRITE
-[DATADIR]slave-bin.000001	wait/io/file/sql/binlog	3	8	602	631
-[DATADIR]slave-bin.index	wait/io/file/sql/binlog_index	0	3	0	57
-[DATADIR]slave-relay-bin.000001	wait/io/file/sql/relaylog	4	3	370	263
-[DATADIR]slave-relay-bin.000002	wait/io/file/sql/relaylog	2	4	368	368
-[DATADIR]slave-relay-bin.index	wait/io/file/sql/relaylog_index	2	4	50	125
+slave-bin.000001	wait/io/file/sql/binlog	MANY	MANY	MANY	MANY
+slave-bin.index	wait/io/file/sql/binlog_index	NONE	MANY	NONE	MANY
+slave-relay-bin.000001	wait/io/file/sql/relaylog	MANY	MANY	MANY	MANY
+slave-relay-bin.000002	wait/io/file/sql/relaylog	MANY	MANY	MANY	MANY
+slave-relay-bin.index	wait/io/file/sql/relaylog_index	MANY	MANY	MANY	MANY
 "Expect a slave binlog + binlog_index"
-select * from performance_schema.file_summary_by_instance
+select
+substring(file_name, locate("slave-", file_name)) as FILE_NAME,
+EVENT_NAME,
+if (count_read > 0, "MANY", "NONE") as COUNT_READ,
+if (count_write > 0,"MANY", "NONE") as COUNT_WRITE,
+if (sum_number_of_bytes_read > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_READ,
+if (sum_number_of_bytes_write > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_WRITE
+from performance_schema.file_summary_by_instance
 where event_name like "%binlog%" order by file_name;
 FILE_NAME	EVENT_NAME	COUNT_READ	COUNT_WRITE	SUM_NUMBER_OF_BYTES_READ	SUM_NUMBER_OF_BYTES_WRITE
-[DATADIR]slave-bin.000001	wait/io/file/sql/binlog	3	8	602	631
-[DATADIR]slave-bin.index	wait/io/file/sql/binlog_index	0	3	0	57
-select * from performance_schema.file_summary_by_event_name
+slave-bin.000001	wait/io/file/sql/binlog	MANY	MANY	MANY	MANY
+slave-bin.index	wait/io/file/sql/binlog_index	NONE	MANY	NONE	MANY
+select
+EVENT_NAME,
+if (count_read > 0, "MANY", "NONE") as COUNT_READ,
+if (count_write > 0,"MANY", "NONE") as COUNT_WRITE,
+if (sum_number_of_bytes_read > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_READ,
+if (sum_number_of_bytes_write > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_WRITE
+from performance_schema.file_summary_by_event_name
 where event_name like "%binlog%" order by event_name;
 EVENT_NAME	COUNT_READ	COUNT_WRITE	SUM_NUMBER_OF_BYTES_READ	SUM_NUMBER_OF_BYTES_WRITE
-wait/io/file/sql/binlog	3	8	602	631
-wait/io/file/sql/binlog_index	0	3	0	57
-select event_name, count_star
+wait/io/file/sql/binlog	MANY	MANY	MANY	MANY
+wait/io/file/sql/binlog_index	NONE	MANY	NONE	MANY
+select
+EVENT_NAME,
+if (count_star > 0, "MANY", "NONE") as COUNT_STAR
 from performance_schema.events_waits_summary_global_by_event_name
 where event_name like "%MYSQL_BIN_LOG%" order by event_name;
-event_name	count_star
-wait/synch/cond/sql/MYSQL_BIN_LOG::COND_prep_xids	0
-wait/synch/cond/sql/MYSQL_BIN_LOG::update_cond	0
-wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_index	5
-wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_prep_xids	0
+EVENT_NAME	COUNT_STAR
+wait/synch/cond/sql/MYSQL_BIN_LOG::COND_prep_xids	NONE
+wait/synch/cond/sql/MYSQL_BIN_LOG::update_cond	NONE
+wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_index	MANY
+wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_prep_xids	NONE
 "Expect a slave relay log"
-select * from performance_schema.file_summary_by_instance
+select
+substring(file_name, locate("slave-", file_name)) as FILE_NAME,
+EVENT_NAME,
+if (count_read > 0, "MANY", "NONE") as COUNT_READ,
+if (count_write > 0,"MANY", "NONE") as COUNT_WRITE,
+if (sum_number_of_bytes_read > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_READ,
+if (sum_number_of_bytes_write > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_WRITE
+from performance_schema.file_summary_by_instance
 where event_name like "%relaylog%" order by file_name;
 FILE_NAME	EVENT_NAME	COUNT_READ	COUNT_WRITE	SUM_NUMBER_OF_BYTES_READ	SUM_NUMBER_OF_BYTES_WRITE
-[DATADIR]slave-relay-bin.000001	wait/io/file/sql/relaylog	4	3	370	263
-[DATADIR]slave-relay-bin.000002	wait/io/file/sql/relaylog	2	4	368	368
-[DATADIR]slave-relay-bin.index	wait/io/file/sql/relaylog_index	2	4	50	125
-select * from performance_schema.file_summary_by_event_name
+slave-relay-bin.000001	wait/io/file/sql/relaylog	MANY	MANY	MANY	MANY
+slave-relay-bin.000002	wait/io/file/sql/relaylog	MANY	MANY	MANY	MANY
+slave-relay-bin.index	wait/io/file/sql/relaylog_index	MANY	MANY	MANY	MANY
+select
+EVENT_NAME,
+if (count_read > 0, "MANY", "NONE") as COUNT_READ,
+if (count_write > 0,"MANY", "NONE") as COUNT_WRITE,
+if (sum_number_of_bytes_read > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_READ,
+if (sum_number_of_bytes_write > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_WRITE
+from performance_schema.file_summary_by_event_name
 where event_name like "%relaylog%" order by event_name;
 EVENT_NAME	COUNT_READ	COUNT_WRITE	SUM_NUMBER_OF_BYTES_READ	SUM_NUMBER_OF_BYTES_WRITE
-wait/io/file/sql/relaylog	6	7	738	631
-wait/io/file/sql/relaylog_index	2	4	50	125
-select event_name, count_star
+wait/io/file/sql/relaylog	MANY	MANY	MANY	MANY
+wait/io/file/sql/relaylog_index	MANY	MANY	MANY	MANY
+select
+EVENT_NAME,
+if (count_star > 0, "MANY", "NONE") as COUNT_STAR
 from performance_schema.events_waits_summary_global_by_event_name
 where event_name like "%MYSQL_RELAY_LOG%" order by event_name;
-event_name	count_star
-wait/synch/cond/sql/MYSQL_RELAY_LOG::update_cond	2
-wait/synch/mutex/sql/MYSQL_RELAY_LOG::LOCK_index	12
+EVENT_NAME	COUNT_STAR
+wait/synch/cond/sql/MYSQL_RELAY_LOG::update_cond	MANY
+wait/synch/mutex/sql/MYSQL_RELAY_LOG::LOCK_index	MANY
 include/stop_slave.inc
diff --git a/mysql-test/suite/perfschema/t/relaylog.test b/mysql-test/suite/perfschema/t/relaylog.test
index 126dacb8803..f9a4d7bfe00 100644
--- a/mysql-test/suite/perfschema/t/relaylog.test
+++ b/mysql-test/suite/perfschema/t/relaylog.test
@@ -34,32 +34,48 @@ drop table test.t1;
 connection master;
 -- echo "============ Performance schema on master ============"
 
-let $MYSQLD_DATADIR= `SELECT @@datadir`;
-
---replace_result $MYSQLD_DATADIR [DATADIR]
-select * from performance_schema.file_summary_by_instance
+select
+  substring(file_name, locate("master-", file_name)) as FILE_NAME,
+  EVENT_NAME,
+  if (count_read > 0, "MANY", "NONE") as COUNT_READ,
+  if (count_write > 0,"MANY", "NONE") as COUNT_WRITE,
+  if (sum_number_of_bytes_read > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_READ,
+  if (sum_number_of_bytes_write > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_WRITE
+  from performance_schema.file_summary_by_instance
   where file_name like "%master-%" order by file_name;
 
---replace_result $MYSQLD_DATADIR [DATADIR]
 select * from performance_schema.file_summary_by_instance
   where file_name like "%slave-%" order by file_name;
 
 -- echo "Expect a master binlog + binlog_index"
 
---replace_result $MYSQLD_DATADIR [DATADIR]
-select * from performance_schema.file_summary_by_instance
+select
+  substring(file_name, locate("master-", file_name)) as FILE_NAME,
+  EVENT_NAME,
+  if (count_read > 0, "MANY", "NONE") as COUNT_READ,
+  if (count_write > 0,"MANY", "NONE") as COUNT_WRITE,
+  if (sum_number_of_bytes_read > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_READ,
+  if (sum_number_of_bytes_write > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_WRITE
+  from performance_schema.file_summary_by_instance
   where event_name like "%binlog%" order by file_name;
 
-select * from performance_schema.file_summary_by_event_name
+select
+  EVENT_NAME,
+  if (count_read > 0, "MANY", "NONE") as COUNT_READ,
+  if (count_write > 0,"MANY", "NONE") as COUNT_WRITE,
+  if (sum_number_of_bytes_read > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_READ,
+  if (sum_number_of_bytes_write > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_WRITE
+  from performance_schema.file_summary_by_event_name
   where event_name like "%binlog%" order by event_name;
 
-select event_name, count_star
+select
+  EVENT_NAME,
+  if (count_star > 0, "MANY", "NONE") as COUNT_STAR
   from performance_schema.events_waits_summary_global_by_event_name
   where event_name like "%MYSQL_BIN_LOG%" order by event_name;
 
 -- echo "Expect no slave relay log"
 
---replace_result $MYSQLD_DATADIR [DATADIR]
 select * from performance_schema.file_summary_by_instance
   where event_name like "%relaylog%" order by file_name;
 
@@ -72,39 +88,70 @@ select * from performance_schema.events_waits_summary_global_by_event_name
 sync_slave_with_master;
 -- echo "============ Performance schema on slave ============"
 
-let $MYSQLD_DATADIR= `SELECT @@datadir`;
-
---replace_result $MYSQLD_DATADIR [DATADIR]
 select * from performance_schema.file_summary_by_instance
   where file_name like "%master-%" order by file_name;
 
---replace_result $MYSQLD_DATADIR [DATADIR]
-select * from performance_schema.file_summary_by_instance
+select
+  substring(file_name, locate("slave-", file_name)) as FILE_NAME,
+  EVENT_NAME,
+  if (count_read > 0, "MANY", "NONE") as COUNT_READ,
+  if (count_write > 0,"MANY", "NONE") as COUNT_WRITE,
+  if (sum_number_of_bytes_read > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_READ,
+  if (sum_number_of_bytes_write > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_WRITE
+  from performance_schema.file_summary_by_instance
   where file_name like "%slave-%" order by file_name;
 
 -- echo "Expect a slave binlog + binlog_index"
 
---replace_result $MYSQLD_DATADIR [DATADIR]
-select * from performance_schema.file_summary_by_instance
+select
+  substring(file_name, locate("slave-", file_name)) as FILE_NAME,
+  EVENT_NAME,
+  if (count_read > 0, "MANY", "NONE") as COUNT_READ,
+  if (count_write > 0,"MANY", "NONE") as COUNT_WRITE,
+  if (sum_number_of_bytes_read > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_READ,
+  if (sum_number_of_bytes_write > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_WRITE
+  from performance_schema.file_summary_by_instance
   where event_name like "%binlog%" order by file_name;
 
-select * from performance_schema.file_summary_by_event_name
+select
+  EVENT_NAME,
+  if (count_read > 0, "MANY", "NONE") as COUNT_READ,
+  if (count_write > 0,"MANY", "NONE") as COUNT_WRITE,
+  if (sum_number_of_bytes_read > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_READ,
+  if (sum_number_of_bytes_write > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_WRITE
+  from performance_schema.file_summary_by_event_name
   where event_name like "%binlog%" order by event_name;
 
-select event_name, count_star
+select
+  EVENT_NAME,
+  if (count_star > 0, "MANY", "NONE") as COUNT_STAR
   from performance_schema.events_waits_summary_global_by_event_name
   where event_name like "%MYSQL_BIN_LOG%" order by event_name;
 
 -- echo "Expect a slave relay log"
 
---replace_result $MYSQLD_DATADIR [DATADIR]
-select * from performance_schema.file_summary_by_instance
+select
+  substring(file_name, locate("slave-", file_name)) as FILE_NAME,
+  EVENT_NAME,
+  if (count_read > 0, "MANY", "NONE") as COUNT_READ,
+  if (count_write > 0,"MANY", "NONE") as COUNT_WRITE,
+  if (sum_number_of_bytes_read > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_READ,
+  if (sum_number_of_bytes_write > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_WRITE
+  from performance_schema.file_summary_by_instance
   where event_name like "%relaylog%" order by file_name;
 
-select * from performance_schema.file_summary_by_event_name
+select
+  EVENT_NAME,
+  if (count_read > 0, "MANY", "NONE") as COUNT_READ,
+  if (count_write > 0,"MANY", "NONE") as COUNT_WRITE,
+  if (sum_number_of_bytes_read > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_READ,
+  if (sum_number_of_bytes_write > 0, "MANY", "NONE") as SUM_NUMBER_OF_BYTES_WRITE
+  from performance_schema.file_summary_by_event_name
   where event_name like "%relaylog%" order by event_name;
 
-select event_name, count_star
+select
+  EVENT_NAME,
+  if (count_star > 0, "MANY", "NONE") as COUNT_STAR
   from performance_schema.events_waits_summary_global_by_event_name
   where event_name like "%MYSQL_RELAY_LOG%" order by event_name;
 
-- 
2.30.9