[MDEV-28412] Introduce sql_require_primary_key Created: 2022-04-25 Updated: 2022-08-08 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Configuration, Replication, Server |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor |
| Reporter: | acsfer | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 6 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||
| Description |
|
MySQL 8 introduced sql_require_primary_key. Similar option (global option, affecting all Engines, unlike innodb_force_primary_key) should be available on MariaDB too. MariaDB 10.1 introduced the innodb_force_primary_key variable, which forces InnoDB tables to have a primary key. Unfortunately, this doesn’t solve the replication problem if we use other storage engines. sql_require_primary_key from MySQL8 simply disallows to create tables without a primary key, or drop a primary key from an existing table. https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_sql_require_primary_key |
| Comments |
| Comment by Sergei Golubchik [ 2022-05-05 ] |
|
https://mariadb.com/kb/en/innodb-system-variables/#innodb_force_primary_key ? |
| Comment by acsfer [ 2022-05-05 ] |
|
Hi Sergei, did you read my description? |
| Comment by Sergei Golubchik [ 2022-05-06 ] |
|
Yes, I did. It's true that innodb_force_primary_key only works for InnoDB. My question was that perhaps innodb_force_primary_key, even if it is not completely universal, still solves your specific problem? In case you only actually needed it for InnoDB in your application, I cannot know that. It seems that you've edited the description to emphasize that you, indeed, need it for other storage engines. That answers my question, thanks. |
| Comment by Daniel Lenski [ 2022-08-04 ] |
|
serg, one substantial problem with innodb_force_primary_key is that, according to the docs, it is Global scope only: https://mariadb.com/kb/en/innodb-system-variables/#innodb_force_primary_key That means, I believe, that it should be impossible for one connection/thread to temporarily disable the enforcement of primary keys. On the other hand sql_require_primary_key can be set at either Global or Session scope, so it can be temporarily disabled by e.g. a management connection which needs to do so: https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_sql_require_primary_key |
| Comment by Sergei Golubchik [ 2022-08-08 ] |
|
also, there are requests for MariaDB to add a hidden pk automatically (MDEV-21181 and MDEV-24001). Perhaps there should be an enum system variable with values, like, "error without a pk", "auto-add pk", "do nothing" ? |