Thread: First inserts are faster than second ones

First inserts are faster than second ones

From
AlannY
Date:
Hi there.

I have a strange behaviour about INSERT execution. I have very dummy
PL/pgSQL function, which SELECT data from table; if data exists - skip, if
not - add one. It's about 3'000'000 execution per program life.

Everything works. But there are one weird thing. After DROP TABLE and then
CREATE TABLE (CREATE INDEX), it's must faster to work for this function.
After initial INSERTs the speed of execution about 5 minutes. But,
transaction may fail. If it fail, I can change data and run this function
from the beginning. The second pass on the empty tables are much slower,
about 1,5 hours. So, I decide to DROP TABLE and CREATE it again and gain
much speedup.

Is it normal?

Thanks for patience.