Wednesday, June 10, 2009

Firing query inside a loop is a sin

Please donot fire a query inside a loop.Otherwise the performance problem your application will face is unimaginable. There is ALWAYS a way around.You can always solve the problem by firing the query outside the loop(using 'join' or 'in' statement or whatever).It doesn't matter if you need to write a complex and lengthy code to solve the problem by firing the query outside the loop.But please please don't fire it inside the loop.Otherwise almighty(a.k.a customer) will never forgive you.

Note:Be careful while using 'in' statement.If tokens inside the 'in' exceeds 490 in number,yacc Overflow Exception will occur. But there is a smart way around. Refer to following Robin's post.