postgresql/src/include/nodes
Tom Lane 5190707d74 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
2020-08-14 22:14:03 -04:00
..
bitmapset.h Use FLEXIBLE_ARRAY_MEMBER in a bunch more places. 2015-02-20 00:11:42 -05:00
execnodes.h Be more careful about the shape of hashable subplan clauses. 2020-08-14 22:14:03 -04:00
lockoptions.h Improve representation of PlanRowMark. 2015-03-15 18:41:47 -04:00
makefuncs.h Fix CREATE MATVIEW/CREATE TABLE AS ... WITH NO DATA to not plan the query. 2016-06-27 15:57:21 -04:00
memnodes.h Move memory context callback declarations into palloc.h. 2015-03-01 12:31:32 -05:00
nodeFuncs.h Selectively include window frames in expression walks/mutates. 2019-10-03 11:18:15 +01:00
nodes.h Orthography fixes for new castNode() macro. 2017-01-27 08:33:58 -05:00
params.h Use FLEXIBLE_ARRAY_MEMBER in a bunch more places. 2015-02-20 00:11:42 -05:00
parsenodes.h Revert "Skip WAL for new relfilenodes, under wal_level=minimal." 2020-03-22 09:24:15 -07:00
pg_list.h Improve castNode notation by introducing list-extraction-specific variants. 2017-04-10 13:51:29 -04:00
plannodes.h Fix improper repetition of previous results from a hashed aggregate. 2016-08-24 14:37:50 -04:00
primnodes.h Fix assorted fallout from IS [NOT] NULL patch. 2016-07-28 16:09:15 -04:00
print.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
readfuncs.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
relation.h Change more places to be less trusting of RestrictInfo.is_pushed_down. 2018-04-20 15:19:17 -04:00
replnodes.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
tidbitmap.h Use FLEXIBLE_ARRAY_MEMBER in a bunch more places. 2015-02-20 00:11:42 -05:00
value.h Update copyright for 2015 2015-01-06 11:43:47 -05:00