Question
In the context of this exercise, why isn’t there a field for whether a user is a premium user in the users
table?
Answer
There can be a number of reasons why this information is not stored in that table. When developing a schema, there are always tradeoffs, and most of the time, there is no “perfect” solution.
It might work to add another field in the users
table, such as an is_premium
column, that tells whether or not they are a premium user. This can probably store a bit value, where 0
means they are not a premium user, and 1
means that they are a premium user. This may speed up some queries because we only would need to check the premium_users
table if the value is 1
.
However, this field would require more memory stored in the table, as well as make the users
table less independent from the premium_users
table. With databases, we want to normalize the data as much as possible. Also, a lookup of whether the user_id
is in the premium_users
table may not take too long, so the time tradeoff can be reasonable to save memory.