I read today this blog post http://www.andrewrollins.com/2009/06/21/mysql-join-performance/ about join performance. As seen, join could cost performance in some way.
Let's take now an example of two tables, user_profile and user_gallery.
user_profile
user_id | avatar | nickname | ...
user_gallery
image_id | user_id | image | caption | is_avatar
On page browse users, users are listed with their nickname and avatar image.
I can get image in users list with join
INNER JOIN user_gallery ON user_gallery.user_id=user_profile.user_id WHERE user_gallery.is_avatar=1
or I can put to avatar field an image path. In this case, I don't need to use is_avatar field and I have all data needed to display users in table user_profile. So no extra join is needed. But since avatar image is part of user gallery, this would mean value of avatar is also in user_gallery table, so one duplicate value.
Is it really worth to strictly follow normalization rules which could cost performance, having in mind this exact case? What would be better in this case?
The logical choice seems to me to abandon the is_avatar
field and just have user_profile.avatar
reference an image_id
...