Re: INDEX suggestion needed

From: Manfred Koizar <mkoi-pg(at)aon(dot)at>
To: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>
Cc: Thomas Beutin <tyrone(at)laokoon(dot)IN-Berlin(dot)DE>, pgsql-general(at)postgresql(dot)org
Subject: Re: INDEX suggestion needed
Date: 2002-12-13 17:37:59
Message-ID: ja5kvuo09052ldtp94maadc7shmhr5vg6t@4ax.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 13 Dec 2002 13:00:14 -0300, Alvaro Herrera
<alvherre(at)dcc(dot)uchile(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Steve Crawford 2002-12-13 17:57:47 \dD Bug??
Previous Message Manfred Koizar 2002-12-13 17:13:49 Re: INDEX suggestion needed