Hi friends,
I want to know that, If normalization is gud for database table then why we need to de-normalize the database tables?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
AartiPosted Nov 16, 2011, 7:28 AM
Prons & Cons for normalized DB:
Normalized databases fair very well under conditions where the applications are write-intensive and the write-load is more than the read-load. This is because of the following reasons:
Prons & Cons for De-normalized DB:
Denormalized databases fair well under heavy read-load and when the application is read intensive. This is because of the following reasons:
Using normalized and denormalized approaches together.
The most common way of mixing denormalized and normalized approaches is to duplicate related columns from one table into another table. Let me show you by example:
Suppose you have a products table and an orders table.
The normalized approach would be to only have the product_id in the orders table and all the other product related information in the products table.
But that would make the query that filters by product_name and sorts by order_date inefficient because both are stored in different tables.
In a fully normalized schema, such a query would be performed in the following manner:
SELECT product_name, order_date
FROM orders INNER JOIN products USING(product_id)
WHERE product_name like 'A%'
ORDER by order_date DESC
As you can see MySQL here will have to scan the order_date index on the orders table and then compare the corresponding product_name in the products table to see if the name starts with A.
The above query can be drastically improved by denormalizing the schema a little bit, so that the orders table now includes the product_name column as well.
SELECT product_name, order_date
FROM orders
WHERE product_name like 'A%'
ORDER by order_date DESC
See how the query has become much simpler, there is no join now and a single index on columns product_name, order_date can be used to do the filtering as well as the sorting.
So can both the techniques be used together? Yes they can be, because real word applications have a mix of read and write loads.
Finally
Although, denormalized schema can greatly improve performance under extreme read-loads but the updates and inserts become complex as the data is duplicate and hence has to be updated/inserted in more than one places.
One clean way to go about solving this problem is through the use of triggers. For example in our case where the orders table has the product_name column as well, when the value of product_name has to be updated, then it can simply be done in the following way:
However, when denormalizing the schema, do take into consideration, the number of times you would be updating records compared to the number of times you would be executing SELECTs. When mixing normalization and denormalization, focus on denormalizing tables that are read intensive, while tables that are write intensive keep them normalized.
Thanks.
Deepak DwijPosted Nov 26, 2011, 4:05 AM
AartiPosted Nov 24, 2011, 11:42 PM
Deepak DwijPosted Nov 24, 2011, 4:17 PM
Deepak DwijPosted Nov 24, 2011, 4:16 PM
Pravin MorePosted Nov 14, 2011, 11:55 PM
Hi Deepak,
see,fully normalized database schema can fail to provide adequate system response time due to excessive table join operations.so its better to denormalize it.
for explanation lets take example....
The third normal form (3NF) solution and the denormalized table structure is given below with telephone number (Phone1, Phone2, Phone3, …) as a repeating field:
3NF:
CUSTOMER (CustomerId, CustomerName,...)
CUST_PHONE (CustomerId, Phone)
Denormalized:
CUSTOMER (CustomerId, CustomerName, Phone1, Phone2, Phone3, ...)
this denormalized solution is usually only appropriate if one can guarantee that a customer will have a limited finite number of telephone numbers, or if the firm makes a management decision not store more than "N" number of telephone numbers.
so its depend on our need to use normalization or denormalization.
Thanks,
Pravin.
Mark "Accepted Answer" if this post help You.