sql - Stored Procedure is too slow (using CURSOR ) -


i have below code insert unprocessed (processed=0) records server 1 server 2 (using linked servers), , once inserted should updated processed=1

i using

query 1:

insert select processed=0 update processed=1 processed=0 

query 2:

declare pending_records cursor local select processed=0  open pending_records  fetch next pending_records @uniqueid  while @@fetch_status=0 begin  insert select uniqueid=@uniqueid  if @@rowcount=1 .... update processed=1 uniqueid=@uniqueid  fetch next pending_records @uniqueid  end  close pending_records  deallocate pending_records 

query 1 super fast , query using cursor slow ( takes 30 seconds updates 1 records)

i stay away query 1 because if there failure in database, effect records. note: cannot use distributed transaction right because needs additional setup.

have tried using 'fast_forward' argument?

the 'fat_forward' specifies forward_only, read_only cursor performance optimizations enabled. fast_forward can not specified if scroll or for_update specified.

read more here.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -