Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XodRn-0000C7-E7 for pgsql-jdbc@arkaria.postgresql.org; Wed, 12 Nov 2014 19:19:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XodRm-0004se-UX for pgsql-jdbc@arkaria.postgresql.org; Wed, 12 Nov 2014 19:19:18 +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 1XodRl-0004qU-D3 for pgsql-jdbc@postgresql.org; Wed, 12 Nov 2014 19:19:17 +0000 Received: from mail-pd0-x236.google.com ([2607:f8b0:400e:c02::236]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XodRh-00066f-0Z for pgsql-jdbc@postgresql.org; Wed, 12 Nov 2014 19:19:16 +0000 Received: by mail-pd0-f182.google.com with SMTP id fp1so12871788pdb.27 for ; Wed, 12 Nov 2014 11:19:10 -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=1c2Bf7TwzYvk6XzySvA/1545u2YissxXx6mP8ssWYW4=; b=a5WDdok/eNE8eHOK33ryraJmp3X5dvqm6kL1ThhWKovFiX08Dznp3b/cCqXXDX353J A0x7s33JO8tvag9z3lm0GFBrR4oFHYrwDOw30jkgyumW0tH25AtxhZF6OWbm3pd4Sgir q5HSjowIKy1cHhF2pWIRFbJVTwyCLdmyxHencJuuzSIC6pbNzoYnWc/8pHAJAc/WAg6R g2Izr4MNOBqgmb6qYdRJ84/O0BDfS5i7wT3hVIqknoCPNlOpMS0Xv2+wS31f//MsxK7w QZJsp9Ioqz7iizace9UXrlO2hnASB+CFTG+09dSgyv5Zzen583ukkKVwX33Owh8mEY31 kICg== X-Received: by 10.66.124.136 with SMTP id mi8mr50511233pab.105.1415819950417; Wed, 12 Nov 2014 11:19:10 -0800 (PST) Received: from [10.10.21.129] (otra.opentable.com. [199.16.144.7]) by mx.google.com with ESMTPSA id ub7sm22860213pbc.30.2014.11.12.11.19.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Nov 2014 11:19:09 -0800 (PST) Content-Type: text/plain; charset=windows-1252 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: Date: Wed, 12 Nov 2014 11:19:07 -0800 Cc: Dave Cramer , Marko Topolnik , List Content-Transfer-Encoding: quoted-printable Message-Id: <36F5668B-7D36-40CB-BEEE-2F6C57633D30@gmail.com> References: <771672CB-9567-4966-8CE9-9D84E4F858D8@gmail.com> To: Kevin Wooten 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 10:58 AM, Kevin Wooten wrote: > I=92m inclined to agree with Dave, your usage of holdable cursors sounds = like an extremely burdensome (server wise) solution to a =93nice to have=94= application architecture solution. >=20 > Why not make a stream adapter that fetches results in groups using LIMIT/= OFFSET. This would work in any situation regardless of cursors, transactio= ns, etc and would *only* cost for large result sets that need to extra roun= d trips. IMO LIMIT/OFFSET is generally strictly inferior to holding a transaction op= en (like I proposed in my earlier mail) for anything that isn't reading row= s in database order (unordered) or index order. This is because you end up= paying the startup cost once per batch instead of once per logical query. = Additionally it is now sensitive to concurrent inserts and you may observe= e.g. duplicated or missing rows unless you are *very* careful. >=20 > That being said=85 pgjdbc-ng uses real cursors when asked for them and re= spects the foldability requirement. There are limitations based on postgre= s=92s feature set but I believe what you are asking for works.=20 >=20 >> On Nov 12, 2014, at 11:51 AM, Dave Cramer wrote: >>=20 >> Marko, >>=20 >> When you say holdable cursors are you referring to a holdable cursor out= side of a transaction? It seems so because the transaction commits after le= aving the service layer ? >>=20 >> If so these are not without significant cost on the server side. >>=20 >> Dave Cramer >>=20 >> dave.cramer(at)credativ(dot)ca >> http://www.credativ.ca >>=20 >> On 12 November 2014 10:22, Marko Topolnik wro= te: >> As of the release of Java 8 and its Streams API a new door has opened fo= r many things, including an important improvement in the way RESTful servic= es can be implemented. Let me briefly describe the architecture with Spring= 's REST support: an MVC framework is used where the Controller dispatches t= he HTTP request to a Service method; the Service method contacts the databa= se and returns a Model-oriented representation of the response; the View la= yer then transforms it into the actual HTTP response bytes. >>=20 >> Data is passed from Controller to View as the return value of a method. = Traditionally, if you wanted a collection-shaped response, you would return= a List. This meant eager loading of all data needed for the response, whic= h caused scalability issues related to the JVM heap space. >>=20 >> With the Streams API it is now very convenient to return a lazily-evalua= ted stream of Model objects. It is also very convenient to make this stream= pull data directly from an underlying ResultSet, tronsforming each row on-= the-fly into a Model object. This, however, calls for holdable result sets = because the transaction commits when program control leaves the Service lay= er. >>=20 >> The Spring team has recognized the relevance of the above use case and w= ith release 4.1.2 they have introduced a specific enhancement needed to sup= port result sets holdable into the View layer (albeit only when JDBC is use= d over Hibernate). This is described in the issue SPR-12349 [1]. Spring als= o plans to support this use case with additional helper code which turns Hi= bernate's ScrollableResults into a Stream (SPR-12388 [2]). >>=20 >> The above could raise the level of interest of the PostgreSQL JDBC team = in implementing holdable result sets backed by native holdable cursors inst= ead of the current client-side cursors, which don't allow the space complex= ity to be reduced from O(n) to O(1) on the JVM side. I am aware that this i= s not a trivial endeavor as it requires intervention into the FE/BE protoco= l, but I would nevertheless propose that this concern be reassessed in the = light of new developments in the Java ecosystem. >>=20 >> Regards, >> Marko Topolnik >>=20 >>=20 >>=20 >> [1] https://jira.spring.io/browse/SPR-12349 >> [2] https://jira.spring.io/browse/SPR-12388 >>=20 >> -- >> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) >> To make changes to your subscription: >> http://www.postgresql.org/mailpref/pgsql-jdbc >>=20 >=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