optimizing a view-driven query

From: will trillich <will(at)serensoft(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: optimizing a view-driven query
Date: 2001-03-28 23:07:33
Message-ID: 20010328170733.C16380@mail.serensoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)serensoft(dot)com
http://newbieDoc.sourceforge.net/ -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

Responses

Browse pgsql-general by date

  From Date Subject
Next Message will trillich 2001-03-28 23:08:55 Re: performance of ORDER BY random()
Previous Message will trillich 2001-03-28 23:01:11 joins and indexes -- a=b or b=a?