optimizing a view-driven query - Mailing list pgsql-general

From will trillich
Subject optimizing a view-driven query
Date
Msg-id 20010328170733.C16380@mail.serensoft.com
Whole thread Raw
Responses Re: optimizing a view-driven query
List pgsql-general
if i've got a view that joins three or four tables, is there a
way to SELECT on that view to bypass any of the joins if they're
not needed in the result?

    create view course as
        select
            _course.name as course,
            _topic.name  as topic,
            _school.name as school,
            _state.name  as state,
            _school.zip  as zip
        where
            _course.topic = _topic.id
            and
            _topic.school = _school.id
            and
            _state.abbr   = _school.state
        ;

    select * from course ;
    -- shows all fields via all tables

    select topic from course where course like '%comput%' ;
    -- not asking for state, we don't need to join the state table

here the optimizer might know we don't need to join the static
lookup '_state' table. can this be made to happen?

or is it just best to have "one view, one purpose"?

--
It is always hazardous to ask "Why?" in science, but it is often
interesting to do so just the same.
        -- Isaac Asimov, 'The Genetic Code'

will@serensoft.com
http://newbieDoc.sourceforge.net/ -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

pgsql-general by date:

Previous
From: will trillich
Date:
Subject: Re: how to load a sql-file????
Next
From: Jean-Christophe Boggio
Date:
Subject: Unexplained behaviour