Hmm, I hadn't looked at depesz comments since I first started looking at this. I think I've basically come full circle and put the inefficient stuff into my suggestion.
I will try and test this on some data here.
If the cursors are what is speeding this up, then we might be able to do the original query as a cursor and forget all the looping.
If the joining is what is slowing it down then we will have to loop over just the copy data.
I will try with retrieving just the new items per circ lib via a cursor and new items for all libs via cursor.
Hmm, I hadn't looked at depesz comments since I first started looking at this. I think I've basically come full circle and put the inefficient stuff into my suggestion.
I will try and test this on some data here.
If the cursors are what is speeding this up, then we might be able to do the original query as a cursor and forget all the looping.
If the joining is what is slowing it down then we will have to loop over just the copy data.
I will try with retrieving just the new items per circ lib via a cursor and new items for all libs via cursor.