pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Avoid crash in partitionwise join planning under GEQO. 2+ messages / 1 participants [nested] [flat]
* pgsql: Avoid crash in partitionwise join planning under GEQO. @ 2019-03-30 16:48 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 2+ messages in thread From: Tom Lane @ 2019-03-30 16:48 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Avoid crash in partitionwise join planning under GEQO. While trying to plan a partitionwise join, we may be faced with cases where one or both input partitions for a particular segment of the join have been pruned away. In HEAD and v11, this is problematic because earlier processing didn't bother to make a pruned RelOptInfo fully valid. With an upcoming patch to make partition pruning more efficient, this'll be even more problematic because said RelOptInfo won't exist at all. The existing code attempts to deal with this by retroactively making the RelOptInfo fully valid, but that causes crashes under GEQO because join planning is done in a short-lived memory context. In v11 we could probably have fixed this by switching to the planner's main context while fixing up the RelOptInfo, but that idea doesn't scale well to the upcoming patch. It would be better not to mess with the base-relation data structures during join planning, anyway --- that's just a recipe for order-of-operations bugs. In many cases, though, we don't actually need the child RelOptInfo, because if the input is certainly empty then the join segment's result is certainly empty, so we can skip making a join plan altogether. (The existing code ultimately arrives at the same conclusion, but only after doing a lot more work.) This approach works except when the pruned-away partition is on the nullable side of a LEFT, ANTI, or FULL join, and the other side isn't pruned. But in those cases the existing code leaves a lot to be desired anyway --- the correct output is just the result of the unpruned side of the join, but we were emitting a useless outer join against a dummy Result. Pending somebody writing code to handle that more nicely, let's just abandon the partitionwise-join optimization in such cases. When the modified code skips making a join plan, it doesn't make a join RelOptInfo either; this requires some upper-level code to cope with nulls in part_rels[] arrays. We would have had to have that anyway after the upcoming patch. Back-patch to v11 since the crash is demonstrable there. Discussion: https://postgr.es/m/8305.1553884377@sss.pgh.pa.us Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/7ad6498fd5a654de6e743814c36cf619a3b5ddb6 Modified Files -------------- src/backend/optimizer/path/allpaths.c | 14 ++-- src/backend/optimizer/path/joinrels.c | 89 ++++++++++++-------- src/backend/optimizer/plan/planner.c | 17 ++-- src/test/regress/expected/partition_aggregate.out | 98 +++++++++-------------- src/test/regress/expected/partition_join.out | 91 +++++++++------------ src/test/regress/sql/partition_aggregate.sql | 10 ++- src/test/regress/sql/partition_join.sql | 3 + 7 files changed, 157 insertions(+), 165 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
* pgsql: Avoid crash in partitionwise join planning under GEQO. @ 2019-03-30 16:48 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 2+ messages in thread From: Tom Lane @ 2019-03-30 16:48 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Avoid crash in partitionwise join planning under GEQO. While trying to plan a partitionwise join, we may be faced with cases where one or both input partitions for a particular segment of the join have been pruned away. In HEAD and v11, this is problematic because earlier processing didn't bother to make a pruned RelOptInfo fully valid. With an upcoming patch to make partition pruning more efficient, this'll be even more problematic because said RelOptInfo won't exist at all. The existing code attempts to deal with this by retroactively making the RelOptInfo fully valid, but that causes crashes under GEQO because join planning is done in a short-lived memory context. In v11 we could probably have fixed this by switching to the planner's main context while fixing up the RelOptInfo, but that idea doesn't scale well to the upcoming patch. It would be better not to mess with the base-relation data structures during join planning, anyway --- that's just a recipe for order-of-operations bugs. In many cases, though, we don't actually need the child RelOptInfo, because if the input is certainly empty then the join segment's result is certainly empty, so we can skip making a join plan altogether. (The existing code ultimately arrives at the same conclusion, but only after doing a lot more work.) This approach works except when the pruned-away partition is on the nullable side of a LEFT, ANTI, or FULL join, and the other side isn't pruned. But in those cases the existing code leaves a lot to be desired anyway --- the correct output is just the result of the unpruned side of the join, but we were emitting a useless outer join against a dummy Result. Pending somebody writing code to handle that more nicely, let's just abandon the partitionwise-join optimization in such cases. When the modified code skips making a join plan, it doesn't make a join RelOptInfo either; this requires some upper-level code to cope with nulls in part_rels[] arrays. We would have had to have that anyway after the upcoming patch. Back-patch to v11 since the crash is demonstrable there. Discussion: https://postgr.es/m/8305.1553884377@sss.pgh.pa.us Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/d70c147fa217c4bae32ac1afb86ab42d98b36fdf Modified Files -------------- src/backend/optimizer/path/allpaths.c | 14 ++-- src/backend/optimizer/path/joinrels.c | 87 +++++++++++++------- src/backend/optimizer/plan/planner.c | 17 ++-- src/test/regress/expected/partition_aggregate.out | 98 +++++++++-------------- src/test/regress/expected/partition_join.out | 91 +++++++++------------ src/test/regress/sql/partition_aggregate.sql | 10 ++- src/test/regress/sql/partition_join.sql | 3 + 7 files changed, 157 insertions(+), 163 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2019-03-30 16:48 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2019-03-30 16:48 pgsql: Avoid crash in partitionwise join planning under GEQO. Tom Lane <tgl@sss.pgh.pa.us> 2019-03-30 16:48 pgsql: Avoid crash in partitionwise join planning under GEQO. 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