Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XcW6K-0006Wa-Ds for pgsql-jdbc@arkaria.postgresql.org; Fri, 10 Oct 2014 09:03:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XcW6J-0000ma-OE for pgsql-jdbc@arkaria.postgresql.org; Fri, 10 Oct 2014 09:03:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XcW6I-0000mS-RG for pgsql-jdbc@postgresql.org; Fri, 10 Oct 2014 09:03:02 +0000 Received: from mout.kundenserver.de ([212.227.17.13]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XcW6E-0007gm-TL for pgsql-jdbc@postgresql.org; Fri, 10 Oct 2014 09:03:01 +0000 Received: from ayaki.localdomain (106-68-76-133.dyn.iinet.net.au [106.68.76.133]) by mrelayeu.kundenserver.de (node=mreue103) with ESMTP (Nemesis) id 0Lwnl2-1YIEhr48Wu-016RUt; Fri, 10 Oct 2014 11:02:57 +0200 Message-ID: <5437A0BB.4070303@2ndquadrant.com> Date: Fri, 10 Oct 2014 17:02:51 +0800 From: Craig Ringer Organization: 2nd Quadrant User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0 MIME-Version: 1.0 To: PostgreSQL JDBC Subject: Adding support for batches that return generated keys Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:U1iAdCKxQLQWZkuaso6lQooowFS1c6hxZJM4eZF+cI4 Zp8LoK/jkhYEkI7Jm0Q+3XocdRAZ/4g44O0edXfJd5DSeUfBv7 XJ0pG7YJPyJQaAM4CbViG31z/K58yF7xR8zQa5pYDqR4EZmbdD +X5zpnc78k/TB7Kd07aaq3ieYfh6ReuQGSqmW2mbCqVBj06KeG Uuzn0YkFdhYNkVK7tX9KqL8ekm8W/7Dl9LcNuI0+O1xUOpkBaN j3FdqCSIdqZA8BjdKvjdiZPlZUsjpGngx6t86OOP+7Wi1fasTI Lwv4euhKug33Rjm7gPd2VoSOhiX8qEdyGgRa1wCufX7S+y8+RE WYyxdwlM8UuFaa374TGaFMwllK2r1GOkTQ562GUqF X-UI-Out-Filterresults: notjunk:1; X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org 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