Bug #117623 The implicit primary key in DD has the wrong type set

Submitted: 5 Mar 2025 12:46 Modified: 6 Mar 2025 6:42
Reporter: Zihao Wang (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Storage Engines Severity:S3 (Non-critical)
Version:8.0, 8.0.41 OS:Any
Assigned to: CPU Architecture:Any

[5 Mar 2025 12:46] Zihao Wang
Description:
If user does not explicitly declare a primary key when creating a table, InnoDB will generate an implicit primary key using row_id for the table.

The ipk should have the same keytype as explicit primary key, that is KEYTYPE_PRIMARY. But in DD, the `type` of ipk is set to KEYTYPE_UNIQUE.

enum keytype {
  KEYTYPE_PRIMARY,
  KEYTYPE_UNIQUE,
  KEYTYPE_MULTIPLE,
  KEYTYPE_FULLTEXT,
  KEYTYPE_SPATIAL,
  KEYTYPE_FOREIGN
};

How to repeat:
Using DEBUG mode and run SQLs below:

1. create table test.no_pk(a int);

2. SET SESSION debug='+d,skip_dd_table_access_check';

3. select name, id from mysql.tables where name like '%no_pk%';

4. select name, type from mysql.indexes where table_id=xxx;

You will get result like:
+---------+--------+
| name    | type   |
+---------+--------+
| PRIMARY | UNIQUE |
+---------+--------+

For an explicit primary key, the result will be:
+---------+--------+
| name    | type   |
+---------+--------+
| PRIMARY | PRIMARY |
+---------+--------+

===

Another way to check `type` of ipk is using ibd2sdi, you will see that the `type` value in SDI is also wrong.
[6 Mar 2025 6:42] MySQL Verification Team
Hello Zihao Wang,

Thank you for the report and feedback.

regards,
Umesh

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

Page generated in 0.052 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.