> >Here is a trick I use sometimes with views, etc. This may or may not
> >effective to solve your problem but it's worth a shot. Create one
> >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
> I would most appreciate if you could define a sample function and
> the VCurPlayer view above. Both PlayerID and AtDate are varchar
> esdt=> explain analyze select PlayerID,AtDate from Player a
> where PlayerID='22220' and AtDate = (select b.AtDate from Player b
> where b.PlayerID = '22220' order by b.PlayerID desc, b.AtDate desc
create function player_max_at_date (varchar) returns date as
select atdate from player where playerid = $1 order by playerid
desc, AtDate desc limit 1;
$$ language sql immutable;
create view v as select playerid, player_max_at_date(playerid) from
select * from v where playerid = 'x'; --etc
note: this function is not really immutable. try with both 'immutable'
and 'stable' if performance is same, do stable.
You're welcome in advance, ;)
pgsql-performance by date
|Next:||From: Kevin Grittner||Date: 2005-09-22 18:19:56|
|Subject: Re: SELECT LIMIT 1 VIEW Performance Issue|
|Previous:||From: Antoine Bajolet||Date: 2005-09-22 17:52:54|
|Subject: Re: Nested Loop trouble : Execution time increases more|