Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 5884D9FB255 for ; Tue, 9 Jan 2007 19:42:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 69237-01 for ; Tue, 9 Jan 2007 19:42:04 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id D40279FB251 for ; Tue, 9 Jan 2007 19:42:07 -0400 (AST) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Tue, 9 Jan 2007 23:42:04 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 09 Jan 2007 17:42:04 -0600 Subject: Re: group by will not use an index? From: Scott Marlowe To: tsuraan Cc: pgsql-performance In-Reply-To: <84fb38e30701091505n59e85c74i27e6ab0e5cdfdd03@mail.gmail.com> References: <84fb38e30701091505n59e85c74i27e6ab0e5cdfdd03@mail.gmail.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1168386124.20602.185.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Tue, 09 Jan 2007 17:42:04 -0600 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/124 X-Sequence-Number: 22725 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.