Sorry, I hadn't read this email before sending my earlier "thank you for
committing" email.

On 2019/01/11 6:47, David Rowley wrote:
> On Fri, 11 Jan 2019 at 06:56, Alvaro Herrera <alvhe...@2ndquadrant.com> wrote:
>> Pushed 0001 with some minor tweaks, thanks.
> 
> Thanks for pushing.  I had looked at 0001 last night and there wasn't
> much to report, just:
> 
> v12 0001
> 
> 1. I see you've moved translate_col_privs() out of prepunion.c into
> appendinfo.c. This required making it an external function, but it's
> only use is in inherit.c, so would it not be better to put it there
> and keep it static?

Actually, I *was* a bit puzzled where to put it.  I tend to agree with you
now that it might be define it locally within inherit.c as it might not be
needed elsewhere.  Let's hear what Alvaro thinks.  I'm attaching a patch
anyway.

> 2. The following two lines I think need to swap their order.
> 
> +#include "utils/rel.h"
> +#include "utils/lsyscache.h"

Oops, fixed.

> Both are pretty minor details but thought I'd post them anyway.

Thank you for reporting.

Attached find the patch.

Regards,
Amit
diff --git a/src/backend/optimizer/util/appendinfo.c 
b/src/backend/optimizer/util/appendinfo.c
index d48e3a09b3..2f23e7bf49 100644
--- a/src/backend/optimizer/util/appendinfo.c
+++ b/src/backend/optimizer/util/appendinfo.c
@@ -15,13 +15,12 @@
 #include "postgres.h"
 
 #include "access/htup_details.h"
-#include "access/sysattr.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
 #include "optimizer/appendinfo.h"
 #include "parser/parsetree.h"
-#include "utils/rel.h"
 #include "utils/lsyscache.h"
+#include "utils/rel.h"
 #include "utils/syscache.h"
 
 
