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 428C33A62DD for ; Sat, 11 Dec 2004 16:25:51 +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 70766-10 for ; Sat, 11 Dec 2004 16:25:45 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 917953A3BA1 for ; Sat, 11 Dec 2004 16:25:44 +0000 (GMT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.1/8.13.1) with ESMTP id iBBGPesW005883 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 11 Dec 2004 09:25:43 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.1/8.13.1) with ESMTP id iBBGPexY072943 for ; Sat, 11 Dec 2004 09:25:40 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id iBBGPdBV072942 for pgsql-performance@postgresql.org; Sat, 11 Dec 2004 09:25:39 -0700 (MST) (envelope-from mfuhr) Date: Sat, 11 Dec 2004 09:25:39 -0700 From: Michael Fuhr To: pgsql-performance@postgresql.org Subject: Re: [GENERAL] Query is not using index when it should Message-ID: <20041211162539.GA66539@winnie.fuhr.org> References: <80oeh2tm7x.fsf@junk.nocrew.org> <20041210182453.G92467@megazone.bigpanda.com> <80d5xgudg6.fsf@junk.nocrew.org> <20041211143213.GA2659@uio.no> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20041211143213.GA2659@uio.no> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200412/147 X-Sequence-Number: 9522 On Sat, Dec 11, 2004 at 03:32:13PM +0100, Steinar H. Gunderson wrote: > 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... I've seen that in generated queries. The generating program uses "WHERE 1=1" to simplify the addition of other conditions: instead of checking if it needs to add a WHERE and putting ANDs in the right places, it simply appends subsequent conditions with " AND condition". -- Michael Fuhr http://www.fuhr.org/~mfuhr/