Sylver
Sylver

Reputation: 2453

DB Design : one or two tables to remember a user choice

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 :

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

Answers (2)

Mureinik
Mureinik

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

David
David

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

Related Questions