From bbfdf7180de85f9e7e995ba00dddc58452b3ba4b Mon Sep 17 00:00:00 2001 From: David Rowley Date: Sat, 24 Dec 2022 00:58:34 +1300 Subject: Fix bug in translate_col_privs_multilevel Fix incorrect code which was trying to convert a Bitmapset of columns at the attnums according to a parent table and transform them into the equivalent Bitmapset with same attnums according to the given child table. This code is new as of a61b1f748 and was failing to do the correct translation when there was an intermediate parent table between 'rel' and 'top_parent_rel'. Reported-by: Ranier Vilela Author: Richard Guo, Amit Langote Discussion: https://postgr.es/m/CAEudQArohfB_Gy%2BhcH2-bANUkxgjJiP%3DABq01_LgTNTbcNijag%40mail.gmail.com --- src/backend/optimizer/util/inherit.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/backend/optimizer/util/inherit.c') diff --git a/src/backend/optimizer/util/inherit.c b/src/backend/optimizer/util/inherit.c index f51ce45cd3b..d3b0b0d2af9 100644 --- a/src/backend/optimizer/util/inherit.c +++ b/src/backend/optimizer/util/inherit.c @@ -52,7 +52,7 @@ static Bitmapset *translate_col_privs(const Bitmapset *parent_privs, static Bitmapset *translate_col_privs_multilevel(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *top_parent_rel, - Bitmapset *top_parent_cols); + Bitmapset *parent_cols); static void expand_appendrel_subquery(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte, Index rti); @@ -923,28 +923,26 @@ apply_child_basequals(PlannerInfo *root, RelOptInfo *parentrel, /* * translate_col_privs_multilevel - * Recursively translates the column numbers contained in - * 'top_parent_cols' to the columns numbers of a descendent relation - * given by 'relid' + * Recursively translates the column numbers contained in 'parent_cols' + * to the columns numbers of a descendent relation given by 'rel' */ static Bitmapset * translate_col_privs_multilevel(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *top_parent_rel, - Bitmapset *top_parent_cols) + Bitmapset *parent_cols) { - Bitmapset *result; AppendRelInfo *appinfo; - if (top_parent_cols == NULL) + if (parent_cols == NULL) return NULL; /* Recurse if immediate parent is not the top parent. */ if (rel->parent != top_parent_rel) { if (rel->parent) - result = translate_col_privs_multilevel(root, rel->parent, - top_parent_rel, - top_parent_cols); + parent_cols = translate_col_privs_multilevel(root, rel->parent, + top_parent_rel, + parent_cols); else elog(ERROR, "rel with relid %u is not a child rel", rel->relid); } @@ -953,7 +951,5 @@ translate_col_privs_multilevel(PlannerInfo *root, RelOptInfo *rel, appinfo = root->append_rel_array[rel->relid]; Assert(appinfo != NULL); - result = translate_col_privs(top_parent_cols, appinfo->translated_vars); - - return result; + return translate_col_privs(parent_cols, appinfo->translated_vars); } -- cgit v1.2.3