Re: group by will not use an index? - Mailing list pgsql-performance

From Scott Marlowe
Subject Re: group by will not use an index?
Date
Msg-id 1168386124.20602.185.camel@state.g2switchworks.com
Whole thread Raw
In response to group by will not use an index?  (tsuraan <tsuraan@gmail.com>)
Responses Re: group by will not use an index?
List pgsql-performance
On Tue, 2007-01-09 at 17:05, tsuraan wrote:
> I have a table of messages with paths and inserted dates (among other
> things), like so:
>
> CREATE TABLE Messages (
>     msgkey BIGSERIAL PRIMARY KEY,
>     path TEXT NOT NULL,
>     inserted TIMESTAMP WITHOUT TIMEZONE DEFAULT NOW()
> );
>
> I run a query to determine which days actually saw emails come in,
> like so:
>
> SELECT DATE(inserted) FROM Messages GROUP BY DATE(inserted);

You're probably under the mistaken impression that PostgreSQL and can
retrieve all the data it needs from the index alone.  It can't.  Anytime
postgresql gets an index reference, it has to then visit the actual
table file to grab the individual entry.  That's because indexes don't
store mvcc visibility information, and due to the problems locking both
indexes and tables together would present, probably won't any time soon.

pgsql-performance by date:

Previous
From: "Gregory S. Williamson"
Date:
Subject: Re: Horribly slow query/ sequential scan
Next
From: Brian Herlihy
Date:
Subject: Re: group by will not use an index?