Skip site navigation (1) Skip section navigation (2)

Re: [GENERAL] Query is not using index when it should

From: "Steinar H(dot) Gunderson" <sgunderson(at)bigfoot(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: [GENERAL] Query is not using index when it should
Date: 2004-12-11 14:32:13
Message-ID: 20041211143213.GA2659@uio.no (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-performancepgsql-sql
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/

In response to

Responses

pgsql-performance by date

Next:From: Mike RylanderDate: 2004-12-11 14:37:15
Subject: Re: LIMIT causes SEQSCAN in subselect
Previous:From: Tomas =?iso-8859-1?q?Sk=E4re?=Date: 2004-12-11 14:17:13
Subject: Re: Query is not using index when it should

pgsql-sql by date

Next:From: Stephan SzaboDate: 2004-12-11 15:47:51
Subject: Re: replacing mysql enum
Previous:From: Tomas =?iso-8859-1?q?Sk=E4re?=Date: 2004-12-11 14:17:13
Subject: Re: Query is not using index when it should

pgsql-general by date

Next:From: Ioannis TheoharisDate: 2004-12-11 15:27:02
Subject: Clustering in the presence of hierarchies (fwd)
Previous:From: Tomas =?iso-8859-1?q?Sk=E4re?=Date: 2004-12-11 14:17:13
Subject: Re: Query is not using index when it should

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group