Обсуждение: Adding support for batches that return generated keys
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
Hello Craig, On 10/10/2014 11:02, Craig Ringer wrote: > 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. I spent some time in looking your patch. Since I am just beginning studying how pgjdbc works, I cannot speak about correctness of the code, but I still have two questions: First one is about the java version you are using. It seems to me that the driver should be compileable in java 1.4, i.e., on a java version that doesn't use int and Integer in a mixed way. At the end of getMaxResultRowSize() in org/postgresql/core/v3/SimpleQuery.java you assign an int value to an Integer variable. Is this correct? On the very same method, on the first lines, you extract the intValue() from the Integer variable. Second, in method flushIfDeadlockRisk(...) in file org/postgresql/core/v3/QueryExecutorImpl.java, about line 1169, you use the word "uresults". Is this a typo or a data structure used by pgjdbc? Bye, Giuseppe
Giuseppe,
I don't think there is any reason to require 1.4 compiling here ? Java 1.4 has been EOL since 2008.
Any new code only needs to be 1.7 compatible.
If we really need to back patch it for whatever reason that is another problem
On 14 October 2014 09:14, Giuseppe Sacco <giuseppe@eppesuigoccas.homedns.org> wrote:
Hello Craig,
On 10/10/2014 11:02, Craig Ringer wrote:
> 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.
I spent some time in looking your patch. Since I am just beginning
studying how pgjdbc works, I cannot speak about correctness of the code,
but I still have two questions:
First one is about the java version you are using. It seems to me that
the driver should be compileable in java 1.4, i.e., on a java version
that doesn't use int and Integer in a mixed way. At the end of
getMaxResultRowSize() in org/postgresql/core/v3/SimpleQuery.java you
assign an int value to an Integer variable. Is this correct?
On the very same method, on the first lines, you extract the intValue()
from the Integer variable.
Second, in method flushIfDeadlockRisk(...) in file
org/postgresql/core/v3/QueryExecutorImpl.java, about line 1169, you use
the word "uresults". Is this a typo or a data structure used by pgjdbc?
Bye,
Giuseppe
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc