pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <craig@2ndquadrant.com>
To: PostgreSQL JDBC <pgsql-jdbc@postgresql.org>
Subject: Adding support for batches that return generated keys
Date: Fri, 10 Oct 2014 17:02:51 +0800
Message-ID: <5437A0BB.4070303@2ndquadrant.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

Hi all

I've implemented support for batches that return generated keys.

https://github.com/pgjdbc/pgjdbc/pull/204

and I'm looking for feedback before I merge this into master.


Currently the driver internally executes these one-by-one, which is
pretty horrible if there's a big round-trip involved.

Details in Github issue #195:

https://github.com/pgjdbc/pgjdbc/issues/195



With this change PgJDBC now executes batches that return generated keys
in internal sub-batches separated by periodic Sync, flush, and input
consume pauses, just, like it does for batches that don't return keys.

This is safe (or almost as safe as it ever was given github #194)
because we force a Describe, then estimate the result row size and
adjust the batch size accordingly.

This approach does increase the deadlock risk if a batch executes
statements where each statement returns many generated keys (e.g. a big
multi-entry VALUES clause or an INSERT INTO ... SELECT ...), as it
assumes each execution will only return one generated key. That's a
fairly reasonable assumption, given that the lack of intra-statement
ordering guarantees means you can't reliably associate generated keys to
the values that generated them unless you run one statement per
generated result. I don't expect this to be an issue in practice. In any
case, anyone who's doing this is likely to be doing so as an attempt to
work around the very limitation this commit fixes.
-- 
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


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



view thread (3+ messages)  latest in thread

Message-ID: <5437A0BB.4070303@2ndquadrant.com>
Permalink:  ../5437A0BB.4070303@2ndquadrant.com/
Also on:    postgresql.org/message-id/5437A0BB.4070303@2ndquadrant.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 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: craig@2ndquadrant.com
  Subject: Re: Adding support for batches that return generated keys
  In-Reply-To: <5437A0BB.4070303@2ndquadrant.com>
  References: <5437A0BB.4070303@2ndquadrant.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