I was wondering what the easiest method would be for me in the future to make queries both effective and less complex.
Should I save a two way relationship like
from_id=1, to_id=2
from_id=2, to_id=1
or just create one unique row
from_id=1, to_id=2
any thoughts?
I would suggest to go for two way relationship. It’s flexible ans it’s only extra work while
inserting anddeleteing the records.The benefits that I see is:
where from_id=useridinstead ofwhere from_id=userid or to_id=useridthat later is expensive.userA is friend of userB while userB does not approves the relationship. To do this you may have an extraisApprovedand set ittrueforfrom_id=userA, to_id=userBand false forfrom_id=userB, to_id=userA— this will allow further cheapsortandselect.The effect in single row will be a little trickier.