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