pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Simon Riggs <simon@2ndquadrant.com>
To: K C Lau <kclau60@netvigator.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: SELECT LIMIT 1 VIEW Performance Issue
Date: Fri, 23 Sep 2005 12:15:41 +0100
Message-ID: <1127474141.19345.10.camel@localhost.localdomain> (raw)
In-Reply-To: <6.2.1.2.0.20050922181009.02c36ca8@localhost>
References: <6.2.1.2.0.20050615100524.04f9d6a8@localhost>
	<6.2.1.2.0.20050922102035.07bcf2e0@localhost>
	<1127378456.4145.76.camel@localhost.localdomain>
	<6.2.1.2.0.20050922181009.02c36ca8@localhost>

On Thu, 2005-09-22 at 18:40 +0800, K C Lau wrote: 
> > > esdt=> explain analyze select PlayerID,AtDate from Player a
> > >   where PlayerID='22220' and AtDate = (select b.AtDate from Player b
> > >   where b.PlayerID = a.PlayerID order by b.PlayerID desc, b.AtDate desc
> > > LIMIT 1);

I think you should try:

select distinct on (PlayerID) PlayerID,AtDate from Player a
where PlayerID='22220' order by PlayerId, AtDate Desc;

Does that work for you?

Best Regards, Simon Riggs




view thread (27+ messages)  latest in thread

Message-ID: <1127474141.19345.10.camel@localhost.localdomain>
Permalink:  ../1127474141.19345.10.camel@localhost.localdomain/
Also on:    postgresql.org/message-id/1127474141.19345.10.camel@localhost.localdomain

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: simon@2ndquadrant.com, kclau60@netvigator.com
  Subject: Re: SELECT LIMIT 1 VIEW Performance Issue
  In-Reply-To: <1127474141.19345.10.camel@localhost.localdomain>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox