question

tabinsc avatar image
tabinsc asked

View with joins to multiple tables - performance

Pardon the long post here. I have a scenario where I'm trying to normalize one table with 200+ columns into 14 tables. This would theoretically be a big boost in performance, both reads and writes. Yet there are thousands of sprocs/queries/apps that select from the one big table. I thought I could just write a view that joins the multiple tables together. While this technically works, performance with the view is very slow because the view has to join all 14 tables, regardless of which ones it actually needs for SELECT and WHERE clauses. Is there a better way to accomplish this? Do I need to write several views, perhaps one for each join scenario? Any advice or thoughts on this are appreciated.

performance-tuningnormalizationdesign
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Kev Riley avatar image
Kev Riley answered

If you create a view for every join scenario, then you have to visit every procedure\query\app that needs adjusting and replace the one large table with a suitable view. If you have to do that then you might as well just replace those queries with the actual joins - why have the need for the views?

The optimizer is very good at eliminating unused tables from queries, but it sounds like you've reached a level of complexity where the optimizer now treats the view as a 'black box' and does not expand the definition out.

So you can have an easy life and have one large table (or large view), but with performance issues, or fix your performance issues and have more code to maintain.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.