Bug #47116 Running SHOW VARIABLES/STATUS increments global counters
Submitted: 4 Sep 2009 0:41 Modified: 14 Sep 2009 20:40
Reporter: Nuno Tavares Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Information schema Severity:S2 (Serious)
Version:5.1.37, 5.0, 5.1, next bzr OS:Linux (RHEL/CentOS 5.x)
Assigned to: CPU Architecture:Any

[4 Sep 2009 0:41] Nuno Tavares
Description:
Very similar to Bug #10210, I started to check SHOW VARIABLES, but it seems SHOW STATUS is still touching global counters.

This makes statistics a bit unreliable, especially if you have GUI tools
or programs like mysqltop running that run lots of meta-data queries, since you can't trust results from this.

How to repeat:
mysql> show global status like 'cr%';
+-------------------------+-------+
| Variable_name           | Value |
+-------------------------+-------+
| Created_tmp_disk_tables | 0     | 
| Created_tmp_files       | 0     | 
| Created_tmp_tables      | 21    | 
+-------------------------+-------+
3 rows in set (0.00 sec)

mysql> show global status like 'cr%';
+-------------------------+-------+
| Variable_name           | Value |
+-------------------------+-------+
| Created_tmp_disk_tables | 0     | 
| Created_tmp_files       | 0     | 
| Created_tmp_tables      | 22    | 
+-------------------------+-------+
3 rows in set (0.00 sec)

And also:

mysql> show global status like 'cr%';
+-------------------------+-------+
| Variable_name           | Value |
+-------------------------+-------+
| Created_tmp_disk_tables | 0     | 
| Created_tmp_files       | 0     | 
| Created_tmp_tables      | 28    | 
+-------------------------+-------+
3 rows in set (0.01 sec)

mysql> show variables like 'cr%';
Empty set (0.00 sec)

mysql> show global status like 'cr%';
+-------------------------+-------+
| Variable_name           | Value |
+-------------------------+-------+
| Created_tmp_disk_tables | 0     | 
| Created_tmp_files       | 0     | 
| Created_tmp_tables      | 30    | 
+-------------------------+-------+
3 rows in set (0.00 sec)

Also, please check SHOW GLOBAL VARIABLES. It seems Bug #10210 was fixed for SESSION only, as GLOBAL STATUS is still affected by ifself.

Suggested fix:
SHOW commands should not increment the status counters, since it can skew the results of profiling.
[4 Sep 2009 5:33] Sveta Smirnova
Thank you for the report.

Veirified as described. Also show global status like 'hand%'; is affected.
[14 Sep 2009 20:40] Omer Barnir
triage: This is expected behavior1 - see note in bug#10210 "[20 Jun 2006 12:25] Michael Widenius" - regarding the increment of global variables and the use of temp tables with show command