From: Tom Lane <tgl@sss.pgh.pa.us>
To: Paul van der Linden <paul.doskabouter@gmail.com>
Cc: David Rowley <dgrowleyml@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: Possible improvement
Date: Fri, 05 Jun 2020 15:02:34 -0400
Message-ID: <1537861.1591383754@sss.pgh.pa.us> (raw)
In-Reply-To: <CAEC-EqDuDsS-vvifDDsvco_CGT9W75dMx03ideV=BnwWaAaHmA@mail.gmail.com>
References: <CAEC-EqBVFGXBG2xH-U+LOXPwiu0bwqoPj=daLmmNvNZRneW+5A@mail.gmail.com>
<CAApHDvr+6=7SZBAtesEavgOQ0ZC03syaRQk19E++piWLopTRbg@mail.gmail.com>
<1470860.1591367497@sss.pgh.pa.us>
<CAEC-EqDuDsS-vvifDDsvco_CGT9W75dMx03ideV=BnwWaAaHmA@mail.gmail.com>
Paul van der Linden <paul.doskabouter@gmail.com> writes:
> For the case where it isn't known if the case expression itself is indexed,
> technically that should be added as a decision-node in the query planner.
That'd be fairly hard to do, if we're regarding this as an expression
simplification step, since expression simplification is run long before
any consideration is given to indexes. (Even if we were willing to
contemplate reversing that ordering, it'd be hard to do, because we
need the simplified expressions to compare to index expressions ---
else we'd get fooled by irrelevant discrepancies that simplification
is supposed to remove.)
The alternative is to try to wire this into index path generation instead
of treating it as a general-purpose expression simplification ... but that
likewise seems pretty undesirable. If you've got a case like this, you'd
like it to be simplified whether it ends up as an indexqual or not.
So, as I said, I'm inclined to dismiss David's complaint as an
impracticable requirement. The other issues I raised are far more
significant.
BTW, speaking of correctness, this seems like a pretty dire
counterexample:
SELECT ... FROM
(SELECT CASE WHEN x = 0 THEN 'zero'
WHEN 1/x > 100 THEN 'tiny'
ELSE 'whatever' END AS class,
...
) ss
WHERE ss.class = 'tiny';
Naive application of this transformation would convert the WHERE to
WHERE 1/x > 100
creating divide-by-zero failures where there should be none.
I'm not sure how we get around that; in general the planner
has little clue which operations can throw what errors.
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, paul.doskabouter@gmail.com, dgrowleyml@gmail.com
Subject: Re: Possible improvement
In-Reply-To: <1537861.1591383754@sss.pgh.pa.us>
References: <CAEC-EqBVFGXBG2xH-U+LOXPwiu0bwqoPj=daLmmNvNZRneW+5A@mail.gmail.com> <CAApHDvr+6=7SZBAtesEavgOQ0ZC03syaRQk19E++piWLopTRbg@mail.gmail.com> <1470860.1591367497@sss.pgh.pa.us> <CAEC-EqDuDsS-vvifDDsvco_CGT9W75dMx03ideV=BnwWaAaHmA@mail.gmail.com> <1537861.1591383754@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