]> granicus.if.org Git - postgresql/commit
Fix incorrect varlevelsup in security_barrier_replace_vars().
authorDean Rasheed <dean.a.rasheed@gmail.com>
Mon, 29 Feb 2016 12:28:06 +0000 (12:28 +0000)
committerDean Rasheed <dean.a.rasheed@gmail.com>
Mon, 29 Feb 2016 12:28:06 +0000 (12:28 +0000)
commit41fedc24626696fdf55d0c43131d91757dbe1c66
treee9a2944a8edb49875c33aba6bdfbaf15b46b68b3
parent907e4dd2b104bdcb4af042065a92fcd73d5790ec
Fix incorrect varlevelsup in security_barrier_replace_vars().

When converting an RTE with securityQuals into a security barrier
subquery RTE, ensure that the Vars in the new subquery's targetlist
all have varlevelsup = 0 so that they correctly refer to the
underlying base relation being wrapped.

The original code was creating new Vars by copying them from existing
Vars referencing the base relation found elsewhere in the query, but
failed to account for the fact that such Vars could come from sublink
subqueries, and hence have varlevelsup > 0. In practice it looks like
this could only happen with nested security barrier views, where the
outer view has a WHERE clause containing a correlated subquery, due to
the order in which the Vars are processed.

Bug: #13988
Reported-by: Adam Guthrie
Backpatch-to: 9.4, where updatable SB views were introduced
src/backend/optimizer/prep/prepsecurity.c
src/test/regress/expected/updatable_views.out
src/test/regress/sql/updatable_views.sql