Bug #95894 DROP PRIMARY KEY on UNIQUE PRIMARY KEY does not update information_schema.column
Submitted: 20 Jun 2019 10:17 Modified: 20 Jun 2019 10:32
Reporter: Manuel Rigger Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Information schema Severity:S3 (Non-critical)
Version:8.0.16, 5.7.26, 5.6.44 OS:Ubuntu
Assigned to: CPU Architecture:x86

[20 Jun 2019 10:17] Manuel Rigger
Description:
When dropping a PRIMARY KEY, information_schema.columns is not updated if the PRIMARY KEY is also declared as UNIQUE.

How to repeat:
CREATE TABLE t0(c0 INT PRIMARY KEY UNIQUE);
ALTER TABLE t0 DROP PRIMARY KEY;
SELECT COLUMN_KEY, COLUMN_NAME from information_schema.columns WHERE TABLE_NAME = 't0'; -- unexpected: c0 is still shown as PRI
ALTER TABLE t0 DROP PRIMARY KEY; -- ERROR 1091 (42000): Can't DROP 'PRIMARY'; check that column/key exists

The SELECT displays the following:

+------------+-------------+
| COLUMN_KEY | COLUMN_NAME |
+------------+-------------+
| PRI        | c1          |
+------------+-------------+

This seems to suggest that the primary key was not removed. However, the subsequent DROP PRIMARY KEY results in an error, which indicates that the PRIMARY KEY had actually been removed.

When not declaring the PRIMARY KEY as UNIQUE, the SELECT works as expected:

CREATE TABLE t0(c0 INT PRIMARY KEY);
ALTER TABLE t0 DROP PRIMARY KEY;
SELECT COLUMN_KEY, COLUMN_NAME from information_schema.columns WHERE TABLE_NAME = 't0';

+------------+-------------+
| COLUMN_KEY | COLUMN_NAME |
+------------+-------------+
|            | c0          |
+------------+-------------+
[20 Jun 2019 10:32] MySQL Verification Team
Hello Manuel Rigger,

Thank you for the report.

regards,
Umesh