Web Hosting Talk







View Full Version : Optimizing SQL queries..


arribadia
02-17-2005, 10:01 AM
Hi,

I am just curious, which would be more optimized... Many small queries, or a few big massive nested queries?

error404
02-17-2005, 10:55 AM
Generally large queries, as it gives the database software a chance to optimize in more places. If you do a bunch of small queries and then do all of your data processing client-side, all those indexes and highly-tuned data-access code won't help you a bit. Just make sure your large queries aren't doing any sequential scans, and it should be faster.

But, as ever, profile your application and decide for yourself.

hiryuu
02-17-2005, 07:51 PM
As long as you can stay on indexes, a few monster queries will be faster. In addition to what error404 mentioned, fewer queries means fewer context switches and shuffling data back and forth between programs (or even boxes).