Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

short circuit joins


  • From: Marcus Engene <mengpg2(at)engene(dot)se>
  • To: POSTGRESQL <pgsql-general(at)postgresql(dot)org>
  • Subject: short circuit joins
  • Date: Mon, 31 Aug 2009 00:54:35 +0200
  • Message-id: <4A9B032B.8070904@engene.se> <text/plain>

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




Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group