Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XotE4-0004NW-SB for pgsql-jdbc@arkaria.postgresql.org; Thu, 13 Nov 2014 12:10:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XotE3-0007tj-P7 for pgsql-jdbc@arkaria.postgresql.org; Thu, 13 Nov 2014 12:10:11 +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 1XotE1-0007t0-PE for pgsql-jdbc@postgresql.org; Thu, 13 Nov 2014 12:10:09 +0000 Received: from mail-wg0-x229.google.com ([2a00:1450:400c:c00::229]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XotDw-0007m5-Vk for pgsql-jdbc@postgresql.org; Thu, 13 Nov 2014 12:10:08 +0000 Received: by mail-wg0-f41.google.com with SMTP id l18so1220055wgh.28 for ; Thu, 13 Nov 2014 04:10:01 -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=HllbSQQDYpEZRlSeNr1stX/lfQ+pYr/sG94Q1xXOLdQ=; b=ri4autqRinD2USQjFKtMqxFHh+jtXgqS9kU/nWJs9y6j9ao4AmRZYRij8qLblfs/Pu 0LsVQVj8ZLYbm895zKLRKxNJce968EcN03wWEvv6urn7IxVPOLu7CZCW1bzTTaQRCfe+ LBzdzzfQDPVfpLxbkfZ8jurLQQBdisG33jQoSGoqIk2NBdsrj3T607WQQxQTTBjEsx0h NHeuwXmSkul21afmcg/EOXggTQ/2HKAOki0ob9skdyWlAxr6uY7ZwQY/Wc5KK8/wcNei hANhmZ0xLV4zVPi1EMpOZcpJ9tnEvpLJWiReKqup2e6qLThnTVCTOklGVmn59W5d1Qdm 1zpw== X-Received: by 10.194.175.67 with SMTP id by3mr3472873wjc.32.1415880601806; Thu, 13 Nov 2014 04:10:01 -0800 (PST) Received: from [172.31.254.245] ([85.183.84.148]) by mx.google.com with ESMTPSA id t7sm35290656wjy.24.2014.11.13.04.09.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Nov 2014 04:10:01 -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: Marko Topolnik In-Reply-To: <49F13D7D-3726-4482-B35A-2AD607E88EBF@gmail.com> Date: Thu, 13 Nov 2014 13:08:32 +0100 Cc: "pgsql-jdbc@postgresql.org JDBC" Content-Transfer-Encoding: quoted-printable Message-Id: References: <771672CB-9567-4966-8CE9-9D84E4F858D8@gmail.com> <75C17D7A-95D9-471F-AF64-EFE83D971654@gmail.com> <5855156D-8010-4735-A63D-DC5DF5EABD27@gmail.com> <49F13D7D-3726-4482-B35A-2AD607E88EBF@gmail.com> To: Steven Schlansker 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 Yes, your approach makes perfect sense---as long as you don't care about tr= ansactional semantics. If the transaction boundary is moved all the way to the end of serving the = response, the following happens: 1. 200 OK status code reported, but transaction still not committed; 2. transaction may roll back due to errors in transfer; 3. thanks to buffering, the transfer may also fail _after_ the transaction = has committed. So, not only have you established quite messy and illogical transaction sem= antics for your client (for example, a typical onSuccess callback on the HT= TP request cannot assume the transaction succeeded); the client has no idea= _in principle_ what happened to the transaction if transfer is aborted for= any reason. In an earlier incarnation of my project I did indeed have setup exactly as = you describe it, but after realizing the above problems, I had to back off = and revert to standard transaction boundaries. On 12. stu. 2014., at 23:04, Steven Schlansker = wrote: >=20 > On Nov 12, 2014, at 11:20 AM, Marko Topolnik w= rote: >>=20 >> I am aware of this approach; I even discuss it as a typical workaround i= n my blog post [1]. The problem is, this completely dispenses with the deta= iled and complex setup present in the View layer: the response format can b= e 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 = method access to the raw response. >>=20 >> I have already developed a Stream-based REST service along the lines I d= iscuss 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 >=20 > Indeed, after reading your blog post, it looks like we have 95% the exact= same solution. >=20 > The essential difference I propose is that instead of having a holdable R= esultSet (which requires PG-JDBC changes) > you hold the Connection/Statement/ResultSet with transaction open for the= duration. >=20 > This way the transaction stays open for the duration of your request. So= you establish a stream all the way through > from end client -> PG. >=20 > With your suggestion, a holdable ResultSet, you run into what Dave mentio= ned: >=20 > 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 = for subsequent transactions. >=20 > So in fact you are just materializing the result set server side. This I= MO defeats the entire purpose - you cannot begin streaming out results unti= l the materialize finishes (the holdable cursor will not be available until= said materialize is done, I believe? or at least the transaction will not= commit until that point?) Therefore my proposal is significantly more eff= icient and will never surprisingly materialize gigabytes of temporary disk = usage. >=20 > Makes more sense? >=20 --=20 Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc