Correctly set userid of subquery relations' child rels
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 20 Feb 2023 15:00:42 +0000 (16:00 +0100)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 20 Feb 2023 15:00:42 +0000 (16:00 +0100)
commita316a3bc6d3f57e3fe0d287d11eb4f114388b1b6
tree8d243e7406590a268c181e5c7d40d34deee5d2f6
parent94cad7a3e6040e23d51b9d4869fc20e3e56ddbf7
Correctly set userid of subquery relations' child rels

The RelOptInfo->userid field (the user ID to check permissions as) of an
"otherrel" relation was being copied from its parent relation, which is
correct in most cases but wrong when the parent is a subquery.  In that
case, using the value from the RTEPermissionInfo of the child itself is
the appropriate thing to do.

Coming up with a test case where user-visible behavior changes proves
hard enough, so we don't add one here.

Bug introduced by a61b1f74823c, discovered by Amit while reviewing
nearby code.

Author: Amit Langote <amitlangote09@gmail.com>
Discussion: https://postgr.es/m/CA+HiwqE0WY_AhLnGtTsY7eYebG212XWbM-D8gr2A_ToOHyCywQ@mail.gmail.com
src/backend/optimizer/util/relnode.c