Re:"At GitHub we do not use foreign keys, ever, anywhere" (2...
by postalrat on Tuesday January 23, 2024 @08:56AM
(#39103292)
You assume you will deal with mistakes later and that will be more costly than the effort implement foreign keys. That's a pretty big assumption that has been proven to be false in many cases.
Re:"At GitHub we do not use foreign keys, ever, anywhere" (2...
by gregjor on Tuesday January 23, 2024 @09:42AM
(#39103914)
Implementing foreign key constraints requires next to no effort -- a single declaration in SQL. You need to think through the schema and the relationships but you have to do that in any case.
"Proven to be false in many cases" with not a single example is just an opinion without evidence. The benefit of foreign keys has decades of actual documentation.
Re:"At GitHub we do not use foreign keys, ever, anywhere" (2...
by postalrat on Tuesday January 23, 2024 @12:27PM
(#39106472)
I'm going to assume you didn't read the linked thread because right there are examples of both.
Re:"At GitHub we do not use foreign keys, ever, anywhere" (2...
by gregjor on Wednesday January 24, 2024 @08:27AM
(#39117037)
Assume what you want. Since I specifically mentioned migrations as a not so good reason to avoid foreign keys, in my opinion, I would think it's obvious I read the original article.
Re:"At GitHub we do not use foreign keys, ever, anywhere" (2...
by lofaszvanitt on Wednesday January 24, 2024 @06:20AM
(#39116022)
Sanely created schema does not have these kinds of problems ;). Plus FKs are a performance impact.
Re:"At GitHub we do not use foreign keys, ever, anywhere" (2...
by gregjor on Thursday January 25, 2024 @10:39AM
(#39130658)
The most trivial schema with a parent-child relationship either has foreign key constraints or update anomalies. There's no way to "sanely create" a normalized schema that doesn't have such relationships.
Performance impact may or may not matter. You don't discard valuable techniques and decades of experience for a "might happen." You measure and identify actual performance and adjust with facts. All indexes have both a performance benefit and a performance cost, incurred in the first case when selecting, and in the second case when updating. The performance benefit and cost of foreign keys comes from the index created. You get protection from update anomalies almost for free.
Re:"At GitHub we do not use foreign keys, ever, anywhere" (2...
by lofaszvanitt on Tuesday January 30, 2024 @06:33AM
(#39188869)
Everyone comes from a different backround and experience. You are wearing a hard hat, but if you don't have the resources, then you need to be smart and not just belch up the dogmas/theoretical stuff.
"Some data left dangling in some table" is the least of the problems. Selecting from those tables will fail to join the parent, or get nulls for the parent columns, depending on the join type. A COUNT(*) or other aggregate function over the orphaned child table will count the orphans. If the parent primary keys get re-used for new rows the orphaned children may end up pointing to the wrong parent. Databases have things like foreign keys to prevent anomalies like this, you shouldn't just conclude it's not worth the trouble now because you will deal with that mistake later.