From: Tom Lane <tgl@sss.pgh.pa.us>
To: Paul A Jungwirth <pj@illuminatedcomputing.com>
Cc: pgsql <pgsql-general@postgresql.org>
Subject: Re: Rules documentation example
Date: Mon, 11 Nov 2019 13:38:49 -0500
Message-ID: <14490.1573497529@sss.pgh.pa.us> (raw)
In-Reply-To: <CA+renyXZFnmp9PcvX1EVR2dR=XG5e6E-AELr8AHCNZ8RYrpnPw@mail.gmail.com>
References: <CA+renyXZFnmp9PcvX1EVR2dR=XG5e6E-AELr8AHCNZ8RYrpnPw@mail.gmail.com>
Paul A Jungwirth <pj@illuminatedcomputing.com> writes:
> I'm reading the docs about the Postgres Rule system here:
> https://www.postgresql.org/docs/12/rules-views.html
> That page says:
>> It turns out that the planner will collapse this tree into a two-level query tree: the bottommost SELECT commands will be “pulled up” into the middle SELECT since there's no need to process them separately. But the middle SELECT will remain separate from the top, because it contains aggregate functions. If we pulled those up it would change the behavior of the topmost SELECT, which we don't want.
> But I don't see an aggregate function. Is it referring to MIN?
Perhaps. Digging in the git history, that text seems to be mine
(commit 1045304a3), but the example that it's talking about was
pre-existing. I think I might've just misread it. It's also
likely (assuming that I was documenting a behavior that I actually
saw at the time) that the real issue is that MIN(), as presented,
defaults to being volatile which would also prevent such flattening.
But this example is so old that I'm not sure whether that particular
optimization behavior existed then.
I'm inclined to:
(1) get rid of the example's MIN() function in favor of using
LEAST(), which is standard and less confusing;
(2) change the text to just say that the planner flattens these
subqueries, so we don't pay any execution-time penalty from the
way the view replacements are handled.
regards, tom lane
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: tgl@sss.pgh.pa.us, pj@illuminatedcomputing.com
Subject: Re: Rules documentation example
In-Reply-To: <14490.1573497529@sss.pgh.pa.us>
References: <CA+renyXZFnmp9PcvX1EVR2dR=XG5e6E-AELr8AHCNZ8RYrpnPw@mail.gmail.com> <14490.1573497529@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