Ahh the old days of LAMP when the M was mysql and foreign keys were just a dream... When you reduce complexity and take off the safeguards things get faster! Cock that foot gun and hope that it doesn't go off! Can you do what the author suggests. You sure can and we did it for a long time with MYSQL. Should you? It depends on your team, how in tune they are with working with databases, sql etc...
Do you really need foreign keys?
121–130 of 179 posts
Re: Do you really need foreign keys?
#122Earlier quoted context omitted.
If you do not particularly care about performance or have a great deal of headroom then database enforcement of referential integrity is great. Alternatively you could just write test cases to check for it and not pay the severe performance penalty. The other major downside of database enforcement of referential integrity is the common need to drop and re-create foreign keys during database schema upgrades and data c…
You’re still going to pay the cost of maintaining referential integrity — you’re just doing it on the app side. You can do it faster by being not-correct — eg you don’t need a lock if you ignore race conditions — but it’s not like the database is arbitrarily slow at doing one of its basic fundamental jobs. Of course, you can just skip the validation altogether and cross your fingers and hope you’re correct, but it’s…
Re: Do you really need foreign keys?
#123 a join b join c
If there is an FK from a to b, and likewise from b to c, and you don't use anything in b, then the optimiser can rewrite this to a join c
YMMVRe: Do you really need foreign keys?
#124Re: Do you really need foreign keys?
#125This github issue is often linked when this topic is discussed: https://github.com/github/gh-ost/issues/331 > Personally, it took me quite a few years to make up my mind about whether foreign keys are good or evil, and for the past 3 years I'm in the unchanging strong opinion that foreign keys should not be used. Main reasons are: > * FKs are in your way to shard your database. Your app is accustomed to rely on FK to…
* https://code.openark.org/blog/mysql/things-that-dont-work-we...
* https://code.openark.org/blog/mysql/the-problem-with-mysql-f...
Re: Do you really need foreign keys?
#126Title should be "Do you really need Foreign Key constraints?". Foreign Key is the field itself, will still be there without the constraint.
Re: Do you really need foreign keys?
#127Re: Do you really need foreign keys?
#128I once worked somewhere that used rails in lieu of foreign keys. The result was a brittle nightly delete_orphaned records script as well as obscure user visible bugs. My team started adding foreign keys to our records and unsurprisingly caught bugs in our application code that otherwise would have been missed. Personally, I think the default should always be to usr foreign keys and only if you have a genuine scalabil…
Always important to remember that while learning from others is important; They're just as human as you are.
Re: Do you really need foreign keys?
#129And if you're concerned for microspeed of basic operations Postgres isn't your friend anyway.
Re: Do you really need foreign keys?
#130It was a nightmare. The article seems to basically be saying "but it's hard!". Well, I'd rather put down the extra effort so that I don't have corrupt data.
You know what's really hard? Fixing corrupt data.
The data is the most important thing in a database.