Skip to content

Commit

Permalink
Bug#28291258 FLUSH STATUS ADDS TWICE TO GLOBAL VALUES
Browse files Browse the repository at this point in the history
During FLUSH STATUS, the Performance Schema unnecessarily aggregates
session status to global status, causing double counts for NO_FLUSH
status variables.

To avoid this, the class PFS_host no longer aggregates to
global_status_vars for status reset operations such as FLUSH STATUS.
  • Loading branch information
Christopher Powers committed Dec 4, 2018
1 parent 75493ae commit a900a05
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 15 deletions.
21 changes: 21 additions & 0 deletions mysql-test/suite/perfschema/r/show_aggregate.result
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,27 @@ variable_name h1 h2 h3 delta host Expected
Handler_delete 6 0 0 6 6 OK
Handler_rollback 6 0 0 6 6 OK
================================================================================
TEST 8: FLUSH STATUS should clear account, host and user status
================================================================================

FLUSH STATUS;

SELECT * FROM status_by_account WHERE user LIKE 'user%' AND variable_name IN ('handler_delete');
USER HOST VARIABLE_NAME VARIABLE_VALUE
user1 localhost Handler_delete 0
user2 localhost Handler_delete 0
user3 localhost Handler_delete 0

SELECT * FROM status_by_host WHERE host IN ('localhost') AND variable_name IN ('handler_delete');
HOST VARIABLE_NAME VARIABLE_VALUE
localhost Handler_delete 0

SELECT * FROM status_by_user WHERE user LIKE 'user%' AND variable_name IN ('handler_delete');
USER VARIABLE_NAME VARIABLE_VALUE
user1 Handler_delete 0
user2 Handler_delete 0
user3 Handler_delete 0
================================================================================
CLEANUP
================================================================================
DROP TABLE test.t1;
Expand Down
37 changes: 33 additions & 4 deletions mysql-test/suite/perfschema/r/show_coverage.result
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,43 @@ SELECT variable_value FROM status_by_thread
WHERE variable_name = "bytes_received" and thread_id = @thread_id INTO @bytes_after;

# Expect bytes_before > bytes_after
SELECT @bytes_before > @bytes_after;
@bytes_before > @bytes_after
SELECT @bytes_before > @bytes_after AS 'Expect 1';
Expect 1
1

# Expect bytes_after is zero
SELECT @bytes_after;
@bytes_after
SELECT @bytes_after AS 'Expect 0';
Expect 0
0

# TEST 6
#
# Bug#28291258 FLUSH STATUS ADDS TWICE TO GLOBAL VALUES
#

# Default connection

# First connection
include/assert.inc [Global value requested from the first session must not change]

# Generate a slow query

SET long_query_time = 2;
SELECT SLEEP(4);
SLEEP(4)
0
SET long_query_time = @@global.long_query_time;

include/assert.inc [Global value requested from the first session after SLEEP() must increase by 1]
include/assert.inc [First session value must increase by 1]

# Default connection
include/assert.inc [Global value requested from the default session after DISCONNECT must remain the same]
include/assert.inc [Default session value must remain zero]

FLUSH STATUS;

include/assert.inc [Global value requested from the default session after FLUSH must remain the same]
include/assert.inc [Default session value after FLUSH must remain zero]
# CLEANUP
set @@global.show_compatibility_56 = @show_compatibility_56_save;
14 changes: 14 additions & 0 deletions mysql-test/suite/perfschema/t/show_aggregate.test
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,20 @@ SELECT variable_name, h1, h2, h3, delta, host, IF(host=delta,'OK','ERROR') Expec
FROM test.status_results
ORDER BY variable_name;


--echo ================================================================================
--echo TEST 8: FLUSH STATUS should clear account, host and user status
--echo ================================================================================
--echo
FLUSH STATUS;
--echo
SELECT * FROM status_by_account WHERE user LIKE 'user%' AND variable_name IN ('handler_delete');
--echo
SELECT * FROM status_by_host WHERE host IN ('localhost') AND variable_name IN ('handler_delete');
--echo
SELECT * FROM status_by_user WHERE user LIKE 'user%' AND variable_name IN ('handler_delete');


--echo ================================================================================
--echo CLEANUP
--echo ================================================================================
Expand Down
83 changes: 80 additions & 3 deletions mysql-test/suite/perfschema/t/show_coverage.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
--source include/have_perfschema.inc
--source include/not_embedded.inc
--source include/no_protocol.inc
--source include/count_sessions.inc

