I am using CURSORs to do some row-by-row operation.
OPEN CURSOR_T
FETCH NEXT FROM ...
WHILE @@FETCH_STATUS = 0
BEGIN
... Block begins
... Block Inserts results into a table
... Block terminates
END
I was wondering why this cannot be executed in parallel as the row operations are completely isolated and only insert some rows into another table and each row has its own ID assigned so there is no obvious possibility of a conflict.
I was wondering if there is a way to parallelize this in pure SQL?
This is usually achieved through a queue: you select the ‘to do’ items and drop them into a queue, and at the same time queue readers (processing threads) are dequeuing the ‘to do’ items and process them one by one. There is a fine art in using tables as queues, the processing is often associated with activation and the enqueue/dequeue cycle is actually contiguous.