sql - Can you run a portion of a script in parallel, based off the results of a select statement? -
i have portion of code which, when simplified, looks this:
select @mainlooptableid = min(uid) queueofids (nolock) while (@mainlooptableid not null) begin -- large block of code several things depending on nature of @mainlooptableid -- . -- . -- . -- end of blocks main logic delete queueofids uid = @mainlooptableid select @mainlooptableid = min(uid) queueofids (nolock) end
i able run segment of code that's inside while loop parallel uids inside queueofids table. based on happens inside loop i can guarantee not interfere each other in way if run concurrently, logically seems safe run this. real question if there way sql run portion of code values in there?
note: did think generating temp table series of created sql statements stored strings, each 1 identical except @mainlooptableid value. if have table of sql statements ready execute, i'm not sure how of these statements execute concurrently.
i can't think of way within single sql script; scripts procedural. if want explore idea, you'd need involve form of multi-threaded application handle looping aspect, , open thread hand off parallelized portion of current script. not impossible, introduce complexity.
if want in sql, you'll have rewrite code eliminate loop. noted in comments above, sql server set-based, means handles amount of parallelization doing work "all @ once" against set.
Comments
Post a Comment