Re: subselects vs WITH in views - Mailing list pgsql-general

From Merlin Moncure
Subject Re: subselects vs WITH in views
Date
Msg-id CAHyXU0wS286_qUV+_42OeQb_e6ZXva72e1kY3jcTeZ0FRE9hiA@mail.gmail.com
Whole thread Raw
In response to Re: subselects vs WITH in views  (Seref Arikan <serefarikan@gmail.com>)
List pgsql-general
On Thu, Feb 21, 2013 at 4:31 AM, Seref Arikan <serefarikan@gmail.com> wrote:
> Hi Merlin,
> So should I interpret this as: there is a potential gain from choosing
> subqueries over with WITHs ?

Well, potentially, yes.  WITH is a mechanic to force iterative order
of evaluation on queries.  This can be a good or bad thing naturally.
Subqueries can also do this, especially if you put them in the field
select list -- but WITH is more general.  We also have an undocumented
hack that uses OFFSET 0 to force subquery evaluation.  These are all
very dangerous tools because they tend to be very sensitive to data
inputs as you are bypassing database statistics effectively.  The
other end of the spectrum is to use vanilla JOINs as much as possible
-- this releases the work of planning the query to the database.

Upcoming 9.3 LATERAL will remove one large class of cases where we
have to do this: joining against set returning functions with
non-constant inputs.

merlin

pgsql-general by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: Trigram (pg_trgm) GIN index not used
Next
From: Tom Lane
Date:
Subject: Re: Trigram (pg_trgm) GIN index not used