From: Steven Hirsch <snhirsch@gmail.com>
To: pinker <pinker@onet.eu>
Cc: pgsql-general@postgresql.org
Subject: Re: decompose big queries
Date: Fri, 6 Apr 2018 10:09:03 -0400 (EDT)
Message-ID: <alpine.DEB.2.20.1804061003410.4018@z87> (raw)
In-Reply-To: <1523021756830-0.post@n3.nabble.com>
References: <CAMsqVxthr_KB_VSa6z1dY+f9DpbA=UrNgB7nMnMT5KBPpk_YAQ@mail.gmail.com>
<40cd1824-1dd0-1aad-2c8d-c34ee510b5c5@simkorp.com.br>
<1523021756830-0.post@n3.nabble.com>
On Fri, 6 Apr 2018, pinker wrote:
> Edson Carlos Ericksson Richter wrote
>> I don't know if there are best practices (each scenario requires its own
>> solution), but for plain complex SELECT queries, I do use "WITH"
>> queries... They work really well.
> Be cautious with CTE's. They weren't meant to be an alternative to
> subqueries and will probably change the way your query is executed,
> because they are optimisation fences:
> https://blog.2ndquadrant.com/postgresql-ctes-are-optimization-fences/
+1
Recently I had a poorly performing view speed up by a factor of 6x when
converted from CTEs to to nested subqueries. In my case, the lack of
predicate push-down was a real killer. Pg would labor away to produce an
enormous intermediate result that was then selected down to a rather
modest final result set. Showed up clearly in the access plan, however,
and wasn't much of a problem to fix.
--
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: snhirsch@gmail.com, pinker@onet.eu
Subject: Re: decompose big queries
In-Reply-To: <alpine.DEB.2.20.1804061003410.4018@z87>
References: <CAMsqVxthr_KB_VSa6z1dY+f9DpbA=UrNgB7nMnMT5KBPpk_YAQ@mail.gmail.com> <40cd1824-1dd0-1aad-2c8d-c34ee510b5c5@simkorp.com.br> <1523021756830-0.post@n3.nabble.com> <alpine.DEB.2.20.1804061003410.4018@z87>
* 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