Re: [GENERAL] Query is not using index when it should - Mailing list pgsql-performance

From Steinar H. Gunderson
Subject Re: [GENERAL] Query is not using index when it should
Date
Msg-id 20041211143213.GA2659@uio.no
Whole thread Raw
In response to Re: [GENERAL] Query is not using index when it should  (tomas@nocrew.org (Tomas Skäre))
Responses Re: [GENERAL] Query is not using index when it should  (Michael Fuhr <mike@fuhr.org>)
Re: [GENERAL] Query is not using index when it should  (tomas@nocrew.org (Tomas Skäre))
List pgsql-performance
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/

pgsql-performance by date:

Previous
From: tomas@nocrew.org (Tomas Skäre)
Date:
Subject: Re: [GENERAL] Query is not using index when it should
Next
From: Mike Rylander
Date:
Subject: Re: LIMIT causes SEQSCAN in subselect