One of the new features in MySQL 5.6 is persistent table
statistics. The word “persistent” makes you think that table
statistics will be very stable from now on.
This is generally true, but there are some exceptions. There is a
particular case where InnoDB statistics may change with no
warning, even when there is no user activity on the server.
Consider the following pattern (which nearly all bug or feature
testcases follow):
CREATE TABLE t1 (...) ENGINE=INNODB;
INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
EXPLAIN SELECT * FROM t1;
EXPLAIN SELECT * FROM t1;
With MySQL 5.6, the following is possible
- the first EXPLAIN will show that the optimizer expects table
t1 to have 6 rows
- the second EXPLAIN will show that the optimizer expects table
t1 to have 5 rows
For me, this was a big surprise. After all, table t1 never had 6
rows. If there was some rounding which rounded up 5 to 6, why …
[Read more]