pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Be more careful about the shape of hashable subplan clauses. 7+ messages / 1 participants [nested] [flat]
* pgsql: Be more careful about the shape of hashable subplan clauses. @ 2020-08-15 02:14 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2020-08-15 02:14 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Be more careful about the shape of hashable subplan clauses. nodeSubplan.c expects that the testexpr for a hashable ANY SubPlan has the form of one or more OpExprs whose LHS is an expression of the outer query's, while the RHS is an expression over Params representing output columns of the subquery. However, the planner only went as far as verifying that the clauses were all binary OpExprs. This works 99.99% of the time, because the clauses have the right shape when emitted by the parser --- but it's possible for function inlining to break that, as reported by PegoraroF10. To fix, teach the planner to check that the LHS and RHS contain the right things, or more accurately don't contain the wrong things. Given that this has been broken for years without anyone noticing, it seems sufficient to just give up hashing when it happens, rather than go to the trouble of commuting the clauses back again (which wouldn't necessarily work anyway). While poking at that, I also noticed that nodeSubplan.c had a baked-in assumption that the number of hash clauses is identical to the number of subquery output columns. Again, that's fine as far as parser output goes, but it's not hard to break it via function inlining. There seems little reason for that assumption though --- AFAICS, the only thing it's buying us is not having to store the number of hash clauses explicitly. Adding code to the planner to reject such cases would take more code than getting nodeSubplan.c to cope, so I fixed it that way. This has been broken for as long as we've had hashable SubPlans, so back-patch to all supported branches. Discussion: https://postgr.es/m/1549209182255-0.post@n3.nabble.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/1e7629d2c95ffd290ab0e18d7618ca9d9da94265 Modified Files -------------- src/backend/executor/nodeSubplan.c | 16 +++---- src/backend/optimizer/plan/subselect.c | 77 +++++++++++++++++++++++---------- src/backend/optimizer/util/clauses.c | 35 +++++++++++++++ src/include/nodes/execnodes.h | 2 + src/include/optimizer/clauses.h | 1 + src/test/regress/expected/subselect.out | 77 +++++++++++++++++++++++++++++++++ src/test/regress/sql/subselect.sql | 41 ++++++++++++++++++ 7 files changed, 219 insertions(+), 30 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Be more careful about the shape of hashable subplan clauses. @ 2020-08-15 02:14 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2020-08-15 02:14 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Be more careful about the shape of hashable subplan clauses. nodeSubplan.c expects that the testexpr for a hashable ANY SubPlan has the form of one or more OpExprs whose LHS is an expression of the outer query's, while the RHS is an expression over Params representing output columns of the subquery. However, the planner only went as far as verifying that the clauses were all binary OpExprs. This works 99.99% of the time, because the clauses have the right shape when emitted by the parser --- but it's possible for function inlining to break that, as reported by PegoraroF10. To fix, teach the planner to check that the LHS and RHS contain the right things, or more accurately don't contain the wrong things. Given that this has been broken for years without anyone noticing, it seems sufficient to just give up hashing when it happens, rather than go to the trouble of commuting the clauses back again (which wouldn't necessarily work anyway). While poking at that, I also noticed that nodeSubplan.c had a baked-in assumption that the number of hash clauses is identical to the number of subquery output columns. Again, that's fine as far as parser output goes, but it's not hard to break it via function inlining. There seems little reason for that assumption though --- AFAICS, the only thing it's buying us is not having to store the number of hash clauses explicitly. Adding code to the planner to reject such cases would take more code than getting nodeSubplan.c to cope, so I fixed it that way. This has been broken for as long as we've had hashable SubPlans, so back-patch to all supported branches. Discussion: https://postgr.es/m/1549209182255-0.post@n3.nabble.com Branch ------ REL_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/b538e83f17e36fd0fe0686815da0ff5866ce8a64 Modified Files -------------- src/backend/executor/nodeSubplan.c | 16 +++---- src/backend/optimizer/plan/subselect.c | 77 +++++++++++++++++++++++---------- src/backend/optimizer/util/clauses.c | 35 +++++++++++++++ src/include/nodes/execnodes.h | 2 + src/include/optimizer/clauses.h | 1 + src/test/regress/expected/subselect.out | 77 +++++++++++++++++++++++++++++++++ src/test/regress/sql/subselect.sql | 41 ++++++++++++++++++ 7 files changed, 219 insertions(+), 30 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Be more careful about the shape of hashable subplan clauses. @ 2020-08-15 02:14 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2020-08-15 02:14 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Be more careful about the shape of hashable subplan clauses. nodeSubplan.c expects that the testexpr for a hashable ANY SubPlan has the form of one or more OpExprs whose LHS is an expression of the outer query's, while the RHS is an expression over Params representing output columns of the subquery. However, the planner only went as far as verifying that the clauses were all binary OpExprs. This works 99.99% of the time, because the clauses have the right shape when emitted by the parser --- but it's possible for function inlining to break that, as reported by PegoraroF10. To fix, teach the planner to check that the LHS and RHS contain the right things, or more accurately don't contain the wrong things. Given that this has been broken for years without anyone noticing, it seems sufficient to just give up hashing when it happens, rather than go to the trouble of commuting the clauses back again (which wouldn't necessarily work anyway). While poking at that, I also noticed that nodeSubplan.c had a baked-in assumption that the number of hash clauses is identical to the number of subquery output columns. Again, that's fine as far as parser output goes, but it's not hard to break it via function inlining. There seems little reason for that assumption though --- AFAICS, the only thing it's buying us is not having to store the number of hash clauses explicitly. Adding code to the planner to reject such cases would take more code than getting nodeSubplan.c to cope, so I fixed it that way. This has been broken for as long as we've had hashable SubPlans, so back-patch to all supported branches. Discussion: https://postgr.es/m/1549209182255-0.post@n3.nabble.com Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/912fb290c5dd087ccc4b04c19692137bb786a9fd Modified Files -------------- src/backend/executor/nodeSubplan.c | 16 +++---- src/backend/optimizer/plan/subselect.c | 77 +++++++++++++++++++++++---------- src/backend/optimizer/util/clauses.c | 35 +++++++++++++++ src/include/nodes/execnodes.h | 2 + src/include/optimizer/clauses.h | 1 + src/test/regress/expected/subselect.out | 77 +++++++++++++++++++++++++++++++++ src/test/regress/sql/subselect.sql | 41 ++++++++++++++++++ 7 files changed, 219 insertions(+), 30 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Be more careful about the shape of hashable subplan clauses. @ 2020-08-15 02:14 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2020-08-15 02:14 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Be more careful about the shape of hashable subplan clauses. nodeSubplan.c expects that the testexpr for a hashable ANY SubPlan has the form of one or more OpExprs whose LHS is an expression of the outer query's, while the RHS is an expression over Params representing output columns of the subquery. However, the planner only went as far as verifying that the clauses were all binary OpExprs. This works 99.99% of the time, because the clauses have the right shape when emitted by the parser --- but it's possible for function inlining to break that, as reported by PegoraroF10. To fix, teach the planner to check that the LHS and RHS contain the right things, or more accurately don't contain the wrong things. Given that this has been broken for years without anyone noticing, it seems sufficient to just give up hashing when it happens, rather than go to the trouble of commuting the clauses back again (which wouldn't necessarily work anyway). While poking at that, I also noticed that nodeSubplan.c had a baked-in assumption that the number of hash clauses is identical to the number of subquery output columns. Again, that's fine as far as parser output goes, but it's not hard to break it via function inlining. There seems little reason for that assumption though --- AFAICS, the only thing it's buying us is not having to store the number of hash clauses explicitly. Adding code to the planner to reject such cases would take more code than getting nodeSubplan.c to cope, so I fixed it that way. This has been broken for as long as we've had hashable SubPlans, so back-patch to all supported branches. Discussion: https://postgr.es/m/1549209182255-0.post@n3.nabble.com Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/9d472b51e98777102d72f8ccdfb8cef10e087f74 Modified Files -------------- src/backend/executor/nodeSubplan.c | 14 +++--- src/backend/optimizer/plan/subselect.c | 77 +++++++++++++++++++++++--------- src/backend/optimizer/util/clauses.c | 35 +++++++++++++++ src/include/nodes/execnodes.h | 2 + src/include/optimizer/clauses.h | 1 + src/test/regress/expected/subselect.out | 79 +++++++++++++++++++++++++++++++++ src/test/regress/sql/subselect.sql | 44 ++++++++++++++++++ 7 files changed, 223 insertions(+), 29 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Be more careful about the shape of hashable subplan clauses. @ 2020-08-15 02:14 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2020-08-15 02:14 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Be more careful about the shape of hashable subplan clauses. nodeSubplan.c expects that the testexpr for a hashable ANY SubPlan has the form of one or more OpExprs whose LHS is an expression of the outer query's, while the RHS is an expression over Params representing output columns of the subquery. However, the planner only went as far as verifying that the clauses were all binary OpExprs. This works 99.99% of the time, because the clauses have the right shape when emitted by the parser --- but it's possible for function inlining to break that, as reported by PegoraroF10. To fix, teach the planner to check that the LHS and RHS contain the right things, or more accurately don't contain the wrong things. Given that this has been broken for years without anyone noticing, it seems sufficient to just give up hashing when it happens, rather than go to the trouble of commuting the clauses back again (which wouldn't necessarily work anyway). While poking at that, I also noticed that nodeSubplan.c had a baked-in assumption that the number of hash clauses is identical to the number of subquery output columns. Again, that's fine as far as parser output goes, but it's not hard to break it via function inlining. There seems little reason for that assumption though --- AFAICS, the only thing it's buying us is not having to store the number of hash clauses explicitly. Adding code to the planner to reject such cases would take more code than getting nodeSubplan.c to cope, so I fixed it that way. This has been broken for as long as we've had hashable SubPlans, so back-patch to all supported branches. Discussion: https://postgr.es/m/1549209182255-0.post@n3.nabble.com Branch ------ REL_10_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/dea07098af20f3dbaac873263020a5d95ea24ed8 Modified Files -------------- src/backend/executor/nodeSubplan.c | 14 +++--- src/backend/optimizer/plan/subselect.c | 77 +++++++++++++++++++++++--------- src/backend/optimizer/util/clauses.c | 35 +++++++++++++++ src/include/nodes/execnodes.h | 2 + src/include/optimizer/clauses.h | 1 + src/test/regress/expected/subselect.out | 79 +++++++++++++++++++++++++++++++++ src/test/regress/sql/subselect.sql | 44 ++++++++++++++++++ 7 files changed, 223 insertions(+), 29 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Be more careful about the shape of hashable subplan clauses. @ 2020-08-15 02:14 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2020-08-15 02:14 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Be more careful about the shape of hashable subplan clauses. nodeSubplan.c expects that the testexpr for a hashable ANY SubPlan has the form of one or more OpExprs whose LHS is an expression of the outer query's, while the RHS is an expression over Params representing output columns of the subquery. However, the planner only went as far as verifying that the clauses were all binary OpExprs. This works 99.99% of the time, because the clauses have the right shape when emitted by the parser --- but it's possible for function inlining to break that, as reported by PegoraroF10. To fix, teach the planner to check that the LHS and RHS contain the right things, or more accurately don't contain the wrong things. Given that this has been broken for years without anyone noticing, it seems sufficient to just give up hashing when it happens, rather than go to the trouble of commuting the clauses back again (which wouldn't necessarily work anyway). While poking at that, I also noticed that nodeSubplan.c had a baked-in assumption that the number of hash clauses is identical to the number of subquery output columns. Again, that's fine as far as parser output goes, but it's not hard to break it via function inlining. There seems little reason for that assumption though --- AFAICS, the only thing it's buying us is not having to store the number of hash clauses explicitly. Adding code to the planner to reject such cases would take more code than getting nodeSubplan.c to cope, so I fixed it that way. This has been broken for as long as we've had hashable SubPlans, so back-patch to all supported branches. Discussion: https://postgr.es/m/1549209182255-0.post@n3.nabble.com Branch ------ REL9_6_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/7241edc4fa8cda23d04bfe3cd139ed27904eac04 Modified Files -------------- src/backend/executor/nodeSubplan.c | 14 +++--- src/backend/optimizer/plan/subselect.c | 77 +++++++++++++++++++++++--------- src/backend/optimizer/util/clauses.c | 35 +++++++++++++++ src/include/nodes/execnodes.h | 2 + src/include/optimizer/clauses.h | 1 + src/test/regress/expected/subselect.out | 79 +++++++++++++++++++++++++++++++++ src/test/regress/sql/subselect.sql | 44 ++++++++++++++++++ 7 files changed, 223 insertions(+), 29 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Be more careful about the shape of hashable subplan clauses. @ 2020-08-15 02:14 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2020-08-15 02:14 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Be more careful about the shape of hashable subplan clauses. nodeSubplan.c expects that the testexpr for a hashable ANY SubPlan has the form of one or more OpExprs whose LHS is an expression of the outer query's, while the RHS is an expression over Params representing output columns of the subquery. However, the planner only went as far as verifying that the clauses were all binary OpExprs. This works 99.99% of the time, because the clauses have the right shape when emitted by the parser --- but it's possible for function inlining to break that, as reported by PegoraroF10. To fix, teach the planner to check that the LHS and RHS contain the right things, or more accurately don't contain the wrong things. Given that this has been broken for years without anyone noticing, it seems sufficient to just give up hashing when it happens, rather than go to the trouble of commuting the clauses back again (which wouldn't necessarily work anyway). While poking at that, I also noticed that nodeSubplan.c had a baked-in assumption that the number of hash clauses is identical to the number of subquery output columns. Again, that's fine as far as parser output goes, but it's not hard to break it via function inlining. There seems little reason for that assumption though --- AFAICS, the only thing it's buying us is not having to store the number of hash clauses explicitly. Adding code to the planner to reject such cases would take more code than getting nodeSubplan.c to cope, so I fixed it that way. This has been broken for as long as we've had hashable SubPlans, so back-patch to all supported branches. Discussion: https://postgr.es/m/1549209182255-0.post@n3.nabble.com Branch ------ REL9_5_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/5190707d7436089a33dd0e83482a314333ab6e59 Modified Files -------------- src/backend/executor/nodeSubplan.c | 14 +++--- src/backend/optimizer/plan/subselect.c | 77 +++++++++++++++++++++++--------- src/backend/optimizer/util/clauses.c | 35 +++++++++++++++ src/include/nodes/execnodes.h | 2 + src/include/optimizer/clauses.h | 1 + src/test/regress/expected/subselect.out | 79 +++++++++++++++++++++++++++++++++ src/test/regress/sql/subselect.sql | 44 ++++++++++++++++++ 7 files changed, 223 insertions(+), 29 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2020-08-15 02:14 UTC | newest] Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2020-08-15 02:14 pgsql: Be more careful about the shape of hashable subplan clauses. Tom Lane <tgl@sss.pgh.pa.us> 2020-08-15 02:14 pgsql: Be more careful about the shape of hashable subplan clauses. Tom Lane <tgl@sss.pgh.pa.us> 2020-08-15 02:14 pgsql: Be more careful about the shape of hashable subplan clauses. Tom Lane <tgl@sss.pgh.pa.us> 2020-08-15 02:14 pgsql: Be more careful about the shape of hashable subplan clauses. Tom Lane <tgl@sss.pgh.pa.us> 2020-08-15 02:14 pgsql: Be more careful about the shape of hashable subplan clauses. Tom Lane <tgl@sss.pgh.pa.us> 2020-08-15 02:14 pgsql: Be more careful about the shape of hashable subplan clauses. Tom Lane <tgl@sss.pgh.pa.us> 2020-08-15 02:14 pgsql: Be more careful about the shape of hashable subplan clauses. 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