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

From Tom Lane
Subject Re: optimizing a view-driven query
Date
Msg-id 20360.985822298@sss.pgh.pa.us
Whole thread Raw
In response to optimizing a view-driven query  (will trillich <will@serensoft.com>)
List pgsql-general
will trillich <will@serensoft.com> writes:
>     select topic from course where course like '%comput%' ;
>     -- not asking for state, we don't need to join the state table

But you still do need to join, because the join affects which rows
will be returned.  The fact that you don't happen to use any values
out of one of the joined tables in your SELECT list is not very
relevant.

In this example, you might happen to know (or think you know) that there
will be one and only one state row matching any possible row from the
subjoin of the other tables, so in the end it wouldn't affect the number
of rows output.  This is not an assumption the planner is prepared to
make, however.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: joins and indexes -- a=b or b=a?
Next
From: Tom Lane
Date:
Subject: Re: Unexplained behaviour