Bug #79775 Innodb doesn't update index stats when dropping virtual column in virtual index
Submitted: 25 Dec 2015 10:42 Modified: 5 Jan 2016 16:11
Reporter: Shaohua Wang Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:5.7.11 OS:Any
Assigned to: CPU Architecture:Any

[25 Dec 2015 10:42] Shaohua Wang
Description:
It seems we don't update index stats when dropping a virtual column in a virtual index.

How to repeat:
CREATE TABLE t (
a INT,
b INT,
c INT GENERATED ALWAYS AS(a+b),
d INT GENERATED ALWAYS AS(a+b+b),
KEY vidx (c, d)
)ENGINE=INNODB;

INSERT INTO t (a,b) VALUES (0, 0), (11, NULL);

select * from mysql.innodb_index_stats WHERE database_name = 'test' AND table_name = 't';
database_name	table_name	index_name	last_update	stat_name	stat_value	sample_size	stat_description
test	t	GEN_CLUST_INDEX	2015-12-25 13:37:47	n_diff_pfx01	2	1	DB_ROW_ID
test	t	GEN_CLUST_INDEX	2015-12-25 13:37:47	n_leaf_pages	1	NULL	Number of leaf pages in the index
test	t	GEN_CLUST_INDEX	2015-12-25 13:37:47	size	1	NULL	Number of pages in the index
test	t	vidx	2015-12-25 13:37:47	n_diff_pfx01	2	1	c
test	t	vidx	2015-12-25 13:37:47	n_diff_pfx02	2	1	c,d
test	t	vidx	2015-12-25 13:37:47	n_diff_pfx03	2	1	c,d,DB_ROW_ID
test	t	vidx	2015-12-25 13:37:47	n_leaf_pages	1	NULL	Number of leaf pages in the index
test	t	vidx	2015-12-25 13:37:47	size	1	NULL	Number of pages in the index

ALTER TABLE t DROP COLUMN c, ALGORITHM=INPLACE;

select * from mysql.innodb_index_stats WHERE database_name = 'test' AND table_name = 't';
database_name	table_name	index_name	last_update	stat_name	stat_value	sample_size	stat_description
test	t	GEN_CLUST_INDEX	2015-12-25 13:37:47	n_diff_pfx01	2	1	DB_ROW_ID
test	t	GEN_CLUST_INDEX	2015-12-25 13:37:47	n_leaf_pages	1	NULL	Number of leaf pages in the index
test	t	GEN_CLUST_INDEX	2015-12-25 13:37:47	size	1	NULL	Number of pages in the index
test	t	vidx	2015-12-25 13:37:47	n_diff_pfx01	2	1	c
test	t	vidx	2015-12-25 13:37:47	n_diff_pfx02	2	1	c,d
test	t	vidx	2015-12-25 13:37:47	n_diff_pfx03	2	1	c,d,DB_ROW_ID
test	t	vidx	2015-12-25 13:37:47	n_leaf_pages	1	NULL	Number of leaf pages in the index
test	t	vidx	2015-12-25 13:37:47	size	1	NULL	Number of pages in the index

Correct result for vidx should be like:
select * from mysql.innodb_index_stats WHERE database_name = 'test' AND table_name = 't';
database_name	table_name	index_name	last_update	stat_name	stat_value	sample_size	stat_description
test	t	GEN_CLUST_INDEX	2015-12-25 13:42:18	n_diff_pfx01	2	1	DB_ROW_ID
test	t	GEN_CLUST_INDEX	2015-12-25 13:42:18	n_leaf_pages	1	NULL	Number of leaf pages in the index
test	t	GEN_CLUST_INDEX	2015-12-25 13:42:18	size	1	NULL	Number of pages in the index
test	t	vidx	2015-12-25 13:42:18	n_diff_pfx01	2	1	d
test	t	vidx	2015-12-25 13:42:18	n_diff_pfx02	2	1	d,DB_ROW_ID
test	t	vidx	2015-12-25 13:42:18	n_leaf_pages	1	NULL	Number of leaf pages in the index
test	t	vidx	2015-12-25 13:42:18	size	1	NULL	Number of pages in the index
[5 Jan 2016 16:11] Daniel Price
Posted by developer:
 
Fixed as of the upcoming 5.7.11, 5.8.0 release, and here's the changelog entry:

InnoDB failed to update index statistics when adding or dropping a
virtual column.