I have a "items" table with 1 million rows and a "users" table with 20,000 rows. When I select from the "items" table I do a join on the "users" table (items.user_id = user.id), so that I can grab the "username" from the users table.
I'm considering adding a username column to the items table and removing the join. Can I expect a decent performance increase from this? It's already quite fast, but it would be nice to decrease my load (which is pretty high).
The downside is that if the user changes their username, items will still reflect their old username, but this is okay with me if I can expect a decent performance increase.
I'm asking stackoverflow because benchmarks aren't telling me too much. Both queries finish very quickly. Regardless, I'm wondering if removing the join would lighten load on the database to any significant degree.
Example query with join:
SELECT Item
.id
, Item
.submitter_id
, Item
.source_image
, Item
.cached_image
, Item
.source_title
, Item
.source_url
, Item
.width
, Item
.height
, Item
.status
, Item
.popular
, Item
.made_popular
, Item
.fave_count
, Item
.tags
, Item
.user_art
, Item
.nudity
, Item
.created
, Item
.modified
, Item
.removed
, Item
.nofront
, Item
.test
, Item
.recs
, Item
.recs_data
, User
.id
, User
.username
, User
.password
, User
.email
, User
.fullname
, User
.profileurl
, User
.homepage
, User
.bio
, User
.location
, User
.avatar
, User
.ff_user
, User
.ff_key
, User
.ff_last_faveid
, User
.twitter_user
, User
.twitter_pass
, User
.emailalerts
, User
.showunsafe
, User
.view
, User
.fb_uid
, User
.fb_session
, User
.fb_avatar
, User
.twitter_uid
, User
.twitter_data
, User
.twitter_autopost
, User
.uri
, User
.created
, User
.modified
FROM items
AS Item
LEFT JOIN users
AS User
ON (Item
.submitter_id
= User
.id
) WHERE Item
.nofront
!= 1 AND Item
.removed
!= 1 AND Item
.made_popular
is not NULL AND nudity != 1 ORDER BY Item
.made_popular
DESC LIMIT 1040, 290;
Example query without join:
SELECT Item
.id
, Item
.submitter_id
, Item
.source_image
, Item
.cached_image
, Item
.source_title
, Item
.source_url
, Item
.width
, Item
.height
, Item
.status
, Item
.popular
, Item
.made_popular
, Item
.fave_count
, Item
.tags
, Item
.user_art
, Item
.nudity
, Item
.created
, Item
.modified
, Item
.removed
, Item
.nofront
, Item
.test
, Item
.recs
, Item
.recs_data
FROM items
AS Item
WHERE Item
.nofront
!= 1 AND Item
.removed
!= 1 AND Item
.made_popular
is not NULL AND nudity != 1 ORDER BY Item
.made_popular
DESC LIMIT 1040, 290;