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 BF644DA826 for ; Thu, 22 Sep 2005 11:57:02 -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 92256-04 for ; Thu, 22 Sep 2005 14:56:58 +0000 (GMT) Received: from wmail05dat.netvigator.com (unknown [218.102.48.220]) by svr1.postgresql.org (Postfix) with ESMTP id DF68CD902F for ; Thu, 22 Sep 2005 11:56:59 -0300 (ADT) Received: from n2.netvigator.com ([218.102.147.167]) by wmail05dat.netvigator.com (InterMail vM.6.01.05.02 201-2131-123-102-20050715) with ESMTP id <20050922145703.YHZT18019.wmail05dat.netvigator.com@n2.netvigator.com>; Thu, 22 Sep 2005 22:57:03 +0800 Message-Id: <6.2.1.2.0.20050922224720.02c365f8@localhost> X-Mailer: QUALCOMM Windows Eudora Version 6.2.1.2 Date: Thu, 22 Sep 2005 22:56:47 +0800 To: "Merlin Moncure" From: K C Lau Subject: Re: SELECT LIMIT 1 VIEW Performance Issue Cc: In-Reply-To: <6EE64EF3AB31D5448D0007DD34EEB3417DD3FF@Herge.rcsinc.local> References: <6EE64EF3AB31D5448D0007DD34EEB3417DD3FF@Herge.rcsinc.local> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.528 required=5 tests=[AWL=-0.364, DNS_FROM_RFC_POST=1.376, FROM_ENDS_IN_NUMS=0.516] X-Spam-Level: * X-Archive-Number: 200509/240 X-Sequence-Number: 14548 At 22:37 05/09/22, Merlin Moncure wrote: > > >create or replace view VCurPlayer as select * from Player a > > >where a.AtDate = (select Max(b.AtDate) from Player b where a.PlayerID= > > >b.PlayerID); > >Here is a trick I use sometimes with views, etc. This may or may not be >effective to solve your problem but it's worth a shot. Create one small >SQL function taking date, etc. and returning the values and define it >immutable. Now in-query it is treated like a constant. We don't use functions as a rule, but I would be glad to give it a try. I would most appreciate if you could define a sample function and rewrite the VCurPlayer view above. Both PlayerID and AtDate are varchar fields. >Another useful application for this feature is when you have nested >views (view 1 queries view 2) and you need to filter records based on >fields from view 2 which are not returned in view 1. Impossible? > >in view 2 add clause where v2.f between f_min() and f_max(), them being >immutable functions which can grab filter criteria based on inputs or >values from a table. > >Merlin Best regards, KC.