MySQL Forums
Forum List  »  General

Re: fragmentation in innodb index
Posted by: Rick James
Date: August 26, 2014 04:38PM

There is fragmentation. But it is rarely a big issue. It is also not possible to clean up the index fragmentation in all cases -- some ALTERs clean up, some do not; some indexes can never be cleaned up. (I forget the details.)

How to see the fragmentation? Well, there are two ways...

Percona/MariaDB
SELECT  INDEX_NAME as Index_Name,
                    IF(ROWS_READ IS NULL, 'Unused?',
                        IF(ROWS_READ > 2e9, 'Overflow', ROWS_READ)) as Rows_Read
                FROM (
                    SELECT DISTINCT TABLE_SCHEMA, INDEX_NAME
                        FROM information_schema.STATISTICS
                     ) i
                LEFT JOIN information_schema.INDEX_STATISTICS s
                         ON i.TABLE_SCHEMA = s.TABLE_SCHEMA
                        AND i.TABLE_NAME = s.TABLE_NAME
                        AND i.INDEX_NAME = s.INDEX_NAME
                WHERE i.TABLE_SCHEMA = ?
                  AND i.TABLE_NAME = ?
                ORDER BY IF(i.INDEX_NAME = 'PRIMARY', 0, 1), i.INDEX_NAME

Oracle 5.6:
SELECT  last_update,
                    @n_rows := n_rows AS n_rows,
                    CONCAT_WS('|', n_rows, clustered_index_size) AS Clustered,
                    CONCAT_WS('|', n_rows, sum_of_other_index_sizes) AS Secondary
            FROM mysql.innodb_table_stats
            WHERE ( database_name = ? AND table_name = ? )
              OR    database_name = LOWER(?) AND table_name = LOWER(?)
(The "LOWER" code is to make the query work on Windows as well as *nix.)

Options: ReplyQuote


Subject
Written By
Posted
Re: fragmentation in innodb index
August 26, 2014 04:38PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.