short circuit joins - Mailing list pgsql-general

From Marcus Engene
Subject short circuit joins
Date
Msg-id 4A9B032B.8070904@engene.se
Whole thread Raw
List pgsql-general
Hi,

-- a
select
    ...
from
    base_table bt
    left outer join sub_table_1 st1 on (st1.base_table = bt.id)
    left outer join sub_table_2 st1 on (st2.base_table = bt.id)

-- b
select
    ...
from
    base_table bt
    left outer join sub_table_1 st1 on (bt.objecttype = 1 AND
st1.base_table = bt.id)
    left outer join sub_table_2 st1 on (bt.objecttype = 2 AND
st2.base_table = bt.id)

Pretend this is some stupid way of object orientation. base_table is the
base class and sub_table_x are subclasses. base_table.objecttype tells
which instance it is. Just for the sake of discussion, it could also be
like "bt.is_married_monogamous = 1 AND wife.husband = bt.id" for example.

In case b, does Postgres avoid to unnecessarily try look for respective
sub_table ? Is it worthwhile to have?

I'm on 8.3 presently. Still curious if newer versions have some
optimization here.

Best regards,
Marcus


pgsql-general by date:

Previous
From: David Fetter
Date:
Subject: Re: Using WITH queries on VIEWs
Next
From: bilal ghayyad
Date:
Subject: Re: $Body$