Bug #104770 schema_redundant_indexes suggesting dropping the PK

Submitted: 30 Aug 2021 18:21 Modified: 31 Aug 2021 6:01
Reporter: Vinicius Malvestio Grippa (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: SYS Schema Severity:S3 (Non-critical)
Version:5.7, 8.0, 8.4, 9.6.0 OS:Any
Assigned to: CPU Architecture:Any

[30 Aug 2021 18:21] Vinicius Malvestio Grippa
Description:
It seems a bit unwise to recommend dropping the PK in the following case. I believe that in situations like this both indexes (PRIMARY KEY and UNIQUE) should be kept and no rows should be returned.

How to repeat:
# Create table

CREATE TABLE test.`fund_perf_info` (
`FUND_ID` varchar(20) not null,
`FUND_UNIVERSE` varchar(10) NOT NULL,
PRIMARY KEY (`FUND_ID`,`FUND_UNIVERSE`),
UNIQUE KEY `FUND_ID` (`FUND_ID`)
);

# SQL statement
select * from sys.schema_redundant_indexes where table_schema='test' and table_name='fund_perf_info'\G

# Output
*************************** 1. row ***************************
              table_schema: test
                table_name: fund_perf_info
      redundant_index_name: PRIMARY
   redundant_index_columns: FUND_ID,FUND_UNIVERSE
redundant_index_non_unique: 0
       dominant_index_name: FUND_ID
    dominant_index_columns: FUND_ID
 dominant_index_non_unique: 0
            subpart_exists: 0
            sql_drop_index: ALTER TABLE `test`.`fund_perf_info` DROP INDEX `PRIMARY`
1 row in set (0.01 sec)

Suggested fix:
To avoid this suggestion, I recommend changing the SQL statement. 

Something like adding the following condition:

...
WHERE
  redundant_keys.index_name != dominant_keys.index_name 
  AND redundant_keys.index_name NOT LIKE 'PRIMARY'
...
[31 Aug 2021 6:01] MySQL Verification Team
Hello Vinicius,

Thank you for report and feedback.

regards,
Umesh
[29 Sep 2025 13:25] Shane Bester
Still affects recent 8.0.43, 8.4.6, and 9.5.0

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.039 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
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.