X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id DBB2B534A6 for ; Tue, 19 Apr 2005 00:10:24 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 09067-04 for ; Tue, 19 Apr 2005 03:10:18 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 1312653405 for ; Tue, 19 Apr 2005 00:10:17 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j3J3A10t030251 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 18 Apr 2005 21:10:04 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j3J3A1Ks075768; Mon, 18 Apr 2005 21:10:01 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j3J3A1d2075767; Mon, 18 Apr 2005 21:10:01 -0600 (MDT) (envelope-from mfuhr) Date: Mon, 18 Apr 2005 21:10:01 -0600 From: Michael Fuhr To: =?iso-8859-1?Q?R=FCdiger?= Herrmann Cc: pgsql-performance@postgresql.org Subject: Re: refcurosr vs. setof Message-ID: <20050419031001.GA75716@winnie.fuhr.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.004 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/447 X-Sequence-Number: 11844 On Sun, Apr 17, 2005 at 10:05:29PM +0200, Rüdiger Herrmann wrote: > > I need to write several PL/pgSQL functions all returning a "result set" wich > can be obtained by a single SELECT statement. > For now the functions are called by a Java application. > Both REFCURSOR and SETOF serve my purpose, but I was wondering if there is a > perfonance difference between the two. The result set can become quite > large. Here's an excerpt from the "Control Structures" section of the PL/pgSQL documentation: The current implementation of RETURN NEXT for PL/pgSQL stores the entire result set before returning from the function, as discussed above. That means that if a PL/pgSQL function produces a very large result set, performance may be poor: data will be written to disk to avoid memory exhaustion, but the function itself will not return until the entire result set has been generated....Currently, the point at which data begins being written to disk is controlled by the work_mem configuration variable. You might want to test both ways in typical and worst-case scenarios and see how each performs. -- Michael Fuhr http://www.fuhr.org/~mfuhr/