diff options
author | David Rowley <drowley@postgresql.org> | 2022-12-24 00:58:34 +1300 |
---|---|---|
committer | David Rowley <drowley@postgresql.org> | 2022-12-24 00:58:34 +1300 |
commit | bbfdf7180de85f9e7e995ba00dddc58452b3ba4b (patch) | |
tree | 7fb18e6bcf19c829292fad8fad9224bf4e97dbfb /src | |
parent | b5d0f8ec01c021452203b2fd3921c9b55f6c3cd3 (diff) | |
download | postgresql-bbfdf7180de85f9e7e995ba00dddc58452b3ba4b.tar.gz postgresql-bbfdf7180de85f9e7e995ba00dddc58452b3ba4b.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/optimizer/util/inherit.c | 22 |
1 files changed, 9 insertions, 13 deletions
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); } |