Reputation: 2453
I have a (huge) list of items in my database, my users (a lot too) are able to say if they like each item or not and i need to keep these informations in the database.
My question is what's the best design for that :
one table with two boolean columns 'like' and 'dislike' for each item for each user (very huge)
two tables, one for the users' like and one for the users' dislike (less huge tables, but will require to do additional joins)
Maybe another way i didn't think about
Basically, in term of performance, is that better to have one very huge table (items * users) or to split it in two tables and using joins ?
Upvotes: 1
Views: 47
Reputation: 311163
You should start by designing for functionality, and then tweak for performance. Do you have any query that needs to access both sets of information (e.g., calculating the "net likes" a topic is given)? If so, this would suggest a single table. Since a user cannot both like and disklike a topic, an improvement on your current suggestion could be a single boolean column - true
can indicate "like" and false
a "dislike". That way you can index it or even partition the table by it in order to improve performance.
Upvotes: 1
Reputation: 1927
Option #1, but wouldn't like and dislike be mutually exclusive?
In that case, why not a single table with item-id, user-id, is-liked. If the user/item is in the table you know if the like/dislike is set. If the user/item is not in the table, then it has not been set
Tables get big, but that's not really a problem if it's indexed properly.
Upvotes: 1