X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 1F2D2D1CA90 for ; Thu, 29 Jan 2004 13:32:12 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 26874-04 for ; Thu, 29 Jan 2004 09:31:49 -0400 (AST) Received: from matrix.gatewaynet.com (unknown [217.19.69.50]) by svr1.postgresql.org (Postfix) with ESMTP id EA956D1B4DA for ; Thu, 29 Jan 2004 09:31:38 -0400 (AST) Received: from matrix.gatewaynet.com (localhost.localdomain [127.0.0.1]) by matrix.gatewaynet.com (8.12.8/8.12.8) with ESMTP id i0TDTBSD009980; Thu, 29 Jan 2004 15:29:11 +0200 Received: from localhost (achill@localhost) by matrix.gatewaynet.com (8.12.8/8.12.8/Submit) with ESMTP id i0TDTBNP009976; Thu, 29 Jan 2004 15:29:11 +0200 Date: Thu, 29 Jan 2004 15:29:11 +0200 (EET) From: Achilleus Mantzios To: Bruno Wolff III Cc: email lists , Subject: Re: query not using index for descending records? In-Reply-To: <20040129131847.GE17068@wolff.to> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/257 X-Sequence-Number: 16650 O kyrios Bruno Wolff III egrapse stis Jan 29, 2004 : As i see there was a thread http://archives.postgresql.org/pgsql-hackers/2003-05/msg00762.php dealing with this issue, assuming the "correct" order by should be "order by datetime ASC, id DESC". Do you know of any progress for declaring the direction of each column in a multicolumn index? > On Thu, Jan 29, 2004 at 22:18:08 +1000, > email lists wrote: > > Limit (cost=0.00..2.31 rows=20 width=12) > > -> Index Scan using idx_trafficlogs_datetime_id on trafficlogs > > (cost=0.00..1057.89 rows=9172 width=12) > > (2 rows) > > > > however, I am wanting to return the last 20 records. I have been using: > > > > explain select datetime,id from trafficlogs order by datetime,id desc > > limit 20; > > You probably don't want to do that. The DESC only applies to the one > expression it follows. What you want is probably: > explain select datetime,id from trafficlogs order by datetime desc,id desc > limit 20; > > The index won't get used because with id and datetime being checked in > different orders, only the first part of the index is usable. And probably > that wasn't selective enough for an index scan to be used. > > ---------------------------(end of broadcast)--------------------------- > TIP 9: the planner will ignore your desire to choose an index scan if your > joining column's datatypes do not match > -- -Achilleus