Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XodUA-0000KG-4R for pgsql-jdbc@arkaria.postgresql.org; Wed, 12 Nov 2014 19:21:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XodU9-0006Gj-Lf for pgsql-jdbc@arkaria.postgresql.org; Wed, 12 Nov 2014 19:21:45 +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 1XodU9-0006Gd-3O for pgsql-jdbc@postgresql.org; Wed, 12 Nov 2014 19:21:45 +0000 Received: from mail-wg0-x230.google.com ([2a00:1450:400c:c00::230]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XodU4-0006C6-75 for pgsql-jdbc@postgresql.org; Wed, 12 Nov 2014 19:21:44 +0000 Received: by mail-wg0-f48.google.com with SMTP id y19so4262410wgg.35 for ; Wed, 12 Nov 2014 11:21: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=qsvhaZJdXwxDUiP/ITcM2+Y8ra1ysrWG/jrzqwuw4cc=; b=zt2frtzmWNPc4JVjimOBgumz5CCTqHaUh2l+Pgh8D+/wuHWQ/X3H1D+JDzy2rz2qds vQPDN5kWpS8gZjPYWcdlxMtp9JttyZSTfyd5IDD6KckCpyY6VSfmacA+qcZ6BPxwwqHA aqxmuqQsvgmZkB1648iAmrfRSPWEMCR8OnHnb0FhUVj6THqzrt/H49PYAJlDzw9e2JHE 8aVib7AbWzvOiJqG4D0GX94Hj4A5ruc3M7Y0XKtiZ0mA4HvDNW78v75eHMfpVb0rZB5N 3Q54CaSYbP3MJeWnFXiS9feELy4d0ZYsyLBKUWGeJ+YXsakUZe5ukMWXN0/dkxgccLea wEzw== X-Received: by 10.180.91.49 with SMTP id cb17mr8368869wib.30.1415820099213; Wed, 12 Nov 2014 11:21:39 -0800 (PST) Received: from [192.168.1.101] (cpe-188-129-64-189.dynamic.amis.hr. [188.129.64.189]) by mx.google.com with ESMTPSA id u5sm22781584wiz.9.2014.11.12.11.21.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Nov 2014 11:21:38 -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: Marko Topolnik In-Reply-To: <36F5668B-7D36-40CB-BEEE-2F6C57633D30@gmail.com> Date: Wed, 12 Nov 2014 20:21:33 +0100 Cc: Kevin Wooten , Dave Cramer , List Content-Transfer-Encoding: quoted-printable Message-Id: <365BAE89-D32B-460E-844C-177234EB0DA4@gmail.com> References: <771672CB-9567-4966-8CE9-9D84E4F858D8@gmail.com> <36F5668B-7D36-40CB-BEEE-2F6C57633D30@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 On 12. stu. 2014., at 20:19, Steven Schlansker = wrote: >=20 > On Nov 12, 2014, at 10:58 AM, Kevin Wooten wrote: >=20 >> 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, transacti= ons, etc and would *only* cost for large result sets that need to extra rou= nd trips. >=20 > IMO LIMIT/OFFSET is generally strictly inferior to holding a transaction = open (like I proposed in my earlier mail) for anything that isn't reading r= ows 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 obser= ve e.g. duplicated or missing rows unless you are *very* careful. This is exactly the workaround I mention in my blog post, and those are exa= ctly the concerns I raise about it :) http://www.airpair.com/v1/posts/spring-streams-memory-efficiency >=20 >>=20 >> That being said=85 pgjdbc-ng uses real cursors when asked for them and r= espects the foldability requirement. There are limitations based on postgr= es=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 ou= tside of a transaction? It seems so because the transaction commits after l= eaving 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 wr= ote: >>> As of the release of Java 8 and its Streams API a new door has opened f= or many things, including an important improvement in the way RESTful servi= ces can be implemented. Let me briefly describe the architecture with Sprin= g's REST support: an MVC framework is used where the Controller dispatches = the HTTP request to a Service method; the Service method contacts the datab= ase and returns a Model-oriented representation of the response; the View l= ayer 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 retur= n a List. This meant eager loading of all data needed for the response, whi= ch caused scalability issues related to the JVM heap space. >>>=20 >>> With the Streams API it is now very convenient to return a lazily-evalu= ated stream of Model objects. It is also very convenient to make this strea= m 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 la= yer. >>>=20 >>> The Spring team has recognized the relevance of the above use case and = with release 4.1.2 they have introduced a specific enhancement needed to su= pport result sets holdable into the View layer (albeit only when JDBC is us= ed over Hibernate). This is described in the issue SPR-12349 [1]. Spring al= so plans to support this use case with additional helper code which turns H= ibernate'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 ins= tead of the current client-side cursors, which don't allow the space comple= xity to be reduced from O(n) to O(1) on the JVM side. I am aware that this = is not a trivial endeavor as it requires intervention into the FE/BE protoc= ol, 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 --=20 Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc