Bug #119911 Documentation is inconsistent
Submitted: 15 Feb 4:25 Modified: 20 Feb 6:36
Reporter: Igor Korot Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Documentation Severity:S2 (Serious)
Version:8.4 OS:Any
Assigned to: CPU Architecture:Any

[15 Feb 4:25] Igor Korot
Description:
On the page https://dev.mysql.com/doc/refman/8.4/en/create-table.html, it states:

[quote]
he name of a PRIMARY KEY is always PRIMARY, which thus cannot be used as the name for any other kind of index. 
[/quote]

However the syntax for creating the primary key is, according to the same page:

[quote]
[CONSTRAINT [symbol]] PRIMARY KEY
      [index_type] (key_part,...)
      [index_option] ...
[/quote]

where the CPNSTRAINT clause is documented as:

[quote]
The CONSTRAINT symbol clause may be given to name a constraint. If the clause is not given, or a symbol is not included following the CONSTRAINT keyword, MySQL automatically generates a constraint name, with the exception noted below
[/quote]

So if I create PRIMARY KEY as:

CONSTRAINT mytable_pk PRIMARY KEY(id1, id2)

what would be happenning?

Does constraint name will be honored? Or it will be called PRIMARY and the name will be disregarded? 

It would be nice if this can be clarified somewhere...

How to repeat:
N/A
[15 Feb 4:26] Igor Korot
I don't know if this is something new or the same can be said for the previous versions of MySQL.
[17 Feb 8:25] Daniël van Eeden
With 9.6 the syntax is accepted, but then silently ignored.

mysql-9.6.0 [test]> CREATE TABLE t1 (id INT NOT NULL, CONSTRAINT mypk PRIMARY KEY(id));
Query OK, 0 rows affected (0.005 sec)

mysql-9.6.0 [test]> SHOW CREATE TABLE t1\G
*************************** 1. row ***************************
       Table: t1
Create Table: CREATE TABLE `t1` (
  `id` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_as_cs
1 row in set (0.002 sec)
[17 Feb 13:21] MySQL Verification Team
Looks like a duplicate of:

https://bugs.mysql.com/bug.php?id=1956
https://bugs.mysql.com/bug.php?id=92242

which I once mentioned in:

https://bugs.mysql.com/bug.php?id=47771
[20 Feb 3:44] Igor Korot
In reply to Daniel (apologies for misspelling):

This ticket is made against the documentation.

Also, if the behavior is changed - its better be documented what version it is fixed in to exclude the confusion for the user.

Thank you.
[20 Feb 3:47] Igor Korot
To MySQL Verification Team:

It is not a dup.

I made it against the documentation, while those 2 you mentioned are against the behavior.
[20 Feb 6:36] Igor Korot
To Daniel (in addition):

Why not give a warning that naming PK is not supported?

Users will be really confused...
[20 Feb 7:49] Daniël van Eeden
Hi Igor,

I just wanted to add some information about what actually happens on the latest release so this can be easily compared with what is in the docs.

Something that's silently ignore, without even a note or warning is bad.

And I think fixing the documentation and eventually the product is needed.

Note that I'm not working for Oracle, I'm just a community person.