From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
Subject: | pgsql: Be more careful about the shape of hashable subplan clauses. |
Date: | 2020-08-15 02:14:35 |
Message-ID: | E1k6liN-0002pC-Km@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
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(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Amit Kapila | 2020-08-15 03:14:26 | pgsql: Mark a few logical decoding related variables with PGDLLIMPORT. |
Previous Message | Andres Freund | 2020-08-14 22:40:13 | pgsql: snapshot scalability: Move PGXACT->vacuumFlags to ProcGlobal->va |