What is the resource impact from normalizing a database?

后端 未结 8 530
南方客
南方客 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.

    0 讨论(0)
  • 2020-12-10 17:50

    There's a very simple answer to your question: it depends.

    Firstly, I'd re-phrase your question as 'what is the benefit of denormalization', because normalization is the something that should be done as a default (as the result of a pure logical model) and then denormalization can be applied for very specific tables where performance is critical. The main problem of denormalization is that it can complicate data integrity management, but the benefits in some cases outweigh the risks.

    My advice for denormalization: do it only when it really hurts and make sure you got all scenarios covered when it comes to maintaining data integrity after any inserts, updates or deleted.

    0 讨论(0)
提交回复
热议问题