pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alexandre Leclerc <alexandre.leclerc@gmail.com>
Cc: PERFORM <pgsql-performance@postgresql.org>
Subject: Re: Performance difference: SELECT from VIEW or not?
Date: Mon, 15 Nov 2004 18:30:41 -0500
Message-ID: <11692.1100561441@sss.pgh.pa.us> (raw)
In-Reply-To: <1dc7f0e3041115151015e34130@mail.gmail.com>
References: <1dc7f0e3041115151015e34130@mail.gmail.com>

Alexandre Leclerc <alexandre.leclerc@gmail.com> writes:
> -- suppose this view (used many times):
> CREATE VIEW prod.alljobs_view AS
>   SELECT *
>   FROM prod.jobs
>     LEFT JOIN prod.jobs_products ON jobs.job_id = jobs_products.job_id;

> -- suppose this other query:
> CREATE VIEW prod.orders_jobs_view AS
>   SELECT job_id, order_id, product_code
>     FROM prod.alljobs_view
>       LEFT JOIN design.products ON alljobs_view.product_id =
> products.product_id;

> -- would this be more effective on database side than:?
> CREATE VIEW prod.orders_jobs_view AS
>   SELECT job_id, order_id, product_code
>     FROM prod.jobs
>       LEFT JOIN prod.jobs_products ON jobs.job_id = jobs_products.job_id
>       LEFT JOIN design.products ON jobs_products.product_id =
> products.product_id;

> Which is the best, or is there any difference?

For the specific case mentioned, there's not going to be any visible
difference (maybe a few more catalog lookups to expand two view
definitions instead of one).  However, it's real easy to shoot yourself
in the foot with views and outer joins.  Don't forget that the syntactic
ordering of outer joins is also a semantic and performance constraint.
(a left join b) left join c is different from a left join (b left join c)
and a view is basically a parenthesized subselect ...

			regards, tom lane



view thread (2+ messages)

Message-ID: <11692.1100561441@sss.pgh.pa.us>
Permalink:  ../11692.1100561441@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/11692.1100561441@sss.pgh.pa.us

 · 

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-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, alexandre.leclerc@gmail.com
  Subject: Re: Performance difference: SELECT from VIEW or not?
  In-Reply-To: <11692.1100561441@sss.pgh.pa.us>

* 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