Re: SELECT LIMIT 1 VIEW Performance Issue

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: <kclau60(at)netvigator(dot)com>, <pgsql-performance(at)postgresql(dot)org>
Subject: Re: SELECT LIMIT 1 VIEW Performance Issue
Date: 2005-09-22 18:19:56
Message-ID: s332af83.045@gwmta.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Have you tried the "best choice" pattern -- where you select the set of
candidate rows and then exclude those for which a better choice
exists within the set? I often get better results with this pattern than
with the alternatives. Transmuting your query to use this patter gives:

select PlayerID,AtDate from Player a where PlayerID='22220'
and not exists
(select * from Player b
where b.PlayerID = a.PlayerID and b.AtDate > a.AtDate);

>>> K C Lau <kclau60(at)netvigator(dot)com> 09/21/05 11:21 PM >>>

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);

Browse pgsql-performance by date

  From Date Subject
Next Message Gurpreet Aulakh 2005-09-22 18:54:11 Re: Query slower on 8.0.3 (Windows) vs 7.3 (cygwin)
Previous Message Merlin Moncure 2005-09-22 18:07:38 Re: SELECT LIMIT 1 VIEW Performance Issue