pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Suppress unnecessary RelabelType nodes in more cases. 5+ messages / 1 participants [nested] [flat]
* pgsql: Suppress unnecessary RelabelType nodes in more cases. @ 2020-02-26 23:14 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 5+ messages in thread From: Tom Lane @ 2020-02-26 23:14 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Suppress unnecessary RelabelType nodes in more cases. @ 2020-02-26 23:14 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 5+ messages in thread From: Tom Lane @ 2020-02-26 23:14 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Suppress unnecessary RelabelType nodes in yet more cases. @ 2020-08-19 18:08 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 5+ messages in thread From: Tom Lane @ 2020-08-19 18:08 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Suppress unnecessary RelabelType nodes in yet more cases. @ 2020-08-19 18:08 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 5+ messages in thread From: Tom Lane @ 2020-08-19 18:08 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 ------ REL_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/69ffc2f838990fb2c802087091ce7c2ff1b735eb 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(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Suppress unnecessary RelabelType nodes in yet more cases. @ 2020-08-19 18:08 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 5+ messages in thread From: Tom Lane @ 2020-08-19 18:08 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/814a57065ec97e44de58db61a16957ddd09938e8 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(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2020-08-19 18:08 UTC | newest] Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2020-02-26 23:14 pgsql: Suppress unnecessary RelabelType nodes in more cases. Tom Lane <tgl@sss.pgh.pa.us> 2020-02-26 23:14 pgsql: Suppress unnecessary RelabelType nodes in more cases. Tom Lane <tgl@sss.pgh.pa.us> 2020-08-19 18:08 pgsql: Suppress unnecessary RelabelType nodes in yet more cases. Tom Lane <tgl@sss.pgh.pa.us> 2020-08-19 18:08 pgsql: Suppress unnecessary RelabelType nodes in yet more cases. Tom Lane <tgl@sss.pgh.pa.us> 2020-08-19 18:08 pgsql: Suppress unnecessary RelabelType nodes in yet more cases. Tom Lane <tgl@sss.pgh.pa.us>
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