Re: group by will not use an index?

From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: tsuraan <tsuraan(at)gmail(dot)com>
Cc: pgsql-performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: group by will not use an index?
Date: 2007-01-09 23:42:04
Message-ID: 1168386124.20602.185.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Brian Herlihy 2007-01-10 01:07:03 Re: group by will not use an index?
Previous Message Gregory S. Williamson 2007-01-09 23:40:51 Re: Horribly slow query/ sequential scan