mysql - Inserting redundant information into the database to prevent table joins? -
i'm trying build activity stream has following structure :
------------------------------------------------------------------------------------ id | activity_by_user_id | activity_by_username | ... other activity related columns ------------------------------------------------------------------------------------
is approach store activity_by_username in activity table ? understand clutter table same username again , again. if not, have join users table fetch username.
the username in web application never changes.
with this, no longer have join table users table. optimum way of achieving need ?
what proposing denormalize data structure. there advantages , disadvantages approach.
clearly, think performance advantage, because not need username
on each row. may not true. lookup should on primary key of table , should quite fast. there situations storing redundant information slow down query. occurs when field size large , there many apps same user. wasting lots of storage on redundant data, increasing size of table. normally, though, expect see modest -- modest -- improvement in performance.
balanced against fact storing redundant data. so, if user name updated, have change lots of rows new information.
on balance, advise go such approach if tested on real data in environment and performance improvement worth it. skeptical see improvement, proof in pudding.
by way, there cases denormalized data structures needed support applications. don't think looking field using primary key 1 of them.
Comments
Post a Comment