pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: eg@tzv.fal.de
To: pgsql-interfaces@postgreSQL.org
Subject: Re: [INTERFACES] Postmaster getting veeeery big
Date: Wed, 19 May 1999 17:40:42 +0300
Message-ID: <l03130304b3687a4f6aa7@[147.233.159.109]> (raw)
In-Reply-To: <99051811205503.00540@salo.tzv.fal.de>

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





view thread (2+ messages)

Message-ID: <l03130304b3687a4f6aa7@[147.233.159.109]>
Permalink:  ../l03130304b3687a4f6aa7@%5B147.233.159.109%5D/
Also on:    postgresql.org/message-id/l03130304b3687a4f6aa7@[147.233.159.109]

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-interfaces@postgresql.org
  Cc: herouth@oumail.openu.ac.il, eg@tzv.fal.de
  Subject: Re: [INTERFACES] Postmaster getting veeeery big
  In-Reply-To: <l03130304b3687a4f6aa7@[147.233.159.109]>
  References: <99051811205503.00540@salo.tzv.fal.de> <l03130304b3687a4f6aa7@[147.233.159.109]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox