Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xod7v-0007th-2V for pgsql-jdbc@arkaria.postgresql.org; Wed, 12 Nov 2014 18:58:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xod7u-0007qB-FE for pgsql-jdbc@arkaria.postgresql.org; Wed, 12 Nov 2014 18:58:46 +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 1Xod7t-0007q4-D1 for pgsql-jdbc@postgresql.org; Wed, 12 Nov 2014 18:58:45 +0000 Received: from mail-wi0-x22b.google.com ([2a00:1450:400c:c05::22b]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Xod7p-0005XS-Sm for pgsql-jdbc@postgresql.org; Wed, 12 Nov 2014 18:58:43 +0000 Received: by mail-wi0-f171.google.com with SMTP id r20so5919525wiv.16 for ; Wed, 12 Nov 2014 10:58:40 -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=MW8b85zCsLUIekPCHG22ocSDZDbzpzrmHBi9haZGBVQ=; b=npIxaZshJgXy1gQ1fhUuR6tM+H9ziIE50BMGHLcu90MagWimfhSg4Lpf0S9D94dDTu TrBflPqm8Sd1kgkmPI/KMxPlcErrfV24WACqtk26Vt6wbDmC6SbYZ9IQtrqe1dfpEMpu EQtk+xe/9dwF6PfUK/zFTLwR18QL7U1TcYRopx61qjmHasedAd3fm/oBhXsf+giOVr+s IPH4CBfmUDIj8mJOaQcCgnwVm8HMyefPbXi5wYNM44IOazNe6fulcqPzsanhXv8dNrvI lHYMUiitlEteTnMcdNnQ0vVllVHWu6+INSQgKhIlqg/jfX9BJQJCRGUFpnebMUAperZS aAzA== X-Received: by 10.180.14.165 with SMTP id q5mr8096745wic.0.1415818720202; Wed, 12 Nov 2014 10:58:40 -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 p1sm32508844wjy.22.2014.11.12.10.58.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Nov 2014 10:58:39 -0800 (PST) Content-Type: text/plain; charset=us-ascii 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: Date: Wed, 12 Nov 2014 19:58:33 +0100 Cc: List Content-Transfer-Encoding: quoted-printable Message-Id: <63F72575-DB78-45FF-B1BD-6C67C311A86B@gmail.com> References: <771672CB-9567-4966-8CE9-9D84E4F858D8@gmail.com> To: Dave Cramer 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, that is correct, Dave. The transaction would have to commit and the cu= rsor would have to live on until the JDBC connection is released back to th= e pool. I am aware that this transfers the cost from the JVM into PG; howev= er I also think that PG is in a much better position to fine-tune its polic= ies around this concern.=20 Even if comparing RAM-only solutions at either end, PG would almost surely = take less RAM to hold the data in its native form than the JVM uses to hold= the client-side cursor; and further, PG would have much better opportuniti= es to overflow to disk than the JDBC driver, which probably doesn't have th= at option at all. -- Marko Topolnik On 12. stu. 2014., at 19:51, Dave Cramer wrote: > Marko, >=20 > When you say holdable cursors are you referring to a holdable cursor outs= ide of a transaction? It seems so because the transaction commits after lea= ving 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 wrot= e: > As of the release of Java 8 and its Streams API a new door has opened for= many things, including an important improvement in the way RESTful service= s can be implemented. Let me briefly describe the architecture with Spring'= s REST support: an MVC framework is used where the Controller dispatches th= e HTTP request to a Service method; the Service method contacts the databas= e and returns a Model-oriented representation of the response; the View lay= er then transforms it into the actual HTTP response bytes. >=20 > Data is passed from Controller to View as the return value of a method. T= raditionally, if you wanted a collection-shaped response, you would return = a List. This meant eager loading of all data needed for the response, which= caused scalability issues related to the JVM heap space. >=20 > With the Streams API it is now very convenient to return a lazily-evaluat= ed stream of Model objects. It is also very convenient to make this stream = pull data directly from an underlying ResultSet, tronsforming each row on-t= he-fly into a Model object. This, however, calls for holdable result sets b= ecause the transaction commits when program control leaves the Service laye= r. >=20 > The Spring team has recognized the relevance of the above use case and wi= th release 4.1.2 they have introduced a specific enhancement needed to supp= ort result sets holdable into the View layer (albeit only when JDBC is used= over Hibernate). This is described in the issue SPR-12349 [1]. Spring also= plans to support this use case with additional helper code which turns Hib= ernate's ScrollableResults into a Stream (SPR-12388 [2]). >=20 > The above could raise the level of interest of the PostgreSQL JDBC team i= n implementing holdable result sets backed by native holdable cursors inste= ad of the current client-side cursors, which don't allow the space complexi= ty 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 protocol= , but I would nevertheless propose that this concern be reassessed in the l= ight 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 Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc