Thread: Simplify calls of pg_class_aclcheck when multiple modes are used

Simplify calls of pg_class_aclcheck when multiple modes are used

From
Michael Paquier
Date:
Hi all,

In a couple of code paths we do the following to check permissions on an object:
if (pg_class_aclcheck(relid, userid, ACL_USAGE) != ACLCHECK_OK &&
    pg_class_aclcheck(relid, userid, ACL_UPDATE) != ACLCHECK_OK)
    ereport(ERROR, blah);

Wouldn't it be better to simplify that with a single call of pg_class_aclcheck, gathering together the modes that need to be checked? In the case above, the call to pg_class_aclcheck would become like that:
if (pg_class_aclcheck(relid, userid,
         ACL_USAGE | ACL_UPDATE) != ACLCHECK_OK)
    ereport(ERROR, blah);

That's not a critical thing, but it would save some cycles. Patch is attached.
Regards,
--
Michael
Attachment

Re: Simplify calls of pg_class_aclcheck when multiple modes are used

From
Fabrízio de Royes Mello
Date:
<div dir="ltr"><div class="gmail_extra">On Wed, Aug 27, 2014 at 9:02 AM, Michael Paquier <<a
href="mailto:michael.paquier@gmail.com">michael.paquier@gmail.com</a>>wrote:<br />><br />> Hi all,<br
/>><br/>> In a couple of code paths we do the following to check permissions on an object:<br />> if
(pg_class_aclcheck(relid,userid, ACL_USAGE) != ACLCHECK_OK &&<br />>     pg_class_aclcheck(relid, userid,
ACL_UPDATE)!= ACLCHECK_OK)<br />>     ereport(ERROR, blah);<br />><br />> Wouldn't it be better to simplify
thatwith a single call of pg_class_aclcheck, gathering together the modes that need to be checked? In the case above,
thecall to pg_class_aclcheck would become like that:<br />> if (pg_class_aclcheck(relid, userid,<br />>        
 ACL_USAGE| ACL_UPDATE) != ACLCHECK_OK)<br />>     ereport(ERROR, blah);<br />><br />> That's not a critical
thing,but it would save some cycles. Patch is attached.<br />><br /><br /></div><div class="gmail_extra">I did a
littlereview:<br /></div><div class="gmail_extra">- applied to master without errors<br /></div><div
class="gmail_extra">-no compiler warnings<br /></div><div class="gmail_extra">- no regressions<br /></div><div
class="gmail_extra"><br/></div><div class="gmail_extra">It's a minor change and as Michael already said would save some
cycles.<br /><br /></div><div class="gmail_extra">Marked as "Ready for commiter".<br /></div><div
class="gmail_extra"><br/></div><div class="gmail_extra">Regards,<br /></div><div class="gmail_extra"><br />--<br
/>Fabríziode Royes Mello<br />Consultoria/Coaching PostgreSQL<br />>> Timbira: <a
href="http://www.timbira.com.br">http://www.timbira.com.br</a><br/>>> Blog: <a
href="http://fabriziomello.github.io">http://fabriziomello.github.io</a><br/>>> Linkedin: <a
href="http://br.linkedin.com/in/fabriziomello">http://br.linkedin.com/in/fabriziomello</a><br/>>> Twitter: <a
href="http://twitter.com/fabriziomello">http://twitter.com/fabriziomello</a><br/>>> Github: <a
href="http://github.com/fabriziomello">http://github.com/fabriziomello</a></div></div>

Re: Simplify calls of pg_class_aclcheck when multiple modes are used

From
Peter Eisentraut
Date:
On 8/27/14 8:02 AM, Michael Paquier wrote:
> In a couple of code paths we do the following to check permissions on an
> object:
> if (pg_class_aclcheck(relid, userid, ACL_USAGE) != ACLCHECK_OK &&
>     pg_class_aclcheck(relid, userid, ACL_UPDATE) != ACLCHECK_OK)
>     ereport(ERROR, blah);
>
> Wouldn't it be better to simplify that with a single call of
> pg_class_aclcheck, gathering together the modes that need to be checked?

Yes, it's probably just an oversight.

While looking at this, I wrote a few tests cases for sequence
privileges, because that was not covered at all.  That patch is attached.

That led me to discover this issue:
http://www.postgresql.org/message-id/5446B819.1020600@gmx.net

I'll wait for the resolution of that and then commit this.


Attachment

Re: Simplify calls of pg_class_aclcheck when multiple modes are used

From
Michael Paquier
Date:
On Wed, Oct 22, 2014 at 5:03 AM, Peter Eisentraut <peter_e@gmx.net> wrote:
While looking at this, I wrote a few tests cases for sequence
privileges, because that was not covered at all.  That patch is attached.
+1 for those tests.
--
Michael

Re: Simplify calls of pg_class_aclcheck when multiple modes are used

From
Fabrízio de Royes Mello
Date:

Em terça-feira, 21 de outubro de 2014, Michael Paquier <michael.paquier@gmail.com> escreveu:
On Wed, Oct 22, 2014 at 5:03 AM, Peter Eisentraut <peter_e@gmx.net> wrote:
While looking at this, I wrote a few tests cases for sequence
privileges, because that was not covered at all.  That patch is attached.
+1 for those tests.

 
+1

Fabrízio Mello


--
Fabrízio de Royes Mello
Consultoria/Coaching PostgreSQL

Re: Simplify calls of pg_class_aclcheck when multiple modes are used

From
Peter Eisentraut
Date:
On 10/21/14 6:19 PM, Michael Paquier wrote:
> On Wed, Oct 22, 2014 at 5:03 AM, Peter Eisentraut <peter_e@gmx.net
> <mailto:peter_e@gmx.net>> wrote:
> 
>     While looking at this, I wrote a few tests cases for sequence
>     privileges, because that was not covered at all.  That patch is
>     attached.
> 
> +1 for those tests.
> -- 
> Michael

Committed your patch and tests.



Re: Simplify calls of pg_class_aclcheck when multiple modes are used

From
Michael Paquier
Date:
On Thu, Oct 23, 2014 at 10:45 AM, Peter Eisentraut <peter_e@gmx.net> wrote:
Committed your patch and tests.
Thanks!
--
Michael