X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E09E1DAB16 for ; Thu, 22 Sep 2005 15:20:09 -0300 (ADT) 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 11768-08 for ; Thu, 22 Sep 2005 18:20:06 +0000 (GMT) Received: from gwmta.wicourts.gov (gwmta.wicourts.gov [165.219.244.91]) by svr1.postgresql.org (Postfix) with ESMTP id B337DDAB2B for ; Thu, 22 Sep 2005 15:20:05 -0300 (ADT) Received: from Courts-MTA by gwmta.wicourts.gov with Novell_GroupWise; Thu, 22 Sep 2005 13:20:03 -0500 Message-Id: X-Mailer: Novell GroupWise Internet Agent 6.5.4 Date: Thu, 22 Sep 2005 13:19:56 -0500 From: "Kevin Grittner" To: , Subject: Re: SELECT LIMIT 1 VIEW Performance Issue Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.004 required=5 tests=[AWL=0.004] X-Spam-Level: X-Archive-Number: 200509/247 X-Sequence-Number: 14555 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: =20 select PlayerID,AtDate from Player a where PlayerID=3D'22220' and not exists (select * from Player b where b.PlayerID =3D a.PlayerID and b.AtDate > a.AtDate); =20 >>> K C Lau 09/21/05 11:21 PM >>> select PlayerID,AtDate from Player a where PlayerID=3D'22220' and AtDate =3D (select b.AtDate from Player b where b.PlayerID =3D a.PlayerID order by b.PlayerID desc, b.AtDate = desc=20 LIMIT 1);