I need to update an entire table. I need a given row (501 in this case) to process against all rows in the table (including itself).
This is what I have so far, but it takes 8 seconds (1.6 million rows):
DECLARE @ID INT = 501;
DECLARE @Lambda DECIMAL(10, 5) = 0.5;
set statistics time on
UPDATE RectangleOne
SET RectangleOne.Jaccard = ((1 - @Lambda) * RectangleOne.Jaccard) + @Lambda *dbo.fn_ComputeJaccard(
RectangleTwo.MinX, RectangleTwo.MinY, RectangleTwo.MaxX, RectangleTwo.MaxY,
RectangleOne.MinX, RectangleOne.MinY, RectangleOne.MaxX, RectangleOne.MaxY)
FROM PreProcessed RectangleOne
INNER JOIN PreProcessed RectangleTwo
ON RectangleTwo.ID = @ID
set statistics time off
I'm hoping someone can see an obvious bottleneck? If not, what should I be looking at to try to get performance improvements?
I should add that performing the calculation takes only 290ms (tested with):
DECLARE @ID INT = 501;
DECLARE @Lambda DECIMAL(10, 5) = 0.5;
set statistics time on
SELECT COUNT(1)
FROM PreProcessed RectangleOne
INNER JOIN PreProcessed RectangleTwo
ON RectangleTwo.ID = @ID
WHERE ((1 - @Lambda) * RectangleOne.Jaccard) + @Lambda *dbo.fn_ComputeJaccard(
RectangleTwo.MinX, RectangleTwo.MinY, RectangleTwo.MaxX, RectangleTwo.MaxY,
RectangleOne.MinX, RectangleOne.MinY, RectangleOne.MaxX, RectangleOne.MaxY) > -1
set statistics time off
And performing a basic update takes only 1500ms (tested using):
UPDATE PreProcessed
SET PreProcessed.Jaccard = PreProcessed.Jaccard*@Lambda;
So it's not clear to me why my actual query takes as long as it does...