postgresql/src/include/optimizer
Tom Lane 9d472b51e9 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
..
clauses.h Be more careful about the shape of hashable subplan clauses. 2020-08-14 22:14:03 -04:00
cost.h Post-feature-freeze pgindent run. 2018-04-26 14:47:16 -04:00
geqo.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
geqo_copy.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
geqo_gene.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
geqo_misc.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
geqo_mutation.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
geqo_pool.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
geqo_random.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
geqo_recombination.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
geqo_selection.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
joininfo.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
orclauses.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
paramassign.h Avoid sharing PARAM_EXEC slots between different levels of NestLoop. 2019-01-11 15:54:08 -05:00
pathnode.h Fix bugs with degenerate window ORDER BY clauses in GROUPS/RANGE mode. 2018-07-11 12:07:21 -04:00
paths.h Post-feature-freeze pgindent run. 2018-04-26 14:47:16 -04:00
placeholder.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
plancat.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
planmain.h Repair bogus EPQ plans generated for postgres_fdw foreign joins. 2018-12-12 16:08:30 -05:00
planner.h Don't allow LIMIT/OFFSET clause within sub-selects to be pushed to workers. 2018-09-14 09:51:47 +05:30
predtest.h Improve predtest.c's internal docs, and enhance its functionality a bit. 2018-03-09 16:58:26 -05:00
prep.h Fix improper uses of canonicalize_qual(). 2018-03-11 18:10:42 -04:00
restrictinfo.h Fix incorrect handling of join clauses pushed into parameterized paths. 2018-04-19 15:49:30 -04:00
subselect.h Avoid sharing PARAM_EXEC slots between different levels of NestLoop. 2019-01-11 15:54:08 -05:00
tlist.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
var.h Update copyright for 2018 2018-01-02 23:30:12 -05:00