Re: performance libpq vs JDBC - Mailing list pgsql-performance

From Richard Huxton
Subject Re: performance libpq vs JDBC
Date
Msg-id 4D0A081E.9010103@archonet.com
Whole thread Raw
In response to Re: performance libpq vs JDBC  (Werner Scholtes <Werner.Scholtes@heuboe.de>)
List 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

pgsql-performance by date:

Previous
From: Jayadevan M
Date:
Subject: Re: How to get FK to use new index without restarting the database
Next
From: Richard Huxton
Date:
Subject: Re: How to get FK to use new index without restarting the database