Join table or duplicate data?
I am looking for real-world imp开发者_开发知识库lementations: Use case is this -> I store the user login details (mode, session, browser, OS, etc) in the session table. I have a activity table where i track activities that FKs to session table.
Now when a user takes an activity on an object like "Create a photo" I want to include all the details with it like the browser the user used to upload the image, his IP address, etc. So all the fields in the session table.
On a good day you would normally FK the session_Id with the photo table and join to pull that data. But what if i duplicate the same 6-7 colunms in the photo and each object table to prevent joins/FKs?
I want to know what works in the real world on large scale user content sites.
If you're not expecting the details (browser, IP address, etc) to change during a session, why duplicate the data? Just associate each photo (or more generally, every activity instance) with the session_id that it was uploaded.
On the other hand, if you are expecting the details to change however once someone has logged in (which can occur -- think of someone having a new IP address when they login to your site on network 1, sleep their laptop, move to a new network, and then un-sleep, such that their browser retains the cookie even though the IP address changes), I would either:
Treat those as different sessions OR
Create a CLIENT_INFO table and make it a 1:M association with SESSION, so that you can maintain one logical session, but support multiple CLIENT instances.
If I were you, and I really needed those details, I would probably do the latter.
精彩评论