diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index d5f3945fb6b..29af76ed8df 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -291,7 +291,7 @@ Level Code Message Note 1050 Table 't1' already exists show status like "Opened_tables"; Variable_name Value -Opened_tables 2 +Opened_tables 1 select * from t1; a b 1 1 diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index 062fa0a92af..3a55dd5aeb4 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -1965,5 +1965,20 @@ event_object_table trigger_name # Clean-up. drop database mysqltest; # +# Test for bug #16869534 - "QUERYING SUBSET OF COLUMNS DOESN'T USE TABLE +# CACHE; OPENED_TABLES INCREASES" +# +SELECT * FROM INFORMATION_SCHEMA.TABLES; +SELECT VARIABLE_VALUE INTO @val1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE +VARIABLE_NAME LIKE 'Opened_tables'; +SELECT ENGINE FROM INFORMATION_SCHEMA.TABLES; +# The below SELECT query should give same output as above SELECT query. +SELECT VARIABLE_VALUE INTO @val2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE +VARIABLE_NAME LIKE 'Opened_tables'; +# The below select should return '1' +SELECT @val1 = @val2; +@val1 = @val2 +1 +# # End of 5.5 tests # diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index e6dc989bdb9..42897735014 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -1782,6 +1782,23 @@ disconnect con12828477_3; --echo # Clean-up. drop database mysqltest; +--echo # +--echo # Test for bug #16869534 - "QUERYING SUBSET OF COLUMNS DOESN'T USE TABLE +--echo # CACHE; OPENED_TABLES INCREASES" +--echo # +--disable_result_log +SELECT * FROM INFORMATION_SCHEMA.TABLES; +--enable_result_log +SELECT VARIABLE_VALUE INTO @val1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE + VARIABLE_NAME LIKE 'Opened_tables'; +--disable_result_log +SELECT ENGINE FROM INFORMATION_SCHEMA.TABLES; +--enable_result_log +--echo # The below SELECT query should give same output as above SELECT query. +SELECT VARIABLE_VALUE INTO @val2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE + VARIABLE_NAME LIKE 'Opened_tables'; +--echo # The below select should return '1' +SELECT @val1 = @val2; --echo # --echo # End of 5.5 tests diff --git a/sql/table.cc b/sql/table.cc index b24e03fbe1a..c17ee39fe9e 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2014, 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 @@ -2138,7 +2138,9 @@ partititon_err: outparam->no_replicate= outparam->file && test(outparam->file->ha_table_flags() & HA_HAS_OWN_BINLOGGING); - thd->status_var.opened_tables++; + /* Increment the opened_tables counter, only when open flags set. */ + if (db_stat) + thd->status_var.opened_tables++; DBUG_RETURN (0);