in reply to DBI insert statement

Looking at the examples it seems the structures of the tables is the same, you are inserting a subset to the new table. If so and there isn't some other parsing happening can't you offload the whole to the database

insert into targettable select * from sourcetable where ...

If target doesn't need to permanently exist you can

create targettable as (select * from sourcetable where...)

Then drop the new table at end of run.