I execute this SQL command twice and profile
select * from sbtest.sbtest2 limit 100; The first time profile result is
mysql> show profile for query 1; +----------------------+----------+ | Status | Duration | +----------------------+----------+ | starting | 0.000124 | | checking permissions | 0.000015 | *| Opening tables | 0.163660 |* | System lock | 0.000029 | | init | 0.000056 | | optimizing | 0.000017 | | statistics | 0.000073 | | preparing | 0.000228 | | executing | 0.000007 | | Sending data | 0.001327 | | end | 0.000019 | | query end | 0.000008 | | closing tables | 0.000013 | | freeing items | 0.004998 | | logging slow query | 0.000015 | | cleaning up | 0.000009 | +----------------------+----------+ 16 rows in set (0.00 sec) This is the first time6 ,so it needs to "open tables" from hard disk, and above is the second time profile.
mysql> show profile for query 5; +----------------------+----------+ | Status | Duration | +----------------------+----------+ | starting | 0.000072 | | checking permissions | 0.000012 | *| Opening tables | 0.000026 |* | System lock | 0.000013 | | init | 0.000025 | | optimizing | 0.000006 | | statistics | 0.000016 | | preparing | 0.000013 | | executing | 0.000003 | | Sending data | 0.000296 | | end | 0.000008 | | query end | 0.000006 | | closing tables | 0.000010 | | freeing items | 0.000018 | | logging slow query | 0.000003 | | cleaning up | 0.000004 | +----------------------+----------+ 16 rows in set (0.00 sec) The second time "open tables time" is 0.00026, which is much faster than the first time "open tables time" 0.163660.
What I don't understand is when I use innodb buffer pool and my open_table_cache is using, why I still need to open tables from hard disk ?