1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-31 22:04:40 +03:00

Remove some dead code in selfuncs.c

RelOptInfo.userid is the same for all relations in a given inheritance
tree, so the code in examine_variable() and example_simple_variable()
that repeats the ACL checks on the root parent rel instead of a given
leaf child relations need not recompute userid too.

Author: Amit Langote <amitlangote09@gmail.com>
Reported-by: Justin Pryzby <pryzby@telsasoft.com>
Discussion: https://postgr.es/m/20221210201753.GA27893@telsasoft.com
This commit is contained in:
Alvaro Herrera
2023-01-19 12:54:15 +01:00
parent 48880840f1
commit 438e6b7240
2 changed files with 16 additions and 27 deletions

View File

@ -5080,6 +5080,18 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
*/
ListCell *ilist;
ListCell *slist;
Oid userid;
/*
* Determine the user ID to use for privilege checks: either
* onerel->userid if it's set (e.g., in case we're accessing the table
* via a view), or the current user otherwise.
*
* If we drill down to child relations, we keep using the same userid:
* it's going to be the same anyway, due to how we set up the relation
* tree (q.v. build_simple_rel).
*/
userid = OidIsValid(onerel->userid) ? onerel->userid : GetUserId();
foreach(ilist, onerel->indexlist)
{
@ -5150,18 +5162,10 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
{
/* Get index's table for permission check */
RangeTblEntry *rte;
Oid userid;
rte = planner_rt_fetch(index->rel->relid, root);
Assert(rte->rtekind == RTE_RELATION);
/*
* Use onerel->userid if it's set, in case
* we're accessing the table via a view.
*/
userid = OidIsValid(onerel->userid) ?
onerel->userid : GetUserId();
/*
* For simplicity, we insist on the whole
* table being selectable, rather than trying
@ -5212,9 +5216,6 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
rte = planner_rt_fetch(varno, root);
Assert(rte->rtekind == RTE_RELATION);
userid = OidIsValid(onerel->userid) ?
onerel->userid : GetUserId();
vardata->acl_ok =
rte->securityQuals == NIL &&
(pg_class_aclcheck(rte->relid,
@ -5281,8 +5282,6 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
/* found a match, see if we can extract pg_statistic row */
if (equal(node, expr))
{
Oid userid;
/*
* XXX Not sure if we should cache the tuple somewhere.
* Now we just create a new copy every time.
@ -5292,13 +5291,6 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
vardata->freefunc = ReleaseDummy;
/*
* Use onerel->userid if it's set, in case we're accessing
* the table via a view.
*/
userid = OidIsValid(onerel->userid) ?
onerel->userid : GetUserId();
/*
* For simplicity, we insist on the whole table being
* selectable, rather than trying to identify which
@ -5345,9 +5337,6 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
rte = planner_rt_fetch(varno, root);
Assert(rte->rtekind == RTE_RELATION);
userid = OidIsValid(onerel->userid) ?
onerel->userid : GetUserId();
vardata->acl_ok =
rte->securityQuals == NIL &&
(pg_class_aclcheck(rte->relid,
@ -5486,9 +5475,10 @@ examine_simple_variable(PlannerInfo *root, Var *var,
rte = planner_rt_fetch(varno, root);
Assert(rte->rtekind == RTE_RELATION);
userid = OidIsValid(onerel->userid) ?
onerel->userid : GetUserId();
/*
* Fine to use the same userid as it's the same in all
* relations of a given inheritance tree.
*/
vardata->acl_ok =
rte->securityQuals == NIL &&
((pg_class_aclcheck(rte->relid, userid,