Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xog22-0006Zp-Oj for pgsql-jdbc@arkaria.postgresql.org; Wed, 12 Nov 2014 22:04:54 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xog22-0000aV-4m for pgsql-jdbc@arkaria.postgresql.org; Wed, 12 Nov 2014 22:04:54 +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 1Xog21-0000aO-8K for pgsql-jdbc@postgresql.org; Wed, 12 Nov 2014 22:04:53 +0000 Received: from mail-pd0-x231.google.com ([2607:f8b0:400e:c02::231]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Xog1r-0000nX-Pp for pgsql-jdbc@postgresql.org; Wed, 12 Nov 2014 22:04:51 +0000 Received: by mail-pd0-f177.google.com with SMTP id v10so12964252pde.22 for ; Wed, 12 Nov 2014 14:04:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=tkys1OUlSsZtFc38i68D/a9gU3OdFhfrykRLDxo4xZA=; b=sVJc/hywymXniyrFWhDzq/0rbHddDlCqsLm0tOMtWk4iiZCYVwO48xH8Q57znteH/1 7OJzfVeIXGkgHTH99PEXwvHyWtHLLgcmMbC5oFgGoFgLM/wEJV0b2fCPQMP/vyzsPNm/ MZ5P4nzRcjSPTn4Pi1I+rMkgNWaQLomrQEFVfSWYlkoiQmgA8nT6OQCg6hFqNqlaw/nN FxhE8wolm7lI30v7dEYH/Xzb6KhT4vIZa/VPM3+lF4MerC8WAWkwKu3F9akS0xro/Bpc Q6qDlxtWzgyAK2pWVtNojkXbY8oVfhvJlhRHbo/r1N/8fLaG1YWYnoSvHQc/d9VJh5mO QYbQ== X-Received: by 10.69.13.196 with SMTP id fa4mr50920016pbd.65.1415829879758; Wed, 12 Nov 2014 14:04:39 -0800 (PST) Received: from [10.10.21.129] (otra.opentable.com. [199.16.144.7]) by mx.google.com with ESMTPSA id lr4sm23157299pab.42.2014.11.12.14.04.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Nov 2014 14:04:39 -0800 (PST) Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Subject: Re: New significance of holdable result sets in Java 8 From: Steven Schlansker In-Reply-To: <5855156D-8010-4735-A63D-DC5DF5EABD27@gmail.com> Date: Wed, 12 Nov 2014 14:04:35 -0800 Cc: "pgsql-jdbc@postgresql.org JDBC" Content-Transfer-Encoding: quoted-printable Message-Id: <49F13D7D-3726-4482-B35A-2AD607E88EBF@gmail.com> References: <771672CB-9567-4966-8CE9-9D84E4F858D8@gmail.com> <75C17D7A-95D9-471F-AF64-EFE83D971654@gmail.com> <5855156D-8010-4735-A63D-DC5DF5EABD27@gmail.com> To: Marko Topolnik X-Mailer: Apple Mail (2.1878.6) X-Pg-Spam-Score: -2.7 (--) 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 Nov 12, 2014, at 11:20 AM, Marko Topolnik wro= te: >=20 > I am aware of this approach; I even discuss it as a typical workaround in= my blog post [1]. The problem is, this completely dispenses with the detai= led and complex setup present in the View layer: the response format can be= driven by the Accept HTTP header, encoding may be adapted to the request, = and so on. I did pretty much that in my Clojure projects because Clojure's = ecosystem isn't as well-developed so roll-your-own solutions are the norm. = With Spring, however, you lose a great deal when you give your Controller m= ethod access to the raw response. >=20 > I have already developed a Stream-based REST service along the lines I di= scuss in the mentioned blog post and the advantages are quite clear to me. = It is a direction that Spring would probably like to move in as well. >=20 > [1] http://www.airpair.com/v1/posts/spring-streams-memory-efficiency > ... > You still seem to dictate the output format directly from the Controller,= the avoidance of which is motivating my approach. >=20 Indeed, after reading your blog post, it looks like we have 95% the exact s= ame solution. The essential difference I propose is that instead of having a holdable Res= ultSet (which requires PG-JDBC changes) you hold the Connection/Statement/ResultSet with transaction open for the d= uration. This way the transaction stays open for the duration of your request. So y= ou establish a stream all the way through from end client -> PG. With your suggestion, a holdable ResultSet, you run into what Dave mentione= d: http://www.postgresql.org/docs/9.3/static/sql-declare.html > In the current implementation, the rows represented by a held cursor are = copied into a temporary file or memory area so that they remain available f= or subsequent transactions. So in fact you are just materializing the result set server side. This IMO= defeats the entire purpose - you cannot begin streaming out results until = the materialize finishes (the holdable cursor will not be available until s= aid materialize is done, I believe? or at least the transaction will not c= ommit until that point?) Therefore my proposal is significantly more effic= ient and will never surprisingly materialize gigabytes of temporary disk us= age. Makes more sense? --=20 Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc