From 4e7c860765f0943736a0b848bda25b941b0fc7ba Mon Sep 17 00:00:00 2001 From: amitlan Date: Sun, 11 Dec 2022 17:57:17 +0900 Subject: [PATCH v3 3/3] Correctly set userid of subquery rel's child rels For a RTE_SUBQUERY parent baserel's child relation that itself is a RTE_RELATION rel, build_simple_rel() should explicitly look up the latter's RTEPermissionInfo instead of copying the parent rel's userid, which would be 0 given that it's a subquery rel. --- src/backend/optimizer/util/relnode.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c index 0a5632699d..ff1b61dbd0 100644 --- a/src/backend/optimizer/util/relnode.c +++ b/src/backend/optimizer/util/relnode.c @@ -228,10 +228,14 @@ build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent) { /* * Get the userid from the relation's RTEPermissionInfo, though only - * the tables mentioned in query are assigned RTEPermissionInfos. - * Child relations (otherrels) simply use the parent's value. + * the tables mentioned in the query are assigned RTEPermissionInfos. + * So, for child relations (otherrels), simply use the parent's value, + * unless the parent is a subquery base rel. */ - if (parent == NULL) + Assert(parent == NULL || + parent->rtekind == RTE_RELATION || + parent->rtekind == RTE_SUBQUERY); + if (parent == NULL || parent->rtekind == RTE_SUBQUERY) { RTEPermissionInfo *perminfo; -- 2.35.3