pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Suppress unnecessary RelabelType nodes in yet more cases.
Date: Wed, 19 Aug 2020 18:08:11 +0000
Message-ID: <E1k8SVP-0002D6-6T@gemulon.postgresql.org> (raw)

Suppress unnecessary RelabelType nodes in yet more cases.

Commit a477bfc1d fixed eval_const_expressions() to ensure that it
didn't generate unnecessary RelabelType nodes, but I failed to notice
that some other places in the planner had the same issue.  Really
noplace in the planner should be using plain makeRelabelType(), for
fear of generating expressions that should be equal() to semantically
equivalent trees, but aren't.

An example is that because canonicalize_ec_expression() failed
to be careful about this, we could end up with an equivalence class
containing both a plain Const, and a Const-with-RelabelType
representing exactly the same value.  So far as I can tell this led to
no visible misbehavior, but we did waste a bunch of cycles generating
and evaluating "Const = Const-with-RelabelType" to prove such entries
are redundant.

Hence, move the support function added by a477bfc1d to where it can
be more generally useful, and use it in the places where planner code
previously used makeRelabelType.

Back-patch to v12, like the previous patch.  While I have no concrete
evidence of any real misbehavior here, it's certainly possible that
I overlooked a case where equivalent expressions that aren't equal()
could cause a user-visible problem.  In any case carrying extra
RelabelType nodes through planning to execution isn't very desirable.

Discussion: https://postgr.es/m/1311836.1597781384@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/20729324078055a4d9654fc5af9570fe625786a5

Modified Files
--------------
src/backend/nodes/nodeFuncs.c           | 75 +++++++++++++++++++++-----
src/backend/optimizer/path/equivclass.c | 43 ++++++---------
src/backend/optimizer/prep/prepunion.c  | 10 ++--
src/backend/optimizer/util/clauses.c    | 94 ++++++++-------------------------
src/include/nodes/nodeFuncs.h           |  3 ++
5 files changed, 106 insertions(+), 119 deletions(-)



view thread (5+ messages)

Message-ID: <E1k8SVP-0002D6-6T@gemulon.postgresql.org>
Permalink:  ../E1k8SVP-0002D6-6T@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1k8SVP-0002D6-6T@gemulon.postgresql.org

 · 

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 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-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Suppress unnecessary RelabelType nodes in yet more cases.
  In-Reply-To: <E1k8SVP-0002D6-6T@gemulon.postgresql.org>
  References: <E1k8SVP-0002D6-6T@gemulon.postgresql.org>

* 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