pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: chester c young <chestercyoung@yahoo.com>
To: sql pgsql <pgsql-sql@postgresql.org>
Subject: better approach: case or join
Date: Sun, 18 Mar 2007 18:21:54 -0700 (PDT)
Message-ID: <828472.77350.qm@web54308.mail.yahoo.com> (raw)

from id extracting name from several tables.  which is generally the
better approach?

select case when tab_tla='usr' then (select name from users where ... )
       case when tab_tla='con' then (select title from contents where
...)
end    as name;

as versus

select  name
from    users
where   tab_tla='usr' and ...
        join
select  title
from    contents
where   tab_tla='con' and ...

I assume the former since the optimizer does not examine whether the
entire where clause might be false before executing the query.

thanks,
chester


 
____________________________________________________________________________________
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.
http://autos.yahoo.com/new_cars.html 



Message-ID: <828472.77350.qm@web54308.mail.yahoo.com>
Permalink:  ../828472.77350.qm@web54308.mail.yahoo.com/
Also on:    postgresql.org/message-id/828472.77350.qm@web54308.mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: chestercyoung@yahoo.com
  Subject: Re: better approach: case or join
  In-Reply-To: <828472.77350.qm@web54308.mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox