Re: Optimizing query - Mailing list pgsql-general

From Peter Eisentraut
Subject Re: Optimizing query
Date
Msg-id Pine.LNX.4.44.0311191320360.20187-100000@peter.localdomain
Whole thread Raw
In response to Optimizing query  (Uros <uros@sir-mag.com>)
List pgsql-general
Uros writes:

> explain SELECT count(*) as views FROM stat_views WHERE date_part('day', created) = 18;
>
>                                      QUERY PLAN
> ------------------------------------------------------------------------------------
>  Aggregate  (cost=100101618.08..100101618.08 rows=1 width=0)
>    ->  Seq Scan on stat_views  (cost=100000000.00..100101565.62 rows=20984 width=0)
>          Filter: (date_part('day'::text, created) = 18::double precision)

Create an index on date_part('day', created).  In 7.3 and earlier you need
to create a wrapper function and index that, in 7.4 you can index
arbitrarz expressions directly.  The documentation contains more
information about that.

--
Peter Eisentraut   peter_e@gmx.net


pgsql-general by date:

Previous
From: "Matthew Lunnon"
Date:
Subject: Re: Optimizing query
Next
From: Shridhar Daithankar
Date:
Subject: Re: Optimizing query