Reputation: 1516
Let's say I have a table with 10,000 rows each with a unique ID. The first time a user visits my website I will pick 100 IDs at random and store them in a DB so that whenever he returns I will be able to pick these exact IDs again.
My question is: what's the best way to store these IDs? Should I just create another table and have each of these IDs store one per row? Or should I join them with a comma and then save them as one big row? What is more efficient for selecting this data every time?
Upvotes: 1
Views: 42
Reputation: 30628
It will probably be more efficient to store these relationally. If you store them in a comma-separated list, you will need to parse this at the client end, and run multiple queries. By storing within the database, you will just need to perform the same query repeatedly.
MySQL has a query cache (which is disabled by default), which will cache the result if you repeatedly execute exactly the same query and the underlying data does not change in the mean time.
Upvotes: 3