postgresql/src/backend
Tom Lane 6ee41a301e Fix mis-planning of repeated application of a projection.
create_projection_plan contains a hidden assumption (here made
explicit by an Assert) that a projection-capable Path will yield a
projection-capable Plan.  Unfortunately, that assumption is violated
only a few lines away, by create_projection_plan itself.  This means
that two stacked ProjectionPaths can yield an outcome where we try to
jam the upper path's tlist into a non-projection-capable child node,
resulting in an invalid plan.

There isn't any good reason to have stacked ProjectionPaths; indeed the
whole concept is faulty, since the set of Vars/Aggs/etc needed by the
upper one wouldn't necessarily be available in the output of the lower
one, nor could the lower one create such values if they weren't
available from its input.  Hence, we can fix this by adjusting
create_projection_path to strip any top-level ProjectionPath from the
subpath it's given.  (This amounts to saying "oh, we changed our
minds about what we need to project here".)

The test case added here only fails in v13 and HEAD; before that, we
don't attempt to shove the Sort into the parallel part of the plan,
for reasons that aren't entirely clear to me.  However, all the
directly-related code looks generally the same as far back as v11,
where the hazard was introduced (by d7c19e62a).  So I've got no faith
that the same type of bug doesn't exist in v11 and v12, given the
right test case.  Hence, back-patch the code changes, but not the
irrelevant test case, into those branches.

Per report from Bas Poot.

Discussion: https://postgr.es/m/534fca83789c4a378c7de379e9067d4f@politie.nl
2021-05-31 12:03:00 -04:00
..
access Fix VACUUM VERBOSE's LP_DEAD item pages output. 2021-05-27 17:09:16 -07:00
bootstrap Rethink definition of pg_attribute.attcompression. 2021-05-27 13:24:27 -04:00
catalog Reduce the range of OIDs reserved for genbki.pl. 2021-05-27 15:55:08 -04:00
commands Rethink definition of pg_attribute.attcompression. 2021-05-27 13:24:27 -04:00
executor Fix planner's use of Result Cache with unique joins 2021-05-22 16:22:27 +12:00
foreign Update copyright for 2021 2021-01-02 13:06:25 -05:00
jit Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
lib Fix typo in comment 2021-04-20 14:35:16 +02:00
libpq Disallow SSL renegotiation 2021-05-25 10:10:09 +09:00
main Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodes Fix mishandling of resjunk columns in ON CONFLICT ... UPDATE tlists. 2021-05-10 11:02:29 -04:00
optimizer Fix mis-planning of repeated application of a projection. 2021-05-31 12:03:00 -04:00
parser Rethink definition of pg_attribute.attcompression. 2021-05-27 13:24:27 -04:00
partitioning Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
po Translation updates 2021-05-17 14:30:27 +02:00
port Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
postmaster Be more verbose when the postmaster unexpectedly quits. 2021-05-23 10:50:21 -04:00
regex Fix performance issue in new regex match-all detection code. 2021-05-03 11:42:31 -04:00
replication Fix assertion during streaming of multi-insert toast changes. 2021-05-27 07:59:43 +05:30
rewrite Remove unused function argument 2021-05-03 09:05:58 +02:00
snowball Update snowball 2021-02-19 08:10:15 +01:00
statistics Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
storage Fix typo and outdated information in README.barrier 2021-05-18 09:54:56 +12:00
tcop Restore the portal-level snapshot after procedure COMMIT/ROLLBACK. 2021-05-21 14:03:59 -04:00
tsearch Fix typos and grammar in comments and docs 2021-04-19 11:32:30 +09:00
utils Improve some error wording with multirange type parsing 2021-05-31 11:35:00 +09:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
Makefile Use sort_template.h for qsort_tuple() and qsort_ssup(). 2021-03-03 17:02:32 +13:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
nls.mk Translation updates 2021-05-10 14:36:21 +02:00