X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 1F1F19FA5DD for ; Thu, 8 Jun 2006 16:20:29 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 16943-10 for ; Thu, 8 Jun 2006 16:20:25 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from zeus.gigaweb.cz (zeus.gigaweb.cz [81.0.236.19]) by postgresql.org (Postfix) with SMTP id 965249FA4D8 for ; Thu, 8 Jun 2006 16:20:24 -0300 (ADT) Received: (qmail 374 invoked from network); 8 Jun 2006 19:20:24 -0000 Received: from unknown (HELO ?192.168.1.101?) (89.102.195.181) by 0 with SMTP; 8 Jun 2006 19:20:24 -0000 Message-ID: <44887875.8000502@fuzzy.cz> Date: Thu, 08 Jun 2006 21:20:21 +0200 From: Tomas Vondra User-Agent: Mail/News 1.5 (X11/20060424) MIME-Version: 1.0 To: Andrus CC: pgsql-performance@postgresql.org Subject: Re: Why date index is not used References: In-Reply-To: X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-2 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/99 X-Sequence-Number: 19456 More precisely - the Postgres could use the index to speed up the sorting, but in this case the sorting is very fast (less than one second according to the output), so Postgres probably decided not to use the index because it would be slower. Btw. have you run ANALYZE on the table recently? What is the number of distinct values in the 'kuupaev' column? Tomas > Why Postgres 8.1 does not use makse_kuupaev_idx index in the following query > ? > > How to speed this query up ? > > explain analyze select * from makse order by kuupaev desc, kellaaeg desc > limit 100 > > "Limit (cost=62907.94..62908.19 rows=100 width=876) (actual > time=33699.551..33701.001 rows=100 loops=1)" > " -> Sort (cost=62907.94..63040.49 rows=53022 width=876) (actual > time=33699.534..33700.129 rows=100 loops=1)" > " Sort Key: kuupaev, kellaaeg" > " -> Seq Scan on makse (cost=0.00..2717.22 rows=53022 width=876) > (actual time=0.020..308.502 rows=53028 loops=1)" > "Total runtime: 37857.177 ms" > > > CREATE TABLE makse( > kuupaev date, > kellaaeg char(6) NOT NULL DEFAULT ''::bpchar, > guid char(36) NOT NULL, > CONSTRAINT makse_pkey PRIMARY KEY (guid) ) > > > CREATE INDEX makse_kuupaev_idx ON makse USING btree (kuupaev); > > > Andrus.