]> granicus.if.org Git - postgresql/commitdiff
Fix Var handling for security barrier views
authorStephen Frost <sfrost@snowman.net>
Wed, 27 Aug 2014 03:08:41 +0000 (23:08 -0400)
committerStephen Frost <sfrost@snowman.net>
Wed, 27 Aug 2014 03:37:50 +0000 (23:37 -0400)
In some cases, not all Vars were being correctly marked as having been
modified for updatable security barrier views, which resulted in invalid
plans (eg: when security barrier views were created over top of
inheiritance structures).

In passing, be sure to update both varattno and varonattno, as _equalVar
won't consider the Vars identical otherwise.  This isn't known to cause
any issues with updatable security barrier views, but was noticed as
missing while working on RLS and makes sense to get fixed.

Back-patch to 9.4 where updatable security barrier views were
introduced.

src/backend/optimizer/prep/prepsecurity.c

index dd7f9003a2801560108ced78eb35e6f2af12d1c8..2420f97a219e5afea4e2f0247bc7d041579cd179 100644 (file)
@@ -398,7 +398,9 @@ security_barrier_replace_vars_walker(Node *node,
                                        ((Var *) tle->expr)->varcollid == var->varcollid)
                                {
                                        /* Map the variable onto this subquery targetlist entry */
-                                       var->varattno = attno;
+                                       var->varattno = var->varoattno = attno;
+                                       /* Mark this var as having been processed */
+                                       context->vars_processed = lappend(context->vars_processed, var);
                                        return false;
                                }
                        }
@@ -444,7 +446,7 @@ security_barrier_replace_vars_walker(Node *node,
                                                                                makeString(pstrdup(attname)));
 
                        /* Update the outer query's variable */
-                       var->varattno = attno;
+                       var->varattno = var->varoattno = attno;
 
                        /* Remember this Var so that we don't process it again */
                        context->vars_processed = lappend(context->vars_processed, var);