select @@global.show_compatibility_56 into @show_compatibility_56_save;
--echo
Expand Down Expand Up @@ -111,14 +112,90 @@ SELECT variable_value FROM status_by_thread
WHERE variable_name = "bytes_received" and thread_id = @thread_id INTO @bytes_after;
--echo
--echo # Expect bytes_before > bytes_after
SELECT @bytes_before > @bytes_after;
SELECT @bytes_before > @bytes_after AS 'Expect 1';
--echo
--echo # Expect bytes_after is zero
SELECT @bytes_after;
SELECT @bytes_after AS 'Expect 0';

disconnect con1;
--source include/wait_until_count_sessions.inc


--echo
--echo # TEST 6
--echo #
--echo # Bug#28291258 FLUSH STATUS ADDS TWICE TO GLOBAL VALUES
--echo #

--echo
--echo # Default connection
--let $initial_global_value = query_get_value(SHOW GLOBAL STATUS LIKE 'Slow_queries', Value, 1)

--source include/count_sessions.inc

--echo
--echo # First connection
--connect (con1, localhost, root,,)

## Global value requested from the first session must not change
--let $current_global_value = query_get_value(SHOW GLOBAL STATUS LIKE 'Slow_queries', Value, 1)
--let $assert_cond = $current_global_value - $initial_global_value = 0
--let $assert_text = Global value requested from the first session must not change
--source include/assert.inc

--echo
--echo # Generate a slow query
--echo
SET long_query_time = 2;
SELECT SLEEP(4);
SET long_query_time = @@global.long_query_time;
--echo

## Global value requested from the first session after SLEEP() must increase by 1
--let $current_global_value = query_get_value(SHOW GLOBAL STATUS LIKE 'Slow_queries', Value, 1)
--let $first_session_value = query_get_value(SHOW SESSION STATUS LIKE 'Slow_queries', Value, 1)
--let $assert_cond = $current_global_value - $initial_global_value = 1
--let $assert_text = Global value requested from the first session after SLEEP() must increase by 1
--source include/assert.inc
--let $assert_cond = $first_session_value = 1
--let $assert_text = First session value must increase by 1
--source include/assert.inc

--connection default
--disconnect con1
--source include/wait_until_count_sessions.inc

--echo
--echo # Default connection
--connection default

## Global value requested from the default session after DISCONNECT must remain the same
--let $current_global_value = query_get_value(SHOW GLOBAL STATUS LIKE 'Slow_queries', Value, 1)
--let $default_session_value = query_get_value(SHOW SESSION STATUS LIKE 'Slow_queries', Value, 1)
--let $assert_cond = $current_global_value - $initial_global_value = 1
--let $assert_text = Global value requested from the default session after DISCONNECT must remain the same
--source include/assert.inc

## Default session value must remain zero
--let $assert_cond = $default_session_value = 0
--let $assert_text = Default session value must remain zero
--source include/assert.inc

--echo
FLUSH STATUS;
--echo

## Global value requested from the default session after FLUSH must remain the same
--let $current_global_value = query_get_value(SHOW GLOBAL STATUS LIKE 'Slow_queries', Value, 1)
--let $default_session_value = query_get_value(SHOW SESSION STATUS LIKE 'Slow_queries', Value, 1)
--let $assert_cond = $current_global_value - $initial_global_value = 1
--let $assert_text = Global value requested from the default session after FLUSH must remain the same
--source include/assert.inc

## Default session value after FLUSH must remain zero
--let $assert_cond = $default_session_value = 0
--let $assert_text = Default session value after FLUSH must remain zero
--source include/assert.inc

--echo # CLEANUP
set @@global.show_compatibility_56 = @show_compatibility_56_save;

8 changes: 2 additions & 6 deletions storage/perfschema/pfs_host.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -274,11 +274,7 @@ void PFS_host::aggregate_memory(bool alive)

void PFS_host::aggregate_status()
{
/*
Aggregate STATUS_BY_HOST to:
- GLOBAL_STATUS
*/
m_status_stats.aggregate_to(& global_status_var);
/* No parent to aggregate to, clean the stats */
m_status_stats.reset();
}

Expand Down
2 changes: 0 additions & 2 deletions storage/perfschema/pfs_variable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1306,8 +1306,6 @@ void reset_pfs_status_stats()
reset_status_by_account();
reset_status_by_user();
reset_status_by_host();
/* Clear again, updated by previous aggregations. */
reset_global_status();
}

/** @} */

0 comments on commit a900a05

Please sign in to comment.