Consider that we have the models A
, B
, C
and D
, each referencing the previous one, ie A
has many B
s, B
has many C
if C
has many D
s:
No redundancy
A
| id | ... |
------------
| ... | ... |
B
| id | a_id | ... |
--------------------
| ... | ... | ... |
C
| id | b_id | ... |
--------------------
| ... | ... | ... |
D
| id | c_id | ... |
--------------------
| ... | ... | ... |
It would be advisable to include more columns in C
and D
indicating which record referenced A
and B
?
With redundancy
C
| id | a_id | b_id | ... |
---------------------------
| ... | ... | ... | ... |
D
| id | a_id | b_id | c_id | ... |
----------------------------------
| ... | ... | ... | ... | ... |
It's a redundancy, but I usually do this to make it easier to query, it's useful to avoid JOIN
s. I also believe that% s% s economy improves 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?