Comments on: Queries for Finding Poorly-Designed MySQL Schemas and How to Fix Them https://www.percona.com/blog/queries-for-finding-poorly-designed-mysql-schemas-and-how-to-fix-them/ Wed, 01 Mar 2023 15:29:07 +0000 hourly 1 https://wordpress.org/?v=6.5.2 By: gggeek https://www.percona.com/blog/queries-for-finding-poorly-designed-mysql-schemas-and-how-to-fix-them/#comment-10974022 Wed, 01 Mar 2023 15:29:07 +0000 https://www.percona.com/blog/?p=82936#comment-10974022 It would probably be a good idea to specify which versions of MySQL and MariaDB support the above queries, and/or if they enabling of some specific features (is per. schema always available and populated?)

As an example, sys.schema_unused_indexes is only available in MariaDb starting from 10.6…

]]>
By: David Stokes https://www.percona.com/blog/queries-for-finding-poorly-designed-mysql-schemas-and-how-to-fix-them/#comment-10973780 Wed, 05 Oct 2022 13:41:48 +0000 https://www.percona.com/blog/?p=82936#comment-10973780 In reply to Hector.

I recommend making an index invisible for a fair amount of time before removing it. As we explain in the stream there is always a chance that the index is used on something that runs rarely such as a quarterly report. And note down the output from SHOW INDEX FROM <index-name> someplace just incase.

]]>
By: Bill Karwin https://www.percona.com/blog/queries-for-finding-poorly-designed-mysql-schemas-and-how-to-fix-them/#comment-10973777 Tue, 04 Oct 2022 15:39:52 +0000 https://www.percona.com/blog/?p=82936#comment-10973777 These may be “code smells” but we should always use our judgment because there are legitimate cases that are an exception to the rule.

It’s not unusual in my experience that some tables have a lot of indexes, sometimes these are bulky and can add up to even greater than 100% of the size of the table.

Duplicate indexes and unused indexes is a bit complicated if you consider unique keys. A unique key may be needed even if it counts as a duplicate or an unused index by your queries.

On the unused indexes query, keep in mind this is reset if MySQL Server restarts. Some indexes are used infrequently, for example for monthly reports. So they could be identified as “unused” even though they are needed. One should keep notes in a wiki or something to document why each index was created, and identify the code and query that needs them.

I’d add to the list of schema design code smells the use of FLOAT or DOUBLE data type. Often it should be DECIMAL instead, especially for storing currency values.

]]>
By: Hector https://www.percona.com/blog/queries-for-finding-poorly-designed-mysql-schemas-and-how-to-fix-them/#comment-10973776 Tue, 04 Oct 2022 14:25:13 +0000 https://www.percona.com/blog/?p=82936#comment-10973776 Really nice post, only to comment: with unused indexes you will need take a multiple reads of this table before that you decide delete an index.

]]>