Received: from mx99.openu.ac.il (arbel.openu.ac.il [147.233.32.4]) by hub.org (8.9.3/8.9.3) with ESMTP id KAA07673 for ; Wed, 19 May 1999 10:40:31 -0400 (EDT) (envelope-from herouth@oumail.openu.ac.il) Received: from talmon.openu.ac.il (talmon.openu.ac.il [147.233.32.11]) by mx99.openu.ac.il (Postfix) with ESMTP for id C57C64B5E4; Wed, 19 May 1999 17:40:29 +0300 (IDT) Received: from [147.233.159.109] (mac-herouth.pc.openu.ac.il) by talmon.openu.ac.il (Netscape Messaging Server 3.54) with ESMTP id AAA3C42; Wed, 19 May 1999 17:42:51 +0300 X-Sender: herouth@shaked.cc.openu.ac.il Message-Id: In-Reply-To: <99051811205503.00540@salo.tzv.fal.de> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Wed, 19 May 1999 17:40:42 +0300 To: eg@tzv.fal.de, pgsql-interfaces@postgreSQL.org From: Herouth Maoz Subject: Re: [INTERFACES] Postmaster getting veeeery big At 12:05 +0300 on 18/05/1999, Eildert Groeneveld wrote: > > Hello everyone, > we observe a problem when doing some sort of aggregation like > > select distinct count(substr(narodene,5,4)) from raw_field; > > (raw_field has 1300000 rows) > > > On executing this query the postmaster grows in memory size until it runs > out of virtual mem and dies. > > Any ideas of what is going on and how to avoid this? No matter what the memory problem is (memory used for the substr function not released, probably), I think your query is wrong. I think what you wanted was the count of the distinct substrings. But that's "count distinct" (which is not implemented in PostgreSQL yet) and not "distinct count". Distinct count only has meaning in a group-by query. So you should probably rephrase your query as: SELECT count(*) FROM raw_field r1 WHERE int4( r1.oid ) = ( SELECT max( in4(oid) ) FROM raw_field r2 WHERE substr( r1.narodene,5,4) = substr( r2.narodene,5,4) ); The WHERE clause will only become true when the current row has the maximal oid for the same substring of narodene. In effect, it selects one row for each substring. Thus you will get the count of the distinct substrings. Herouth -- Herouth Maoz, Internet developer. Open University of Israel - Telem project http://telem.openu.ac.il/~herutma