X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 40F843A62A8 for ; Sat, 11 Dec 2004 14:32:27 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 49451-02 for ; Sat, 11 Dec 2004 14:32:13 +0000 (GMT) Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [129.241.93.19]) by svr1.postgresql.org (Postfix) with ESMTP id 060173A62E8 for ; Sat, 11 Dec 2004 14:32:16 +0000 (GMT) Received: from trofast.sesse.net ([129.241.93.32]) by cassarossa.samfundet.no with esmtp (Exim 4.34) id 1Cd8IA-0001er-2Q for pgsql-performance@postgresql.org; Sat, 11 Dec 2004 15:32:15 +0100 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1Cd8I9-0000ih-00 for ; Sat, 11 Dec 2004 15:32:13 +0100 Date: Sat, 11 Dec 2004 15:32:13 +0100 From: "Steinar H. Gunderson" To: pgsql-performance@postgresql.org Subject: Re: [GENERAL] Query is not using index when it should Message-ID: <20041211143213.GA2659@uio.no> Mail-Followup-To: pgsql-performance@postgresql.org References: <80oeh2tm7x.fsf@junk.nocrew.org> <20041210182453.G92467@megazone.bigpanda.com> <80d5xgudg6.fsf@junk.nocrew.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <80d5xgudg6.fsf@junk.nocrew.org> X-Operating-System: Linux 2.6.8.1 on a i686 User-Agent: Mutt/1.5.6+20040907i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200412/145 X-Sequence-Number: 9520 On Sat, Dec 11, 2004 at 03:17:13PM +0100, Tomas Skäre wrote: > select c.* from cjm_object c > inner join > (select max(timestamp) as timestamp,objectid,field from cjm_object > group by objectid,field) t > using(timestamp,objectid,field) > where 1=1 and data is not null > order by objectid,field; Usually, SELECT max(field) FROM table is better written in PostgreSQL as SELECT field FROM table ORDER field DESC LIMIT 1. I don't see the point of "where 1=1", though... /* Steinar */ -- Homepage: http://www.sesse.net/