I have a table which I'm updating, the update itself takes 8 seconds to complete. When a user comes in, I need to update the table and present them with a sum from the table:
Query
SELECT Jaccard/(SELECT SUM(Jaccard) FROM PreProcessed)
FROM PreProcessed
WHERE MinX = 25 AND MinY = 25
AND MaxX = 26 AND MaxY = 26
The problem is that multiple users can come in at the same time and the X
lock of the UPDATE
statement means that I cannot read from the table for a prolonged period of time.
I was wondering what type of LOCK
I should be using to allow for a query to be able to SELECT
from the previously committed data whilst the update is happening? I initially thought of using READCOMMITTED
, but it doesn't appear to do what I want. I want the data before the update, not the partially committed data.
Stored Procedure
set statistics time ON
DECLARE @MinX INT = 0;
DECLARE @MinY INT = 0;
DECLARE @MaxX INT = 50;
DECLARE @MaxY INT = 50;
DECLARE @Lambda DECIMAL(10, 5) = 0.5;
DECLARE @ReverseLambda DECIMAL(10, 5) = 1 - @Lambda;
DECLARE @Area INT = (@MaxX - @MinX) * (@MaxY - @MinY);
UPDATE PreProcessed
SET Jaccard = (@ReverseLambda * Jaccard) + (@Lambda * dbo.fn_ComputeJaccard(@MinX, @MinY, @MaxX, @MaxY, @Area, MinX, MinY, MaxX, MaxY))
FROM PreProcessed
set statistics time off
What can I do to allow reads to happen during my update, if anything?
EDIT
select CAST(1 AS DECIMAL(38, 28))/CAST(1625625 AS DECIMAL(38, 28))
select CAST(1 AS DECIMAL(20, 10))/CAST(1625625 AS DECIMAL(20, 10))