What is the resource impact from normalizing a database?

后端 未结 8 544
南方客
南方客 2020-12-10 16:58

When taking a database from a relatively un-normalized form and normalizing it, what, if any, changes in resource utilization might one expect?

For example,

8条回答
  •  暖寄归人
    2020-12-10 17:38

    For one thing, you'll end up having to do resultset calculations. For example, if you have a Blog, with a number of Posts, you could either do:

    select count(*) from Post where BlogID = @BlogID
    

    which is more expensive than

    select PostCount from Blog where ID = @BlogID
    

    and can lead to the SELECT N+1 problem, if you're not careful.

    Of course with the second option you have to deal with keeping the data integrity, but if the first option is painful enough, then you make it work.

    Be careful you don't fall foul of premature optimisation. Do it in the normalised fashion, then measure performance against requirements, and only if it falls short should you look to denormalise.

提交回复
热议问题