Commit aed8369e authored by V S Murthy Sidagam's avatar V S Murthy Sidagam

Bug #16869534 QUERYING SUBSET OF COLUMNS DOESN'T USE TABLE CACHE; OPENED_TABLES I

Description: When querying a subset of columns from the information_schema.TABLES

Analysis: When information about tables is collected for statements like
"SELECT ENGINE FROM I_S.TABLES" we do not perform full-blown table opens
in SE, instead we only use information from table shares from the Table
Definition Cache or .FRMs. Still in order to simplify I_S implementation
mock TABLE objects are created from TABLE_SHARE during this process.
This is done by calling open_table_from_share() function with special
arguments. Since this function always increments "Opened_tables" counter,
calls to it can be mistakingly interpreted as full-blown table opens in SE.

Note that claim that "'SELECT ENGINE FROM I_S.TABLES' statement doesn't
use Table Cache" is nevertheless factually correct. But it misses the
point, since such statements a) don't use full-blown TABLE objects and
therefore don't do table opens b) still use Table Definition Cache.

Fix: We are now incrementing the counter when db_stat(i.e open flags for ha_open(

we have considered an optimization which would use TABLE objects from
Table Cache when available instead of constructing mock TABLE objects,
but found it too intrusive for stable releases.
parent 5a587b6d
......@@ -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
......
......@@ -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
#
......@@ -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
......
/*
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 @@ int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment