X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 0865AD1BBA2 for ; Mon, 5 Apr 2004 16:27:00 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 38980-10 for ; Mon, 5 Apr 2004 13:27:27 -0300 (ADT) Received: from jefftrout.com (h00a0cc4084e5.ne.client2.attbi.com [24.128.241.68]) by svr1.postgresql.org (Postfix) with SMTP id 46098D1B560 for ; Mon, 5 Apr 2004 13:26:56 -0300 (ADT) Received: (qmail 37033 invoked from network); 5 Apr 2004 16:27:38 -0000 Received: from unknown (HELO ?192.168.0.4?) (10.10.10.177) by 10.10.10.10 with SMTP; 5 Apr 2004 16:27:38 -0000 Mime-Version: 1.0 (Apple Message framework v609) Content-Transfer-Encoding: 7bit Message-Id: <49B1B198-871E-11D8-B8C1-000393D1F76E@torgo.978.org> Content-Type: text/plain; charset=US-ASCII; format=flowed To: pgsql-performance@postgresql.org From: Jeff Subject: SETOF performance Date: Mon, 5 Apr 2004 12:28:36 -0400 X-Mailer: Apple Mail (2.609) X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200404/40 X-Sequence-Number: 6340 I think it was on this list - someone posted a message about SETOF being slower. Tom replied saying it was because it needed to create an on-disk tuplestore. I was just looking for some clarification - a SETOF function will always write the reslting tuples to disk (Not buffering in say a sort_mem sized buffer)? I think if that is the case I may need to go back and change some stuff around. I have a procedure that I broke out a bit to make life easier. Basically it goes for v_row in select blah from function_that_gets_data_from_some_cache(....) rowcount := rowcount + 1; return next v_row; end for; if rowcount = 0 then [same thing, but we call some_function_that_creates_data_for_cache] end if; Doing it this way means I avoid having to deal with it in the client and I also avoid having a giant stored procedure. (I like short & sweet things) What I've found for timings is this: select * from function_that_gets_data_from_some_cache() runs around 1.8 ms but select * from the_top_level_function() runs around 4.2ms (Yes, I know 4.2 ms is fast, but that is not the point). could this overhead be related to the SETOF tuplestores? Might it be better to use refcursor or something or bite the bullet and live with a giant procedure? -- Jeff Trout http://www.jefftrout.com/ http://www.stuarthamm.net/