7
Consider that we have the models A
, B
, C
and D
, each one referencing to the above, ie, A
has many B
s, B
has many C
s and C
has many D
s:
Redundancy-free
A
| id | ... |
------------
| ... | ... |
B
| id | a_id | ... |
--------------------
| ... | ... | ... |
C
| id | b_id | ... |
--------------------
| ... | ... | ... |
D
| id | c_id | ... |
--------------------
| ... | ... | ... |
It would be recommended to include more columns in C
and D
indicating which the referenced record of A
and B
?
Redundancy
C
| id | a_id | b_id | ... |
---------------------------
| ... | ... | ... | ... |
D
| id | a_id | b_id | c_id | ... |
----------------------------------
| ... | ... | ... | ... | ... |
It is a redundancy, but I usually do this to facilitate consultations, it is useful to avoid JOIN
s. I also believe that the economy of JOIN
improve your performance.
Is this considered good or bad practice? (If not in all cases, at least when the data is immutable) Is there any better solution for this?
I didn’t ask the question, but... what if the data is immutable?
– user7261
@Andrey To tell the truth, I took into consideration that all the fields mentioned were immutable. Strictly speaking, in this case the part of the second topic mentioning an UPDATE operation may perhaps be discarded - I imagine that most Dbmss only test cardinality if the fields involved in a relationship are changed - but still all the other points are valid.
– OnoSendai