Refactor recordExtObjInitPriv()

Started by Peter Eisentrautover 3 years ago8 messageshackers
Jump to latest
#1Peter Eisentraut
peter_e@gmx.net

Another aclchk.c refactoring patch, similar to [0]/messages/by-id/95c30f96-4060-2f48-98b5-a4392d3b6066@enterprisedb.com and [1]/messages/by-id/22c7e802-4e7d-8d87-8b71-cba95e6f4bcf@enterprisedb.com.

Refactor recordExtObjInitPriv(): Instead of half a dozen of
mostly-duplicate conditional branches, write one common one that can
handle most catalogs. We already have all the information we need, such
as which system catalog corresponds to which catalog table and which
column is the ACL column.

[0]: /messages/by-id/95c30f96-4060-2f48-98b5-a4392d3b6066@enterprisedb.com
/messages/by-id/95c30f96-4060-2f48-98b5-a4392d3b6066@enterprisedb.com
[1]: /messages/by-id/22c7e802-4e7d-8d87-8b71-cba95e6f4bcf@enterprisedb.com
/messages/by-id/22c7e802-4e7d-8d87-8b71-cba95e6f4bcf@enterprisedb.com

Attachments:

0001-Refactor-recordExtObjInitPriv.patchtext/plain; charset=UTF-8; name=0001-Refactor-recordExtObjInitPriv.patchDownload+8-146
#2Nathan Bossart
nathandbossart@gmail.com
In reply to: Peter Eisentraut (#1)
Re: Refactor recordExtObjInitPriv()

On Tue, Dec 27, 2022 at 09:56:10AM +0100, Peter Eisentraut wrote:

Refactor recordExtObjInitPriv(): Instead of half a dozen of
mostly-duplicate conditional branches, write one common one that can handle
most catalogs. We already have all the information we need, such as which
system catalog corresponds to which catalog table and which column is the
ACL column.

This seems reasonable.

+	/* This will error on unsupported classoid. */
+	else if (get_object_attnum_acl(classoid))

nitpick: I would suggest explicitly checking that it isn't
InvalidAttrNumber instead of relying on it always being 0.

- classoid == AggregateRelationId ||

I noticed that AggregateRelationId isn't listed in the ObjectProperty
array, so I think recordExtObjInitPriv() will begin erroring for that
classoid instead of ignoring it like we do today.

--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com

#3Peter Eisentraut
peter_e@gmx.net
In reply to: Nathan Bossart (#2)
Re: Refactor recordExtObjInitPriv()

On 12.01.23 01:04, Nathan Bossart wrote:

- classoid == AggregateRelationId ||

I noticed that AggregateRelationId isn't listed in the ObjectProperty
array, so I think recordExtObjInitPriv() will begin erroring for that
classoid instead of ignoring it like we do today.

Hmm, we do have some extensions in contrib that add aggregates (citext,
intagg). I suspect that the aggregate function is actually registered
into the extension via its pg_proc entry, so this wouldn't actually
matter. But maybe the commenting should be clearer?

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#3)
Re: Refactor recordExtObjInitPriv()

Peter Eisentraut <peter.eisentraut@enterprisedb.com> writes:

On 12.01.23 01:04, Nathan Bossart wrote:
- classoid == AggregateRelationId ||

I noticed that AggregateRelationId isn't listed in the ObjectProperty
array, so I think recordExtObjInitPriv() will begin erroring for that
classoid instead of ignoring it like we do today.

Hmm, we do have some extensions in contrib that add aggregates (citext,
intagg). I suspect that the aggregate function is actually registered
into the extension via its pg_proc entry, so this wouldn't actually
matter. But maybe the commenting should be clearer?

Yeah, I don't believe that AggregateRelationId is used in object
addresses; we just refer to pg_proc for any kind of function including
aggregates. Note that there is no "oid" column in pg_aggregate.

regards, tom lane

#5Nathan Bossart
nathandbossart@gmail.com
In reply to: Tom Lane (#4)
Re: Refactor recordExtObjInitPriv()

On Thu, Jan 12, 2023 at 12:20:50PM -0500, Tom Lane wrote:

Peter Eisentraut <peter.eisentraut@enterprisedb.com> writes:

On 12.01.23 01:04, Nathan Bossart wrote:
- classoid == AggregateRelationId ||

I noticed that AggregateRelationId isn't listed in the ObjectProperty
array, so I think recordExtObjInitPriv() will begin erroring for that
classoid instead of ignoring it like we do today.

Hmm, we do have some extensions in contrib that add aggregates (citext,
intagg). I suspect that the aggregate function is actually registered
into the extension via its pg_proc entry, so this wouldn't actually
matter. But maybe the commenting should be clearer?

Yeah, I don't believe that AggregateRelationId is used in object
addresses; we just refer to pg_proc for any kind of function including
aggregates. Note that there is no "oid" column in pg_aggregate.

Got it, thanks for clarifying.

--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com

#6Peter Eisentraut
peter_e@gmx.net
In reply to: Nathan Bossart (#5)
Re: Refactor recordExtObjInitPriv()

On 12.01.23 18:40, Nathan Bossart wrote:

On Thu, Jan 12, 2023 at 12:20:50PM -0500, Tom Lane wrote:

Peter Eisentraut <peter.eisentraut@enterprisedb.com> writes:

On 12.01.23 01:04, Nathan Bossart wrote:
- classoid == AggregateRelationId ||

I noticed that AggregateRelationId isn't listed in the ObjectProperty
array, so I think recordExtObjInitPriv() will begin erroring for that
classoid instead of ignoring it like we do today.

Hmm, we do have some extensions in contrib that add aggregates (citext,
intagg). I suspect that the aggregate function is actually registered
into the extension via its pg_proc entry, so this wouldn't actually
matter. But maybe the commenting should be clearer?

Yeah, I don't believe that AggregateRelationId is used in object
addresses; we just refer to pg_proc for any kind of function including
aggregates. Note that there is no "oid" column in pg_aggregate.

Got it, thanks for clarifying.

I have updated the patch as you suggested and split out the aggregate
issue into a separate patch for clarity.

Attachments:

v2-0001-Remove-AggregateRelationId-from-recordExtObjInitP.patchtext/plain; charset=UTF-8; name=v2-0001-Remove-AggregateRelationId-from-recordExtObjInitP.patchDownload+0-2
v2-0002-Refactor-recordExtObjInitPriv.patchtext/plain; charset=UTF-8; name=v2-0002-Refactor-recordExtObjInitPriv.patchDownload+8-145
#7Nathan Bossart
nathandbossart@gmail.com
In reply to: Peter Eisentraut (#6)
Re: Refactor recordExtObjInitPriv()

On Mon, Jan 16, 2023 at 12:01:47PM +0100, Peter Eisentraut wrote:

I have updated the patch as you suggested and split out the aggregate issue
into a separate patch for clarity.

LGTM

--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com

#8Peter Eisentraut
peter_e@gmx.net
In reply to: Nathan Bossart (#7)
Re: Refactor recordExtObjInitPriv()

On 16.01.23 23:43, Nathan Bossart wrote:

On Mon, Jan 16, 2023 at 12:01:47PM +0100, Peter Eisentraut wrote:

I have updated the patch as you suggested and split out the aggregate issue
into a separate patch for clarity.

LGTM

committed