Re: Optimizing query

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Uros <uros(at)sir-mag(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Optimizing query
Date: 2003-11-19 12:21:52
Message-ID: Pine.LNX.4.44.0311191320360.20187-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)gmx(dot)net

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Shridhar Daithankar 2003-11-19 12:23:26 Re: Optimizing query
Previous Message Matthew Lunnon 2003-11-19 11:44:01 Re: Optimizing query