[MDEV-7085] innodb index stats miscounted index fields Created: 2014-11-12  Updated: 2014-11-13  Due: 2014-12-12  Resolved: 2014-11-13

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - XtraDB
Affects Version/s: 5.5.40
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Daniel Black Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Environment:

centos6-amd64



 Description   

idx_obs_daily_1 has 3 fields not 4.

MariaDB [weather]> select * from information_schema.INNODB_INDEX_STATS where table_schema='weather' and table_name='obs_daily';
+--------------+------------+-----------------+--------+---------------------+-------------------+------------------+
| table_schema | table_name | index_name      | fields | rows_per_key        | index_total_pages | index_leaf_pages |
+--------------+------------+-----------------+--------+---------------------+-------------------+------------------+
| weather      | obs_daily  | PRIMARY         |      1 | 1                   |            212672 |           185818 |
| weather      | obs_daily  | idx_obs_daily_2 |      2 | 3178, 1             |             28032 |            24434 |
| weather      | obs_daily  | idx_obs_daily_1 |      4 | 2160489, 1271, 0, 0 |             46784 |            40750 |

| obs_daily | CREATE TABLE `obs_daily` (
  `iId` int(11) NOT NULL AUTO_INCREMENT, 
  `sLocType` varchar(10) NOT NULL DEFAULT '',  
  `sLocCode` varchar(30) NOT NULL DEFAULT '',  
  `dtDate` date NOT NULL DEFAULT '0000-00-00',  
....
  PRIMARY KEY (`iId`),
  UNIQUE KEY `idx_obs_daily_1` (`sLocType`,`sLocCode`,`dtDate`),
  KEY `idx_obs_daily_2` (`dtDate`)
) ENGINE=InnoDB AUTO_INCREMENT=23562482 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC |



 Comments   
Comment by Arjen Lentz [ 2014-11-12 ]

Of course we know that in InnoDB, non-PK indexes also contain the value of the primary key as the last field of the index, except this is internal and hidden from the visible table structure.
So the output is, while correct in terms of what's stored, confusing.

To "unconfuse" it, the INNODB_INDEX_STATS output could just colcount-1 for any non-PK index.
Pretty simple, but I have to say I'm ambivalent about whether it's worthwhile - it's good to have this documented explicitly of course, to at least have a reference point in case of confusion

Comment by Daniel Black [ 2014-11-12 ]

 
table_schema	table_name	index_name	fields	rows_per_key	index_total_pages	index_leaf_pages
weather	obs_daily	PRIMARY	1	1	206976	180899
weather	obs_daily	idx_obs_daily_1	3	2884335, 3533, 1	67328	58696
weather	obs_daily	idx_obs_daily_2	2	8472, 1	28032	24442

Other database servers like above showed 3 for the same schema

Comment by Sergei Golubchik [ 2014-11-12 ]

I cannot repeat this, I'm getting the same result as on your "other database servers".
Can you create a repeatable test case for this?

Comment by Elena Stepanova [ 2014-11-12 ]

I cannot either, although I can get 3 fields for idx_obs_daily_2 if I try hard enough:

MariaDB [test]> CREATE TABLE `obs_daily` (      `sLocType` varchar(10) NOT NULL DEFAULT '',     `sLocCode` varchar(30) NOT NULL DEFAULT '',     `dtDate` date NOT NULL DEFAULT '0000-00-00',    UNIQUE KEY `idx_obs_daily_1` (`sLocType`,`sLocCode`,`dtDate`),   KEY `idx_obs_daily_2` (`dtDate`) ) ENGINE=InnoDB AUTO_INCREMENT=23562482 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
Query OK, 0 rows affected (0.99 sec)
 
MariaDB [test]> select * from information_schema.innodb_index_stats;
+--------------+------------+-----------------+--------+--------------+-------------------+------------------+
| table_schema | table_name | index_name      | fields | rows_per_key | index_total_pages | index_leaf_pages |
+--------------+------------+-----------------+--------+--------------+-------------------+------------------+
| test         | obs_daily  | idx_obs_daily_1 |      3 | 0, 0, 0      |                 1 |                1 |
| test         | obs_daily  | idx_obs_daily_2 |      3 | 0, 0, 0      |                 1 |                1 |
+--------------+------------+-----------------+--------+--------------+-------------------+------------------+

In any case, this is documented explicitly in Percona docs:
http://www.percona.com/doc/percona-server/5.5/diagnostics/innodb_stats.html

fields – How many fields the index key has. (it is internal structure of InnoDB, it may be larger than the CREATE TABLE).

Comment by Elena Stepanova [ 2014-11-12 ]

Given that it's "design", explicitly documented by Percona, and that the table doesn't even exist in XtraDB 5.6 / MariaDB 10.0, I suppose the reasonable course of action is not to do anything about it. Does everyone agree?

Comment by Daniel Black [ 2014-11-12 ]

fair call.

Comment by Elena Stepanova [ 2014-11-13 ]

Is somebody disagrees, please comment to re-open.

Generated at Thu Feb 08 07:16:53 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.