Integrity constraints in a relational database - should we overlook them?
11
votes
3
answers
2512
views
I’m in a permanent discussion with the developers of the company where I work because they say it is better to get rid of relationship enforcement (via FOREIGN KEY constraint definitions) in a relational database in order to speed up large queries and to gain better performance.
The platform under consideration is MySQL 5.x, and no FOREIGN KEY has been set up, even some PRIMARY KEY constraints of the relevant tables are missing which, at least for me, is not reasonable. Maybe they’re right and I’m wrong, but I don’t have enough arguments to discuss about this situation.
This has been the preferred approach for three years now. I’m new in this company (only one month) but, as the product “works”, there is hesitation to enhance the database; nevertheles, the first thing I noticed is one page taking 1 minute to load (yes, 60 seconds!).
One of the claims behind the current state of affairs is that a “denormalized” database is faster than a normalized one, but I don’t believe that’s true.
Most of the relevant queries include JOIN operations, which makes them run very, very, very slow with large amounts of data (the database contains millions of rows).
Commonly, the handling of “CRUD” operations is implemented at the application program code level; for example, in order to DELETE some data FROM, let’s say,
TableA
:
- it is necessary to first check **on the fly** if there is some relationship between the rows of TableA
and TableB
,
- in case that said relationship is “detected”, then the app program code won’t allow to DELETE the pertinent row(s), **but**
- if for some reason the app program code fails, then the DELETE operation will “succeed”, no matter if there is any relationship regarding the involved rows and tables.
## Question ##
Could you help me to elaborate a good, accurate and solid answer to enrich the debate?
**Note**: Maybe something like this has been asked (and answered) before, but I couldn’t find anything by means of Google.
Asked by ReynierPM
(1888 rep)
Oct 17, 2016, 01:27 PM
Last activity: Nov 20, 2020, 07:46 PM
Last activity: Nov 20, 2020, 07:46 PM