Bug #92087 ER_TABLE_WITHOUT_PK can be improved for other cases
Submitted: 20 Aug 2018 14:17 Modified: 3 Oct 2018 1:52
Reporter: Narendra Singh Chauhan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Errors Severity:S3 (Non-critical)
Version:8.0.13 OS:Any
Assigned to: CPU Architecture:Any

[20 Aug 2018 14:17] Narendra Singh Chauhan
Description:
Message ER_TABLE_WITHOUT_PK is same for creation of non-primary key table AND for dropping of primary key from a PK enabled table, but it doesn't give clear information that user is wrongly trying to drop the PK or action is non-PK table.

Error message "ER_TABLE_WITHOUT_PK" is same for:
a) Creation of non-pk table.
b) Dropping of pk from a pk table.
c) Any modification on an existing non-pk table.

====
M1> create table tnopk3 (a int);
ERROR 3750 (HY000): Unable to create a table without PK, when system variable 'sql_require_primary_key' is set. Add a PK to the table or unset this variable to avoid this message. Note that tables without PK can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

M1> alter table tpk1 drop primary key;
ERROR 3750 (HY000): Unable to create a table without PK, when system variable 'sql_require_primary_key' is set. Add a PK to the table or unset this variable to avoid this message. Note that tables without PK can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

M1> alter table tnopk2 add column b int;
ERROR 3750 (HY000): Unable to create a table without PK, when system variable 'sql_require_primary_key' is set. Add a PK to the table or unset this variable to avoid this message. Note that tables without PK can cause performance problems in row-based replication, so please consult your DBA before changing this setting.
====

How to repeat:
Steps to repro:-
================
M1> select @@session.sql_require_primary_key;
+-----------------------------------+
| @@session.sql_require_primary_key |
+-----------------------------------+
|                                 0 |
+-----------------------------------+
1 row in set (0.00 sec)

M1> create table tpk1 (a int primary key);
Query OK, 0 rows affected (0.17 sec)

M1> create table tnopk1 (a int);
Query OK, 0 rows affected (0.07 sec)

M1> create table tnopk2 (a int unique key);
Query OK, 0 rows affected (0.16 sec)

M1> set @@global.sql_require_primary_key=1, @@session.sql_require_primary_key=1;
Query OK, 0 rows affected (0.00 sec)

M1> select @@session.sql_require_primary_key;
+-----------------------------------+
| @@session.sql_require_primary_key |
+-----------------------------------+
|                                 1 |
+-----------------------------------+
1 row in set (0.00 sec)

## Now check that message is same for all the below mentioned operations:-
M1> create table tnopk3 (a int);
ERROR 3750 (HY000): Unable to create a table without PK, when system variable 'sql_require_primary_key' is set. Add a PK to the table or unset this variable to avoid this message. Note that tables without PK can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

M1> alter table tpk1 drop primary key;
ERROR 3750 (HY000): Unable to create a table without PK, when system variable 'sql_require_primary_key' is set. Add a PK to the table or unset this variable to avoid this message. Note that tables without PK can cause performance problems in row-based replication, so please consult your DBA before changing this setting.

M1> alter table tnopk2 add column b int;
ERROR 3750 (HY000): Unable to create a table without PK, when system variable 'sql_require_primary_key' is set. Add a PK to the table or unset this variable to avoid this message. Note that tables without PK can cause performance problems in row-based replication, so please consult your DBA before changing this setting.
M1>
[7 Sep 2018 10:42] Dyre Tjeldvoll
Posted by developer:
 
Setting to DOCUMENTING to let the docs team have a look.
[3 Oct 2018 1:52] Paul DuBois
Posted by developer:
 
Fixed in 8.0.14.

Error messages relating to creating and dropping foreign keys were
improved to be more specific and informative.