postgresql - Difference between INSERT and COPY -


as per documentation,

loading large number of rows using copy faster using insert, if prepare used , multiple insertions batched single transaction.

why copy faster insert (multiple insertion batched single transaction) ?

quite number of reasons, actually, main ones are:

  • typically, client applications wait confirmation of 1 insert's success before sending next. there's round-trip delay each insert, scheduling delays, etc. (pgjdbc supports pipelineing inserts in batches, i'm not aware of other clients do).

  • each insert has go through whole executor. use of prepared statement bypasses need run parser, rewriter , planner, there's still executor state set , tear down each row. copy setup once, , has extremely low overhead each row, no triggers involved.

the first point significant. it's network round-trips , rescheduling delays.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -