pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Werner Scholtes <Werner.Scholtes@heuboe.de>
Cc: Divakar Singh <dpsmails@yahoo.com>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: performance libpq vs JDBC
Date: Thu, 16 Dec 2010 12:37:50 +0000
Message-ID: <4D0A081E.9010103@archonet.com> (raw)
In-Reply-To: <128DB53227227D43B4AAEED73E89A81901E2C4B590@vm-exchg-2k8.heuboe.hbintern>
References: <128DB53227227D43B4AAEED73E89A81901E2C4B584@vm-exchg-2k8.heuboe.hbintern>
	<209185.49892.qm@web65409.mail.ac4.yahoo.com>
	<128DB53227227D43B4AAEED73E89A81901E2C4B58B@vm-exchg-2k8.heuboe.hbintern>
	<4D0A02A8.5050206@archonet.com>
	<128DB53227227D43B4AAEED73E89A81901E2C4B590@vm-exchg-2k8.heuboe.hbintern>

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



view thread (10+ messages)  latest in thread

Message-ID: <4D0A081E.9010103@archonet.com>
Permalink:  ../4D0A081E.9010103@archonet.com/
Also on:    postgresql.org/message-id/4D0A081E.9010103@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: dev@archonet.com, Werner.Scholtes@heuboe.de, dpsmails@yahoo.com
  Subject: Re: performance libpq vs JDBC
  In-Reply-To: <4D0A081E.9010103@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox