[Also on SuperUser - https://superuser.com/questions/116600/can-i-spead-out-a-long-running-stored-proc-accross-multiple-cpus ]
I have a stored procedure on an SQL server that receives and decrypts a data block. (Credit cards in this case.)
In most cases, performance is acceptable, but there are a couple of clients where the process is slow, literally 1 minute to complete. (Well, 59377ms to return from SQL Server, to be precise, but it can vary by several hundred ms based on load)
When I look at a process, I see that SQL uses only one proc to execute the whole process and usually only proc 0.
Is there a way to modify my stored proc so that SQL can process the process multithreadedly? Is it possible to fool and split calls in half (50%, lower 50%) and distribute the load like a rough hack? (just flattening here)
My saved proc:
USE [Commerce] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[GetAllCreditCardsByCustomerId] @companyId UNIQUEIDENTIFIER, @DecryptionKey NVARCHAR (MAX) AS SET NoCount ON DECLARE @cardId uniqueidentifier DECLARE @tmpdecryptedCardData VarChar(MAX); DECLARE @decryptedCardData VarChar(MAX); DECLARE @tmpTable as Table ( CardId uniqueidentifier, DecryptedCard NVarChar(Max) ) DECLARE creditCards CURSOR FAST_FORWARD READ_ONLY FOR Select cardId from CreditCards where companyId = @companyId and Active=1 order by addedBy desc
source share