Re:Things that don’t work well with MySQL’s FOREIGN KEY impl...
by Dachande663 on Monday May 01, 2023 @11:36AM
(#35774309)
I am probably in the minority and would get shouted at by a DBA of yore, but I use foreign keys for referential integrity and… that’s it. We use soft deletes for almost all rows, so the whole cascading side is less relevant for us than getting an error in test or even production because a missing relation has been used. Combined with using non-integer primary keys, it’s godsend.
[ Parent
| on HN ]
Re:Things that don’t work well with MySQL’s FOREIGN KEY impl...
by Svip on Monday May 01, 2023 @11:40AM
(#35774395)
I remember working on a large database without foreign keys for a while. When asked why did not use foreign keys, I was told that they didn't like the opaqueness of CASCADE, which I could understand. I guess I did not give it much thought afterwards, until I later ended up in a shop, where the database did include foreign keys, but only with RESTRICT. It was eye-opening how useful foreign keys were, when they were just integrity checks.
Re:Things that don’t work well with MySQL’s FOREIGN KEY impl...
by shlomi-noach on Monday May 01, 2023 @11:54AM
(#35774632)
OP. I agree! RESTRICT is by far the best rule to use, and makes the most sense.
Perhaps to balance my post a bit, and for what it's worth, I don't advocate for "don't ever use foreign keys" as a blanket statement. My experience was one where using foreign keys did not make sense. I do wish they were more operationally friendly.
Re:Things that don’t work well with MySQL’s FOREIGN KEY impl...
by _a_a_a_ on Monday May 01, 2023 @01:14PM
(#35775924)
what does 'more operationally friendly' mean? TIA
Re:Things that don’t work well with MySQL’s FOREIGN KEY impl...
by shlomi-noach on Monday May 01, 2023 @01:20PM
(#35776043)
Like the issues I mention in my post: modifying the data type of a column that is used by a foreign key; otherwise the fact you can't run Online DDL on a table that participates in foreign key relationship ; that INSTANT does not support (yet?) adding/removing foreign key constraints ; that cascaded writes are not written the the binary logs.
These are all things that the casual developer doesn't deal with when designing a schema and writes an app that INSERTs/DELETEs/UPDATEs to tables with foreign keys. But once there's a need for a change; once you wire 3rd party tools onto your database, that's where the operations hit a wall.
Re:Things that don’t work well with MySQL’s FOREIGN KEY impl...
by _a_a_a_ on Monday May 01, 2023 @01:31PM
(#35776224)
I didn't realise grep_it and you (shlomi-noach) were the same, apologies
Re:Things that don’t work well with MySQL’s FOREIGN KEY impl...
by shlomi-noach on Monday May 01, 2023 @01:37PM
(#35776317)
We are not the same. My mistake for writing "OP".
Re:Things that don’t work well with MySQL’s FOREIGN KEY impl...
by shlomi-noach on Monday May 01, 2023 @01:36PM
(#35776291)
Whoops. I wrote "OP" when I really meant "Post author". I'm a bit rusty with HN notations.
Re:Things that don’t work well with MySQL’s FOREIGN KEY impl...
by tomnipotent on Wednesday May 03, 2023 @04:44AM
(#35799685)
eBay released a blog/paper over two decades ago talking about how they achieved scale in part by removing FK constraints from their database. It was vogue for the next decade when SAN/DAS IOPS were ~1-3k, and FK constraints could lead to more disk writes (like Postgres multixact).
Re:Things that don’t work well with MySQL’s FOREIGN KEY impl...
by Phelinofist on Monday May 01, 2023 @01:42PM
(#35776392)
What's wrong with non-integer primary keys?
Re:Things that don’t work well with MySQL’s FOREIGN KEY impl...
by takethisdownplz on Monday May 01, 2023 @02:00PM
(#35776664)
besides performance for using something that is not often tested by devs working in performance, bad support for locale collating and open you for bugs such as indexing on email but allowing application to store both upper and lower case etc.
Re:Things that don’t work well with MySQL’s FOREIGN KEY impl...
by evilspammer on Monday May 01, 2023 @03:08PM
(#35777598)
I would expect they're referring to UUIDs or something
Re:Things that don’t work well with MySQL’s FOREIGN KEY impl...
by tomnipotent on Wednesday May 03, 2023 @04:52AM
(#35799730)
You can pack fewer of them into a page, which means more disk IO for things like index scans.