On Mon, 27 Aug 2001, Joseph Shraibman wrote:

> Stephan Szabo wrote:
> > I think you'd want to move the entire query excepting the lastml where
> > condition into a single subselect in the outer from with the lastml
> > condition on the outside:
> >  select * from (<old query minus lastml condition>) as blah where
> >   lastml=2;
> > 
> > However, I don't think this changes the computation that it's doing
> > (simple example explains still show two subquery runs).
> > 
> 
> Yep, that works.  I wasn't familiar with how the subselect in the from part works.  
>But as 
> you say an explain still shows it doing the index scan twice.
> 
>  From the postgres docs:
> 
>       A sub-SELECT can appear in the FROM clause. This acts as though its output 
>were 
> created as a temporary table for the duration of this single SELECT command. Note 
>that the 
> sub-SELECT must be surrounded by parentheses, and an alias must  be provided for it.
> 
> So does postgres actually use a temporary table behind the scenses?  It appears not.

I think what's happening is that the where condition is being pushed down
into the subselect because usually that's the correct optimization, since
you'd normally want 
 select col1 from (select col1 from foo) as foo2 where col1=2; 
to do an index scan on foo.


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Reply via email to