Commit e64d3c56 authored by Peter Eisentraut's avatar Peter Eisentraut

Minimize calls of pg_class_aclcheck to minimum necessary

In a couple of code paths, pg_class_aclcheck is called in succession
with multiple different modes set.  This patch combines those modes to
have a single call of this function and reduce a bit process overhead
for permission checking.

Author: Michael Paquier <michael@otacoo.com>
Reviewed-by: default avatarFabrízio de Royes Mello <fabriziomello@gmail.com>
parent a5f7d581
...@@ -546,8 +546,8 @@ nextval_internal(Oid relid) ...@@ -546,8 +546,8 @@ nextval_internal(Oid relid)
/* open and AccessShareLock sequence */ /* open and AccessShareLock sequence */
init_sequence(relid, &elm, &seqrel); init_sequence(relid, &elm, &seqrel);
if (pg_class_aclcheck(elm->relid, GetUserId(), ACL_USAGE) != ACLCHECK_OK && if (pg_class_aclcheck(elm->relid, GetUserId(),
pg_class_aclcheck(elm->relid, GetUserId(), ACL_UPDATE) != ACLCHECK_OK) ACL_USAGE | ACL_UPDATE) != ACLCHECK_OK)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied for sequence %s", errmsg("permission denied for sequence %s",
...@@ -759,8 +759,8 @@ currval_oid(PG_FUNCTION_ARGS) ...@@ -759,8 +759,8 @@ currval_oid(PG_FUNCTION_ARGS)
/* open and AccessShareLock sequence */ /* open and AccessShareLock sequence */
init_sequence(relid, &elm, &seqrel); init_sequence(relid, &elm, &seqrel);
if (pg_class_aclcheck(elm->relid, GetUserId(), ACL_SELECT) != ACLCHECK_OK && if (pg_class_aclcheck(elm->relid, GetUserId(),
pg_class_aclcheck(elm->relid, GetUserId(), ACL_USAGE) != ACLCHECK_OK) ACL_SELECT | ACL_USAGE) != ACLCHECK_OK)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied for sequence %s", errmsg("permission denied for sequence %s",
...@@ -801,8 +801,8 @@ lastval(PG_FUNCTION_ARGS) ...@@ -801,8 +801,8 @@ lastval(PG_FUNCTION_ARGS)
/* nextval() must have already been called for this sequence */ /* nextval() must have already been called for this sequence */
Assert(last_used_seq->last_valid); Assert(last_used_seq->last_valid);
if (pg_class_aclcheck(last_used_seq->relid, GetUserId(), ACL_SELECT) != ACLCHECK_OK && if (pg_class_aclcheck(last_used_seq->relid, GetUserId(),
pg_class_aclcheck(last_used_seq->relid, GetUserId(), ACL_USAGE) != ACLCHECK_OK) ACL_SELECT | ACL_USAGE) != ACLCHECK_OK)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied for sequence %s", errmsg("permission denied for sequence %s",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment