While I was at Santanna Energy for a few weeks, Ragan Morris wisely pointed out that a CTE/subselect in the middle of a select in T-SQL statement made for an n+1 problem and the way to fix that in optimizing a stored procedure was to pull that which was in the inner query out to one upfront query to a temp table and to then join that which you were to otherwise query to the temp table. That way n+1 queries becomes just two! But... What if you have some O(n²) issue in C#? How do you fix that? A coworker recommends using a join in LINQ! Using AsParallel in a LINQ join (looping in PLINQ) can break the heavy stuff up across different threads too, but you really only want to go there if things are indeed heavy. Try to join two record sets with a LINQ join in lieu of having a loop inside a loop. That will get expensive when data gets fat.
No comments:
Post a Comment