@@ -167,58 +166,6 @@ make_inh_translation_list(Relation oldrelation, Relation 
newrelation,
 }
 
 /*
- * translate_col_privs
- *       Translate a bitmapset representing per-column privileges from the
- *       parent rel's attribute numbering to the child's.
- *
- * The only surprise here is that we don't translate a parent whole-row
- * reference into a child whole-row reference.  That would mean requiring
- * permissions on all child columns, which is overly strict, since the
- * query is really only going to reference the inherited columns.  Instead
- * we set the per-column bits for all inherited columns.
- */
-Bitmapset *
-translate_col_privs(const Bitmapset *parent_privs,
-                                       List *translated_vars)
-{
-       Bitmapset  *child_privs = NULL;
-       bool            whole_row;
-       int                     attno;
-       ListCell   *lc;
-
-       /* System attributes have the same numbers in all tables */
-       for (attno = FirstLowInvalidHeapAttributeNumber + 1; attno < 0; attno++)
-       {
-               if (bms_is_member(attno - FirstLowInvalidHeapAttributeNumber,
-                                                 parent_privs))
-                       child_privs = bms_add_member(child_privs,
-                                                                               
 attno - FirstLowInvalidHeapAttributeNumber);
-       }
-
-       /* Check if parent has whole-row reference */
-       whole_row = bms_is_member(InvalidAttrNumber - 
FirstLowInvalidHeapAttributeNumber,
-                                                         parent_privs);
-
-       /* And now translate the regular user attributes, using the vars list */
-       attno = InvalidAttrNumber;
-       foreach(lc, translated_vars)
-       {
-               Var                *var = lfirst_node(Var, lc);
-
-               attno++;
-               if (var == NULL)                /* ignore dropped columns */
-                       continue;
-               if (whole_row ||
-                       bms_is_member(attno - 
FirstLowInvalidHeapAttributeNumber,
-                                                 parent_privs))
-                       child_privs = bms_add_member(child_privs,
-                                                                               
 var->varattno - FirstLowInvalidHeapAttributeNumber);
-       }
-
-       return child_privs;
-}
-
-/*
  * adjust_appendrel_attrs
  *       Copy the specified query or expression and translate Vars referring 
to a
  *       parent rel to refer to the corresponding child rel instead.  We also
diff --git a/src/backend/optimizer/util/inherit.c 
b/src/backend/optimizer/util/inherit.c
index 350e6afe27..db474acbc5 100644
--- a/src/backend/optimizer/util/inherit.c
+++ b/src/backend/optimizer/util/inherit.c
@@ -15,6 +15,7 @@
 #include "postgres.h"
 
 #include "access/heapam.h"
+#include "access/sysattr.h"
 #include "catalog/partition.h"
 #include "catalog/pg_inherits.h"
 #include "miscadmin.h"
@@ -38,6 +39,8 @@ static void expand_single_inheritance_child(PlannerInfo *root,
                                                                PlanRowMark 
*top_parentrc, Relation childrel,
                                                                List 
**appinfos, RangeTblEntry **childrte_p,
                                                                Index 
*childRTindex_p);
+static Bitmapset *translate_col_privs(const Bitmapset *parent_privs,
+                                       List *translated_vars);
 
 
 /*
@@ -437,3 +440,55 @@ expand_single_inheritance_child(PlannerInfo *root, 
RangeTblEntry *parentrte,
                root->rowMarks = lappend(root->rowMarks, childrc);
        }
 }
+
+/*
+ * translate_col_privs
+ *       Translate a bitmapset representing per-column privileges from the
+ *       parent rel's attribute numbering to the child's.
+ *
+ * The only surprise here is that we don't translate a parent whole-row
+ * reference into a child whole-row reference.  That would mean requiring
+ * permissions on all child columns, which is overly strict, since the
+ * query is really only going to reference the inherited columns.  Instead
+ * we set the per-column bits for all inherited columns.
+ */
+static Bitmapset *
+translate_col_privs(const Bitmapset *parent_privs,
+                                       List *translated_vars)
+{
+       Bitmapset  *child_privs = NULL;
+       bool            whole_row;
+       int                     attno;
+       ListCell   *lc;
+
+       /* System attributes have the same numbers in all tables */
+       for (attno = FirstLowInvalidHeapAttributeNumber + 1; attno < 0; attno++)
+       {
+               if (bms_is_member(attno - FirstLowInvalidHeapAttributeNumber,
+                                                 parent_privs))
+                       child_privs = bms_add_member(child_privs,
+                                                                               
 attno - FirstLowInvalidHeapAttributeNumber);
+       }
+
+       /* Check if parent has whole-row reference */
+       whole_row = bms_is_member(InvalidAttrNumber - 
FirstLowInvalidHeapAttributeNumber,
+                                                         parent_privs);
+
+       /* And now translate the regular user attributes, using the vars list */
+       attno = InvalidAttrNumber;
+       foreach(lc, translated_vars)
+       {
+               Var                *var = lfirst_node(Var, lc);
+
+               attno++;
+               if (var == NULL)                /* ignore dropped columns */
+                       continue;
+               if (whole_row ||
+                       bms_is_member(attno - 
FirstLowInvalidHeapAttributeNumber,
+                                                 parent_privs))
+                       child_privs = bms_add_member(child_privs,
+                                                                               
 var->varattno - FirstLowInvalidHeapAttributeNumber);
+       }
+
+       return child_privs;
+}
diff --git a/src/include/optimizer/appendinfo.h 
b/src/include/optimizer/appendinfo.h
index 16705da780..56f7192d71 100644
--- a/src/include/optimizer/appendinfo.h
+++ b/src/include/optimizer/appendinfo.h
@@ -20,8 +20,6 @@
 extern AppendRelInfo *make_append_rel_info(Relation parentrel,
                                         Relation childrel,
                                         Index parentRTindex, Index 
childRTindex);
-extern Bitmapset *translate_col_privs(const Bitmapset *parent_privs,
-                                       List *translated_vars);
 extern Node *adjust_appendrel_attrs(PlannerInfo *root, Node *node,
                                           int nappinfos, AppendRelInfo 
**appinfos);
 

Reply via email to