pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: ralf.baumhof@bgs-ag.de
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Performance of jdbc insert statements and select nextval
Date: Fri, 20 Feb 2009 12:41:52 -0500 (EST)
Message-ID: <Pine.BSO.4.64.0902201230530.23634@leary.csoft.net> (raw)
In-Reply-To: <OF1AE9FE8F.A62C4576-ONC1257561.0053E641-C1257563.00384E4C@LocalDomain>
References: <OF1AE9FE8F.A62C4576-ONC1257561.0053E641-C1257563.00384E4C@LocalDomain>



On Fri, 20 Feb 2009, ralf.baumhof@bgs-ag.de wrote:

> [insert with pgadmin is faster than JDBC]

As I explained previously I believe pgadmin is sending all of your inserts 
in one network roundtrip rather than a single insert at a time.  So for 
example:

StringBuffer sql = new StringBuffer();
for (int i=0; i<100; i++) {
 	sql.append("INSERT INTO mytable (a) VALUES (");
 	sql.append(i).append(")");
}
Statement.execute(sql.toString())

will be faster than

for (int i=0; i<100; i++) {
 	String sql = "INSERT INTO mytable (a) VALUES (" + i + ")";
 	Statement.execute(sql);
}

because the second sample has to make 100 network trips instead of just 
one.

> I made a test with "logical" insert of objects which results in 50000 
> inserts can be done within 2 minutes, what means 416 inserts per second, 
> or 1 insert in 2/1000 sec (2ms). The cost estimate with explain for an 
> insert is on the other hand is 0,4 ms.

Explain cost estimates do not have units of milliseconds, so the 
comparison is invalid.

Kris Jurka



view thread (6+ messages)  latest in thread

Message-ID: <Pine.BSO.4.64.0902201230530.23634@leary.csoft.net>
Permalink:  ../Pine.BSO.4.64.0902201230530.23634@leary.csoft.net/
Also on:    postgresql.org/message-id/Pine.BSO.4.64.0902201230530.23634@leary.csoft.net

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: books@ejurka.com, ralf.baumhof@bgs-ag.de
  Subject: Re: Performance of jdbc insert statements and select nextval
  In-Reply-To: <Pine.BSO.4.64.0902201230530.23634@leary.csoft.net>
  References: <OF1AE9FE8F.A62C4576-ONC1257561.0053E641-C1257563.00384E4C@LocalDomain> <Pine.BSO.4.64.0902201230530.23634@leary.csoft.net>

* 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