Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XayGB-0006xx-Si for pgsql-jdbc@arkaria.postgresql.org; Mon, 06 Oct 2014 02:42:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XayGB-0003a3-8z for pgsql-jdbc@arkaria.postgresql.org; Mon, 06 Oct 2014 02:42:51 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XayG9-0003Zu-AA for pgsql-jdbc@postgresql.org; Mon, 06 Oct 2014 02:42:49 +0000 Received: from mout.kundenserver.de ([212.227.17.13]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XayG5-0006Vp-D2 for pgsql-jdbc@postgresql.org; Mon, 06 Oct 2014 02:42:47 +0000 Received: from ayaki.localdomain (124-148-67-205.dyn.iinet.net.au [124.148.67.205]) by mrelayeu.kundenserver.de (node=mreue103) with ESMTP (Nemesis) id 0Lyk6B-1YFekA10St-016Asi; Mon, 06 Oct 2014 04:42:42 +0200 Message-ID: <5432019C.7000401@2ndquadrant.com> Date: Mon, 06 Oct 2014 10:42:36 +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: Vitalii Tymchyshyn CC: PG-JDBC Mailing List Subject: Re: Disk buffering of resultsets References: <541E7FC3.3000201@2ndquadrant.com> <3F6D0B4E-2FA9-42D0-8C2C-DC68E6D0D641@gmail.com> <54205F94.9010102@hogranch.com> <542091F0.10706@hogranch.com> <1321.1411433175@sss.pgh.pa.us> <54300AA6.3040309@2ndquadrant.com> <5431F61B.9060802@2ndquadrant.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:B9MXTTWtbILWaDkuXkUgIZKiGKuU/aO4RP1JCE2/nmd JxvNRXlzpos3zJfL/t7sOOyryanHKDkNZh7LLbqAkByOjw9cqU qwxDSS8uMDcO4ib0heL9iSrwMh6NAd3EBe3xVtx/Ha2CljMhlz brYEn4doU18+ghJZdSLN5Of6CdnXXvE05kcoKjYFh/xQ4fXcU5 +hliU6TR2M0b/9oAjALQlAiEBKD0WRtCJp32yStKdZ3GlE6mmI UsLxy4X+2qyvDuj6+BHLVog6EXF8Uh0p1sXmdg86daFfFDjZ87 seH4bBuGNNK7dTVyWTeQcQg80KAbxIUXIxnnCPL2dUWzl0E9a0 0SOg2+9D6XH/HljHslZfZauehH5Abq82NP1ZDUt1N 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 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