Mar 6, 2007 10:47 pm
Database Optimizations
I want to bring up some points about subject of database optimization based on my collective experience in dealing in this area.
- Optimizing sql queries requires effort which in business world translates into money. A business may want efforts spend on development of features which would bring the company revenue and hence more money to spend on development. So efforts spend on optimization may well be spend on things that are more important at any one time. Off-course if the application is so slow that it is unusable that's a problem that is worth spending the effort on optimizing.
- Normalizing the data model is good in general but its great for performance. I noticed that joining tables is almost always efficient if the data model is normalized properly. Also I found it is helpful to give consistent naming convention to key columns. For example Post( Post_Id , ... ), Comment( Comment_Id, Post_Id, ... ).
- Optimize only when it is required based on real world profiling. Each application may have different set of requirement but in general new application do not have a lot of data and hence will not see performance issues that would show up if a lot of data is present. So in the beginning developing the critical features is more important than making the application snappy. Sure it may take 4 seconds to submit some form and the fix may be trivial but still the effort required may still divert the scarce developer resource. In my experience those initially badly written part of the application are better of being rewritten completely when the data-model is re-factored. At that time it is OK since the parts being rewritten are the ones that matter.