Re: SELECT LIMIT 1 VIEW Performance Issue - Mailing list pgsql-performance

From Merlin Moncure
Subject Re: SELECT LIMIT 1 VIEW Performance Issue
Date
Msg-id 6EE64EF3AB31D5448D0007DD34EEB3417DD3FF@Herge.rcsinc.local
Whole thread Raw
In response to SELECT LIMIT 1 VIEW Performance Issue  (K C Lau <kclau60@netvigator.com>)
Responses Re: SELECT LIMIT 1 VIEW Performance Issue
List pgsql-performance
> >I previously posted the following as a sequel to my SELECT DISTINCT
> >Performance Issue question. We would most appreciate any clue or
> >suggestions on how to overcome this show-stopping issue. We are using
> >8.0.3 on Windows.
> >
> >Is it a known limitation when using a view with SELECT ... LIMIT 1?
> >
> >Would the forthcoming performance enhancement with MAX help when used
> >within a view, as in:
> >
> >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.

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

pgsql-performance by date:

Previous
From: Simon Riggs
Date:
Subject: Re: SELECT LIMIT 1 VIEW Performance Issue
Next
From: K C Lau
Date:
Subject: Re: SELECT LIMIT 1 VIEW Performance Issue