Re: INDEX suggestion needed - Mailing list pgsql-general

From Manfred Koizar
Subject Re: INDEX suggestion needed
Date
Msg-id ja5kvuo09052ldtp94maadc7shmhr5vg6t@4ax.com
Whole thread Raw
In response to Re: INDEX suggestion needed  (Alvaro Herrera <alvherre@dcc.uchile.cl>)
Responses Re: INDEX suggestion needed  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: INDEX suggestion needed  (Thomas Beutin <tyrone@laokoon.IN-Berlin.DE>)
List pgsql-general
On Fri, 13 Dec 2002 13:00:14 -0300, Alvaro Herrera
<alvherre@dcc.uchile.cl> wrote:
>Now this catched my attention (in the questions' side, sorry, not the
>answers').  Why the aggregate takes 10 times the time needed for the
>indexscan?

Good point!

>  One would think that a function like count() should be
>pretty cheap,

COUNT is cheap.  But COUNT(DISTINCT something) is not trivial, it has
to keep a list of all values it has already counted.  I didn't look at
the implementation.  Do we have O(n^2) cost here?

Thomas, could you EXPLAIN ANALYZE some test cases with

    SELECT COUNT(*) FROM (
        SELECT DISTINCT a_id
          FROM stat_pages
         WHERE ...
    ) AS x;

and compare them to the results of SELECT COUNT(DISTINCT ...)?

So now you are back where you started.  At least you have an index on
"visit" now ;-)

Servus
 Manfred

pgsql-general by date:

Previous
From: Manfred Koizar
Date:
Subject: Re: INDEX suggestion needed
Next
From: Steve Crawford
Date:
Subject: \dD Bug??