pgsql: Suppress unnecessary RelabelType nodes in more cases.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Suppress unnecessary RelabelType nodes in more cases.
Дата
Msg-id E1j75su-00044I-D1@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Suppress unnecessary RelabelType nodes in more cases.

eval_const_expressions sometimes produced RelabelType nodes that
were useless because they just relabeled an expression to the same
exposed type it already had.  This is worth avoiding because it can
cause two equivalent expressions to not be equal(), preventing
recognition of useful optimizations.  In the test case added here,
an unpatched planner fails to notice that the "sqli = constant" clause
renders a sort step unnecessary, because one code path produces an
extra RelabelType and another doesn't.

Fix by ensuring that eval_const_expressions_mutator's T_RelabelType
case will not add in an unnecessary RelabelType.  Also save some
code by sharing a subroutine with the effectively-equivalent cases
for CollateExpr and CoerceToDomain.  (CollateExpr had no bug, and
I think that the case couldn't arise with CoerceToDomain, but
it seems prudent to do the same check for all three cases.)

Back-patch to v12.  In principle this has been wrong all along,
but I haven't seen a case where it causes visible misbehavior
before v12, so refrain from changing stable branches unnecessarily.

Per investigation of a report from Eric Gillum.

Discussion: https://postgr.es/m/CAMmjdmvAZsUEskHYj=KT9sTukVVCiCSoe_PBKOXsncFeAUDPCQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a477bfc1dfb8d2b7125a9818edcbf383bf82d62a

Modified Files
--------------
src/backend/optimizer/util/clauses.c     | 179 ++++++++++++++-----------------
src/test/regress/expected/equivclass.out |  12 +++
src/test/regress/sql/equivclass.sql      |   7 ++
3 files changed, 101 insertions(+), 97 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: pgsql: Silence compiler warning in nbtinsert.c.
Следующее
От: Peter Geoghegan
Дата:
Сообщение: pgsql: Silence another compiler warning in nbtinsert.c.