pgjdbc/pgjdbc — pull request #204 by ringerc (2014-10-10 08:15:56+00:00)
Title: Batch returning support

Remove the restriction that a batch that returns generated keys is executed internally as individual queries.

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.

Fixes github #195.