X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 69D5CD1B16A for ; Sun, 23 May 2004 15:33:10 -0300 (ADT) 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 90501-09 for ; Sun, 23 May 2004 15:32:51 -0300 (ADT) Received: from dyatel.antar.bryansk.ru (unknown [195.239.214.85]) by svr1.postgresql.org (Postfix) with ESMTP id AC3DDD1B534 for ; Sun, 23 May 2004 15:32:49 -0300 (ADT) Received: from fduch by dyatel.antar.bryansk.ru with local (Exim 4.32; FreeBSD) id 1BRxmE-000FYd-0x; Sun, 23 May 2004 22:32:50 +0400 Date: Sun, 23 May 2004 22:32:49 +0400 From: "Alexander M. Pravking" To: Tom Lane Cc: pgsql-sql@postgresql.org Subject: Re: Memory usage on subselect Message-ID: <20040523183249.GC54296@dyatel.antar.bryansk.ru> References: <20040522175419.GB54296@dyatel.antar.bryansk.ru> <24527.1085329698@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline In-Reply-To: <24527.1085329698@sss.pgh.pa.us> User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200405/202 X-Sequence-Number: 17916 On Sun, May 23, 2004 at 12:28:18PM -0400, Tom Lane wrote: > "Alexander M. Pravking" writes: > > I've got a memory usage problem when I try to do a subselect on the same > > table as the main select (PostgreSQL 7.3.4 on FreeBSD). Here's my query: > > ... > > The "services" table is indexed only on "id" column and has about a > > thousand tuples. sreq(integer, text, timestamptz) is a strict immutable > > function written in SQL. > > IIRC, there were intraquery memory leaks associated with SQL-language > functions until fairly recently. Can you try your problem case on 7.4? > Or see if you can rewrite the sreq function in plpgsql. Thanks, Tom, both 7.4.1 and plpgsql function on 7.3.4 work well. However, plpgsql function is a little slower, but that's another story. I also tried to turn off IMMUTABLE for the function, but it did not affect memory usage on 7.3.4. BTW, after cancelling the original query postgres freed all the memory, and used ~7M again, so the leak was not "forever". Good luck, thansk again ;) -- Fduch M. Pravking