From: | Richard Huxton <dev(at)archonet(dot)com> |
---|---|
To: | Werner Scholtes <Werner(dot)Scholtes(at)heuboe(dot)de> |
Cc: | Divakar Singh <dpsmails(at)yahoo(dot)com>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org> |
Subject: | Re: performance libpq vs JDBC |
Date: | 2010-12-16 12:37:50 |
Message-ID: | 4D0A081E.9010103@archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
On 16/12/10 12:28, Werner Scholtes wrote:
> Thanks a lot for your advice. I found the difference: My Java program
> sends one huge SQL string containing 1000 INSERT statements separated
> by ';' (without using prepared statements at all!), whereas my C++
> program sends one INSERT statement with parameters to be prepared and
> after that 1000 times parameters. Now I refactured my C++ program to
> send also 1000 INSERT statements in one call to PQexec and reached
> the same performance as my Java program.
So - it was the network round-trip overhead. Like Divakar suggested,
COPY or VALUES (),(),() would work too.
You mention multiple updates/deletes too. Perhaps the cleanest and
fastest method would be to build a TEMP table containing IDs/values
required and join against that for your updates/deletes.
> I just wonder why anyone should use prepared statements at all?
Not everything is a simple INSERT. Preparing saves planning-time on
repeated SELECTs. It also provides some SQL injection safety since you
provide parameters rather than building a SQL string.
--
Richard Huxton
Archonet Ltd
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2010-12-16 12:39:39 | Re: How to get FK to use new index without restarting the database |
Previous Message | Jayadevan M | 2010-12-16 12:34:45 | Re: How to get FK to use new index without restarting the database |