pgsql: Suppress unnecessary RelabelType nodes in more cases.
От | Tom Lane |
---|---|
Тема | pgsql: Suppress unnecessary RelabelType nodes in more cases. |
Дата | |
Msg-id | E1j75su-00044J-Dn@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 ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/30d5c6bf2e09fe76448e59e9889ab5b38171da34 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 по дате отправления: