Re: performance libpq vs JDBC

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance


[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux