@@ -5080,6 +5080,18 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
5080
5080
*/
5081
5081
ListCell * ilist ;
5082
5082
ListCell * slist ;
5083
+ Oid userid ;
5084
+
5085
+ /*
5086
+ * Determine the user ID to use for privilege checks: either
5087
+ * onerel->userid if it's set (e.g., in case we're accessing the table
5088
+ * via a view), or the current user otherwise.
5089
+ *
5090
+ * If we drill down to child relations, we keep using the same userid:
5091
+ * it's going to be the same anyway, due to how we set up the relation
5092
+ * tree (q.v. build_simple_rel).
5093
+ */
5094
+ userid = OidIsValid (onerel -> userid ) ? onerel -> userid : GetUserId ();
5083
5095
5084
5096
foreach (ilist , onerel -> indexlist )
5085
5097
{
@@ -5150,18 +5162,10 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
5150
5162
{
5151
5163
/* Get index's table for permission check */
5152
5164
RangeTblEntry * rte ;
5153
- Oid userid ;
5154
5165
5155
5166
rte = planner_rt_fetch (index -> rel -> relid , root );
5156
5167
Assert (rte -> rtekind == RTE_RELATION );
5157
5168
5158
- /*
5159
- * Use onerel->userid if it's set, in case
5160
- * we're accessing the table via a view.
5161
- */
5162
- userid = OidIsValid (onerel -> userid ) ?
5163
- onerel -> userid : GetUserId ();
5164
-
5165
5169
/*
5166
5170
* For simplicity, we insist on the whole
5167
5171
* table being selectable, rather than trying
@@ -5212,9 +5216,6 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
5212
5216
rte = planner_rt_fetch (varno , root );
5213
5217
Assert (rte -> rtekind == RTE_RELATION );
5214
5218
5215
- userid = OidIsValid (onerel -> userid ) ?
5216
- onerel -> userid : GetUserId ();
5217
-
5218
5219
vardata -> acl_ok =
5219
5220
rte -> securityQuals == NIL &&
5220
5221
(pg_class_aclcheck (rte -> relid ,
@@ -5281,8 +5282,6 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
5281
5282
/* found a match, see if we can extract pg_statistic row */
5282
5283
if (equal (node , expr ))
5283
5284
{
5284
- Oid userid ;
5285
-
5286
5285
/*
5287
5286
* XXX Not sure if we should cache the tuple somewhere.
5288
5287
* Now we just create a new copy every time.
@@ -5292,13 +5291,6 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
5292
5291
5293
5292
vardata -> freefunc = ReleaseDummy ;
5294
5293
5295
- /*
5296
- * Use onerel->userid if it's set, in case we're accessing
5297
- * the table via a view.
5298
- */
5299
- userid = OidIsValid (onerel -> userid ) ?
5300
- onerel -> userid : GetUserId ();
5301
-
5302
5294
/*
5303
5295
* For simplicity, we insist on the whole table being
5304
5296
* selectable, rather than trying to identify which
@@ -5345,9 +5337,6 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
5345
5337
rte = planner_rt_fetch (varno , root );
5346
5338
Assert (rte -> rtekind == RTE_RELATION );
5347
5339
5348
- userid = OidIsValid (onerel -> userid ) ?
5349
- onerel -> userid : GetUserId ();
5350
-
5351
5340
vardata -> acl_ok =
5352
5341
rte -> securityQuals == NIL &&
5353
5342
(pg_class_aclcheck (rte -> relid ,
@@ -5486,9 +5475,10 @@ examine_simple_variable(PlannerInfo *root, Var *var,
5486
5475
rte = planner_rt_fetch (varno , root );
5487
5476
Assert (rte -> rtekind == RTE_RELATION );
5488
5477
5489
- userid = OidIsValid (onerel -> userid ) ?
5490
- onerel -> userid : GetUserId ();
5491
-
5478
+ /*
5479
+ * Fine to use the same userid as it's the same in all
5480
+ * relations of a given inheritance tree.
5481
+ */
5492
5482
vardata -> acl_ok =
5493
5483
rte -> securityQuals == NIL &&
5494
5484
((pg_class_aclcheck (rte -> relid , userid ,
0 commit comments