pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <craig@2ndquadrant.com>
To: Vitalii Tymchyshyn <vit@tym.im>
Cc: PG-JDBC Mailing List <pgsql-jdbc@postgresql.org>
Subject: Re: Disk buffering of resultsets
Date: Mon, 06 Oct 2014 10:42:36 +0800
Message-ID: <5432019C.7000401@2ndquadrant.com> (raw)
In-Reply-To: <CABWW-d3jpnTLeY3mrRJtNW+2NNN21kPh=rXDXowOkB5qYMyVfw@mail.gmail.com>
References: <CAHKhnVUW9hu9ePD9zeVmvkeRjK8VaO9_jVDdqiNPf8=xBkaM1Q@mail.gmail.com>
	<541E7FC3.3000201@2ndquadrant.com>
	<3F6D0B4E-2FA9-42D0-8C2C-DC68E6D0D641@gmail.com>
	<54205F94.9010102@hogranch.com>
	<CAHKhnVX5qxNOCBFXwivt1Mwzdaru9hoG9wCviAKUj9Dcmnu=0w@mail.gmail.com>
	<542091F0.10706@hogranch.com>
	<1321.1411433175@sss.pgh.pa.us>
	<CABWW-d3QW0ywPge0-mVZ1d1WhsGwB5cWy4wOo3CK-sPOdqEKiA@mail.gmail.com>
	<54300AA6.3040309@2ndquadrant.com>
	<CABWW-d3u+iOim+R9NXfC=NzHO7OuL0W_6T4diKNmPkja+Vfm2A@mail.gmail.com>
	<5431F61B.9060802@2ndquadrant.com>
	<CABWW-d3jpnTLeY3mrRJtNW+2NNN21kPh=rXDXowOkB5qYMyVfw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

On 10/06/2014 10:22 AM, Vitalii Tymchyshyn wrote:
> Hello.
> 
> As of routing I meant exactly attaching to original statement result
> belongs to and throwing an error as soon as someone get to correct point
> calling this original statement.
> As of threading I tend to agree with you. It can be revised in Java 8
> where there is a default executor that can be used.
> 
> The primary problem as I can see it are OOMs on large result sets.
> Currently the workaround is to use fetchSize, but it works only in very
> limited scenarios. 

Specifically, autocommit=off and only one active Statement. Right?

The PostgreSQL backend its self supports multiple open portals, but only
within the same open transaction, and if any statement causes an error
all portals are invalidated. So we can't really use that if you want
multiple *independent* statements.

The usual answer would be WITH HOLD cursors (or a portal-level
equivalent). There's a server-side impact to them, but it's probably the
first thing to try.

Failing that, as you say, we'd have to fetch the whole result set to the
client and store it off-heap, which is where the abstraction I've talked
about on this mailing list thread comes in.

An issue here is that PgJDBC currently has some restrictions around
multiple application threads using a single Connection at the same time.
If you're working with multiple statements you're quite possibly also
working with multiple threads, right?

> I can see two ways here: improve fetchSize handling (potentially setting
> default fetchSize to some value like 10000) or storing result sets out
> of heap.
> One more thing to remember is time to get first row. It would be great
> to have first fast enough  without reading, parsing and storing
> somewhere all the 1000000 rows.

... which is where the issues with threading come in, because you want
to fetch some results, return them to the client, and continue
processing the rest of the results in a helper thread in the driver.

I think we'd have to get the client app involved more directly in that,
by exposing partial fetches more directly to the client and allowing it
to ask us (possibly via a separate thread) to consume more results and
append them to the result set. We'd have to deal with the resulting
locking issues carefully.

-- 
 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 (37+ messages)  latest in thread

Message-ID: <5432019C.7000401@2ndquadrant.com>
Permalink:  ../5432019C.7000401@2ndquadrant.com/
Also on:    postgresql.org/message-id/5432019C.7000401@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, vit@tym.im
  Subject: Re: Disk buffering of resultsets
  In-Reply-To: <5432019C.7000401@2ndquadrant.com>
  References: <CAHKhnVUW9hu9ePD9zeVmvkeRjK8VaO9_jVDdqiNPf8=xBkaM1Q@mail.gmail.com> <541E7FC3.3000201@2ndquadrant.com> <3F6D0B4E-2FA9-42D0-8C2C-DC68E6D0D641@gmail.com> <54205F94.9010102@hogranch.com> <CAHKhnVX5qxNOCBFXwivt1Mwzdaru9hoG9wCviAKUj9Dcmnu=0w@mail.gmail.com> <542091F0.10706@hogranch.com> <1321.1411433175@sss.pgh.pa.us> <CABWW-d3QW0ywPge0-mVZ1d1WhsGwB5cWy4wOo3CK-sPOdqEKiA@mail.gmail.com> <54300AA6.3040309@2ndquadrant.com> <CABWW-d3u+iOim+R9NXfC=NzHO7OuL0W_6T4diKNmPkja+Vfm2A@mail.gmail.com> <5431F61B.9060802@2ndquadrant.com> <CABWW-d3jpnTLeY3mrRJtNW+2NNN21kPh=rXDXowOkB5qYMyVfw@mail.gmail.com> <5432019C.7000401@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