pg.ddx.io pgsql-jdbc@postgresql.org mailing list archivehelp / 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: Wed, 18 Feb 2009 23:01:14 -0500 (EST)
Message-ID: <Pine.BSO.4.64.0902182251440.7630@leary.csoft.net> (raw)
In-Reply-To: <OF1AE9FE8F.A62C4576-ONC1257561.0053E641-C1257561.00534F39@LocalDomain>
References: <OF1AE9FE8F.A62C4576-ONC1257561.0053E641-C1257561.00534F39@LocalDomain>
On Wed, 18 Feb 2009, ralf.baumhof@bgs-ag.de wrote:
> 10000 inserts with pgadmin tool into one table (primary key bigserial) can
> be done wihtin 3 seconds. If i perform the same job with jdbc this takes
> 13 seconds. The insert statement is prepared only once, the statement for
> fetching the nextval also. If i omit the select nextval execution time
> improves to 8 seconds. Can anybody tell me why jdbc is 3 to four times
> slower than pgadmin?
It's not clear how pgadmin is executing the inserts, but your description
makes it seem like your Java code is doing things a single execution at a
time even if it's only prepared once. If pgadmin is sending all of these
statements across to the server in one batch, then it has just one network
roundtrip to make, while the Java code will need 20000 roundtrips. Since
your alternating insert/select nextval, you can't really use batch
execution. Perhaps you can rework your java code to either fetch a lot of
nextvals at once and then use them in a later batch insert.
SELECT nextval('myseq') FROM generate_series(1,10000);
Or you could rework it to do:
CREATE TABLE tab (a serieal, b int);
INSERT INTO tab (b) VALUES (1), (2), (3) RETURNING a;
Kris Jurka
view thread (6+ messages) latest in thread
Message-ID: <Pine.BSO.4.64.0902182251440.7630@leary.csoft.net> Permalink: ../Pine.BSO.4.64.0902182251440.7630@leary.csoft.net/ Also on: postgresql.org/message-id/Pine.BSO.4.64.0902182251440.7630@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.0902182251440.7630@leary.csoft.net> References: <OF1AE9FE8F.A62C4576-ONC1257561.0053E641-C1257561.00534F39@LocalDomain> <Pine.BSO.4.64.0902182251440.7630@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