Re: Performance of a view - Mailing list pgsql-general

From John McCawley
Subject Re: Performance of a view
Date
Msg-id 437CAAEE.2010808@hardgeus.com
Whole thread Raw
In response to Re: Performance of a view  ("Thomas F. O'Connell" <tfo@sitening.com>)
List pgsql-general
> I'd be curious to see what would happen if you added claimnum as a
> field in your view. I don't have a complete understanding of the
> postgres internals in terms of how it is able to push outer clauses
> down in to its views, but I think it might be able to optimize in
> that fashion if it is able to add a WHERE clause internally to the
> view, which it can't do in the case of claimnum since it doesn't
> exist in the view.


I added the claimnum and this actually slowed it down a bit because of
the additional group by, however I then changed my where clause to
filter on the view's claimnum rather than tbl_claim's claimnum, and I
got the results I wanted.

It seems to me that in the future I should always construct my views
such that my WHERE clauses end up on the view and not on any tables that
they join with.  The only problem with this is that very often I don't
know in advance what fields the client will want to search by, and now
I'll end up with two steps instead of one (modify my code AND modify the
view), however the speed increase is an order of magnatude and well
worth it.

Thanks!

John


pgsql-general by date:

Previous
From: "codeWarrior"
Date:
Subject: Re: Very slow queries on 8.1
Next
From: Tom Lane
Date:
Subject: Re: Very slow queries on 8.1