Re: pgsql: Support comments on FOREIGN DATA WRAPPER and SERVER objects.

Lists: pgsql-committerspgsql-hackers
From: Robert Haas <rhaas(at)postgresql(dot)org>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Support comments on FOREIGN DATA WRAPPER and SERVER objects.
Date: 2011-04-01 15:28:34
Message-ID: E1Q5gH4-0004Hu-4T@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

Support comments on FOREIGN DATA WRAPPER and SERVER objects.

This mostly involves making it work with the objectaddress.c framework,
which does most of the heavy lifting. In that vein, change
GetForeignDataWrapperOidByName to get_foreign_data_wrapper_oid and
GetForeignServerOidByName to get_foreign_server_oid, to match the
pattern we use for other object types.

Robert Haas and Shigeru Hanada

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/50533a6dc515cc3182f52838275c9d2a1f587604

Modified Files
--------------
doc/src/sgml/ref/comment.sgml | 2 +
src/backend/catalog/aclchk.c | 31 ++++++++++-
src/backend/catalog/objectaddress.c | 33 +++++++++++-
src/backend/commands/foreigncmds.c | 4 +-
src/backend/foreign/foreign.c | 82 ++++++++++++++--------------
src/backend/parser/gram.y | 13 +++--
src/backend/utils/adt/acl.c | 4 +-
src/include/foreign/foreign.h | 5 +-
src/include/utils/acl.h | 1 +
src/test/regress/expected/foreign_data.out | 2 +
src/test/regress/sql/foreign_data.sql | 2 +
11 files changed, 124 insertions(+), 55 deletions(-)


From: Thom Brown <thom(at)linux(dot)com>
To: Robert Haas <rhaas(at)postgresql(dot)org>
Cc: pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Support comments on FOREIGN DATA WRAPPER and SERVER objects.
Date: 2011-04-01 15:57:11
Message-ID: AANLkTi==NemsL7Vo=YfsPc8DdZActYF7ZwCFVO-0Nu21@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On 1 April 2011 16:28, Robert Haas <rhaas(at)postgresql(dot)org> wrote:
> Support comments on FOREIGN DATA WRAPPER and SERVER objects.
>
> This mostly involves making it work with the objectaddress.c framework,
> which does most of the heavy lifting.  In that vein, change
> GetForeignDataWrapperOidByName to get_foreign_data_wrapper_oid and
> GetForeignServerOidByName to get_foreign_server_oid, to match the
> pattern we use for other object types.
>
> Robert Haas and Shigeru Hanada
>
> Branch
> ------
> master
>
> Details
> -------
> http://git.postgresql.org/pg/commitdiff/50533a6dc515cc3182f52838275c9d2a1f587604
>
> Modified Files
> --------------
> doc/src/sgml/ref/comment.sgml              |    2 +
> src/backend/catalog/aclchk.c               |   31 ++++++++++-
> src/backend/catalog/objectaddress.c        |   33 +++++++++++-
> src/backend/commands/foreigncmds.c         |    4 +-
> src/backend/foreign/foreign.c              |   82 ++++++++++++++--------------
> src/backend/parser/gram.y                  |   13 +++--
> src/backend/utils/adt/acl.c                |    4 +-
> src/include/foreign/foreign.h              |    5 +-
> src/include/utils/acl.h                    |    1 +
> src/test/regress/expected/foreign_data.out |    2 +
> src/test/regress/sql/foreign_data.sql      |    2 +
> 11 files changed, 124 insertions(+), 55 deletions(-)

Should we also have support for comments on user mappings?

--
Thom Brown
Twitter: @darkixion
IRC (freenode): dark_ixion
Registered Linux user: #516935

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Thom Brown <thom(at)linux(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [COMMITTERS] pgsql: Support comments on FOREIGN DATA WRAPPER and SERVER objects.
Date: 2011-04-01 17:37:58
Message-ID: AANLkTineR1KcA0HkVX-BiOQ0ev-fiWm-vruNExDJ8_mR@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On Fri, Apr 1, 2011 at 11:57 AM, Thom Brown <thom(at)linux(dot)com> wrote:
> On 1 April 2011 16:28, Robert Haas <rhaas(at)postgresql(dot)org> wrote:
>> Support comments on FOREIGN DATA WRAPPER and SERVER objects.
>>
>> This mostly involves making it work with the objectaddress.c framework,
>> which does most of the heavy lifting.  In that vein, change
>> GetForeignDataWrapperOidByName to get_foreign_data_wrapper_oid and
>> GetForeignServerOidByName to get_foreign_server_oid, to match the
>> pattern we use for other object types.
>
> Should we also have support for comments on user mappings?

Oh, bugger. Yeah, probably.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Thom Brown <thom(at)linux(dot)com>, pgsql-hackers(at)postgresql(dot)org, hanada(at)metrosystems(dot)co(dot)jp
Subject: Re: Re: [COMMITTERS] pgsql: Support comments on FOREIGN DATA WRAPPER and SERVER objects.
Date: 2011-04-03 01:51:04
Message-ID: AANLkTi=KvkY00zjwmBsR+KNSA9b-ncWps9Oi+HdM9SVz@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

2011/4/2 Robert Haas <robertmhaas(at)gmail(dot)com>:
> On Fri, Apr 1, 2011 at 11:57 AM, Thom Brown <thom(at)linux(dot)com> wrote:
>> Should we also have support for comments on user mappings?
>
> Oh, bugger.  Yeah, probably.

I'd work on this, if taking some days is OK.

Regards,
--
Shigeru Hanada


From: Shigeru HANADA <hanada(at)metrosystems(dot)co(dot)jp>
To: Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Thom Brown <thom(at)linux(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [COMMITTERS] pgsql: Support comments on FOREIGN DATA WRAPPER and SERVER objects.
Date: 2011-04-04 10:49:09
Message-ID: 20110404194909.5EFE.6989961C@metrosystems.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On Sun, 3 Apr 2011 10:51:04 +0900
Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com> wrote:
> 2011/4/2 Robert Haas <robertmhaas(at)gmail(dot)com>:
> > On Fri, Apr 1, 2011 at 11:57 AM, Thom Brown <thom(at)linux(dot)com> wrote:
> >> Should we also have support for comments on user mappings?
> >
> > Oh, bugger.  Yeah, probably.
>
> I'd work on this, if taking some days is OK.

I've worked on this for a while and found some debatable points.

1) Who can comment on a user mapping?
Basically only the owner can comment on a object, but user mappings
don't have owner. So following rules for ALTER/DROP seems good
because they are similarly allowed to only owner. In addition to
server's owner, a user can perform ALTER/DROP USER MAPPING if target
mapping is his own user's and USAGE privilege on the server has been
granted. This means that mappings for PUBLIC can be commented by only
server's owner. Is this spec reasonable?

2) How to specify user name of the target mapping
ALTER/DROP USER MAPPING also accept USER and CURRENT_USER as current
user. This syntax seems suitable for COMMENT ON USER MAPPING too for
consistency and usability.

3) Omitting ACL framework support
ISTM that full-support of ACL framework is not necessary for USER
MAPPING because USER MAPPING has no GRANT/REVOKE statements.
COMMENT ON USER MAPPING patch works fine, but some oversight might be
here.

Please see attached patches for details.
Sorry for long patch names, I generated these patches with git
format-patch.

And, attached test_user_mapping_comments.sql is a script which I've
used to test patches locally.

Regards,
--
Shigeru Hanada

Attachment Content-Type Size
0001-Implement-COMMENT-ON-USER-MAPPING.patch application/octet-stream 7.9 KB
0002-Add-regression-tests-for-COMMENT-ON-USER-MAPPING.patch application/octet-stream 2.7 KB
0003-Document-about-COMMENT-ON-USER-MAPPING.patch application/octet-stream 3.8 KB
0004-Fix-pg_dump-to-dump-COMMENT-ON-USER-MAPPING-statemen.patch application/octet-stream 3.3 KB
0005-Fix-psql-to-complete-COMMENT-ON-USER-MAPPING-stateme.patch application/octet-stream 2.6 KB
test_user_mapping_comments.sql application/octet-stream 3.9 KB

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Shigeru HANADA <hanada(at)metrosystems(dot)co(dot)jp>
Cc: Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com>, Thom Brown <thom(at)linux(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [COMMITTERS] pgsql: Support comments on FOREIGN DATA WRAPPER and SERVER objects.
Date: 2011-04-04 16:47:18
Message-ID: BANLkTimyETAP=ZVxv4YPuSsLctvJX8eeWw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On Mon, Apr 4, 2011 at 6:49 AM, Shigeru HANADA
<hanada(at)metrosystems(dot)co(dot)jp> wrote:
> 1) Who can comment on a user mapping?
> Basically only the owner can comment on a object, but user mappings
> don't have owner.  So following rules for ALTER/DROP seems good
> because they are similarly allowed to only owner.  In addition to
> server's owner, a user can perform ALTER/DROP USER MAPPING if target
> mapping is his own user's and USAGE privilege on the server has been
> granted.  This means that mappings for PUBLIC can be commented by only
> server's owner.  Is this spec reasonable?

I guess so. The existing rules for user mapping permissions are not
really what I would have expected, but there doesn't seem to be any
particular reason to deviate from them here. I do think however that
we should try NOT to duplicate the logic in user_mapping_ddl_aclcheck
into multiple places, as someone will certainly screw that up down the
road. If we're going to have complex logic like this we need to at
least make sure that we only have one copy of it.

>> 2) How to specify user name of the target mapping
> ALTER/DROP USER MAPPING also accept USER and CURRENT_USER as current
> user.  This syntax seems suitable for COMMENT ON USER MAPPING too for
> consistency and usability.

OK, sounds fine. But what does it actually mean when you say
{ALTER|DROP|COMMENT ON} USER MAPPING FOR USER SERVER servername? I
see some code to handle CURRENT_USER, but I must be missing the
special-casing for USER. It's not documented, either. :-(

> 3) Omitting ACL framework support
> ISTM that full-support of ACL framework is not necessary for USER
> MAPPING because USER MAPPING has no GRANT/REVOKE statements.
> COMMENT ON USER MAPPING patch works fine, but some oversight might be
> here.

I agree.

BTW, I think you can merge patches 0001 to 0004 into a single patch.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Shigeru HANADA <hanada(at)metrosystems(dot)co(dot)jp>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com>, Thom Brown <thom(at)linux(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [COMMITTERS] pgsql: Support comments on FOREIGN DATA WRAPPER and SERVER objects.
Date: 2011-04-05 04:37:48
Message-ID: 20110405133748.63D9.6989961C@metrosystems.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

Thanks for the review.

On Mon, 4 Apr 2011 12:47:18 -0400
Robert Haas <robertmhaas(at)gmail(dot)com> wrote:

> On Mon, Apr 4, 2011 at 6:49 AM, Shigeru HANADA
> <hanada(at)metrosystems(dot)co(dot)jp> wrote:
> > 1) Who can comment on a user mapping?
> > Basically only the owner can comment on a object, but user mappings
> > don't have owner.  So following rules for ALTER/DROP seems good
> > because they are similarly allowed to only owner.  In addition to
> > server's owner, a user can perform ALTER/DROP USER MAPPING if target
> > mapping is his own user's and USAGE privilege on the server has been
> > granted.  This means that mappings for PUBLIC can be commented by only
> > server's owner.  Is this spec reasonable?
>
> I guess so. The existing rules for user mapping permissions are not
> really what I would have expected, but there doesn't seem to be any
> particular reason to deviate from them here. I do think however that
> we should try NOT to duplicate the logic in user_mapping_ddl_aclcheck
> into multiple places, as someone will certainly screw that up down the
> road. If we're going to have complex logic like this we need to at
> least make sure that we only have one copy of it.

Agreed, I'm going to merge them.

> >> 2) How to specify user name of the target mapping
> > ALTER/DROP USER MAPPING also accept USER and CURRENT_USER as current
> > user.  This syntax seems suitable for COMMENT ON USER MAPPING too for
> > consistency and usability.
>
> OK, sounds fine. But what does it actually mean when you say
> {ALTER|DROP|COMMENT ON} USER MAPPING FOR USER SERVER servername? I
> see some code to handle CURRENT_USER, but I must be missing the
> special-casing for USER. It's not documented, either. :-(

The statement above also operates a user mapping which was created for
current user explicitly because both USER and CURRENT_USER in the
context of authentication identifier have same meaning.

The parser transforms them into a C-lang-string "current_user" in
auth_ident of gram.y, so only "current_user" is handled in code.

Agreed with that this behavior should be documented in where
"current_user" is handled in backend code.

> > 3) Omitting ACL framework support
> > ISTM that full-support of ACL framework is not necessary for USER
> > MAPPING because USER MAPPING has no GRANT/REVOKE statements.
> > COMMENT ON USER MAPPING patch works fine, but some oversight might be
> > here.
>
> I agree.
>
> BTW, I think you can merge patches 0001 to 0004 into a single patch.

They were separated just for review, so I'll post revised and unified
patch ASAP.

Regards,
--
Shigeru Hanada


From: Shigeru HANADA <hanada(at)metrosystems(dot)co(dot)jp>
To: Shigeru HANADA <hanada(at)metrosystems(dot)co(dot)jp>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com>, Thom Brown <thom(at)linux(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [COMMITTERS] pgsql: Support comments on FOREIGN DATA WRAPPER and SERVER objects.
Date: 2011-04-05 10:03:07
Message-ID: 20110405190306.63EB.6989961C@metrosystems.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On Tue, 05 Apr 2011 13:37:48 +0900
Shigeru HANADA <hanada(at)metrosystems(dot)co(dot)jp> wrote:
> On Mon, 4 Apr 2011 12:47:18 -0400
> Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> > BTW, I think you can merge patches 0001 to 0004 into a single patch.
>
> They were separated just for review, so I'll post revised and unified
> patch ASAP.

Please find attached revised comment-on-user-mapping patches.

* The comment_user_mapping_core.patch includes syntax support, catalog
manipulation, pg_dump support, documents and regression tests.

Some functions were exposed to merge logic of user mapping owner check.

* The comment_user_mapping_psql.patch includes only psql
tab-completion feature. It can be applied separately.

Regards,
--
Shigeru Hanada

Attachment Content-Type Size
comment_user_mapping_core.patch application/octet-stream 19.9 KB
comment_user_mapping_psql.patch application/octet-stream 2.5 KB

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Shigeru HANADA <hanada(at)metrosystems(dot)co(dot)jp>
Cc: Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com>, Thom Brown <thom(at)linux(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [COMMITTERS] pgsql: Support comments on FOREIGN DATA WRAPPER and SERVER objects.
Date: 2011-04-05 16:25:42
Message-ID: BANLkTinvc7=vjU3SUi5ziECx3uPcqOtsUA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On Tue, Apr 5, 2011 at 6:03 AM, Shigeru HANADA
<hanada(at)metrosystems(dot)co(dot)jp> wrote:
> On Tue, 05 Apr 2011 13:37:48 +0900
> Shigeru HANADA <hanada(at)metrosystems(dot)co(dot)jp> wrote:
>> On Mon, 4 Apr 2011 12:47:18 -0400
>> Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>> > BTW, I think you can merge patches 0001 to 0004 into a single patch.
>>
>> They were separated just for review, so I'll post revised and unified
>> patch ASAP.
>
> Please find attached revised comment-on-user-mapping patches.
>
> * The comment_user_mapping_core.patch includes syntax support, catalog
> manipulation, pg_dump support, documents and regression tests.

I don't think it's going to fly to add a function
pg_usermapping_ownercheck() with a randomly different API than all the
parallel functions for other object types. There is probably some
more refactoring that needs to be done here to make this sane, but I'm
coming around to the view that trying to slip this into 9.1 is not the
best thing for us to be spending time on, especially considering that
it doesn't seem to be straightforward to figure out how it should
actually work. I am inclined to punt this to 9.2.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Shigeru HANADA <hanada(at)metrosystems(dot)co(dot)jp>
Cc: Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Thom Brown <thom(at)linux(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [COMMITTERS] pgsql: Support comments on FOREIGN DATA WRAPPER and SERVER objects.
Date: 2011-04-05 17:44:12
Message-ID: 1302025452.27487.0.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On mån, 2011-04-04 at 19:49 +0900, Shigeru HANADA wrote:
> 1) Who can comment on a user mapping?

I'm not sure that it's necessary to allow commenting on user mappings.
You can't comment on role grants either, for example. They're somewhat
similar things.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Shigeru HANADA <hanada(at)metrosystems(dot)co(dot)jp>, Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com>, Thom Brown <thom(at)linux(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [COMMITTERS] pgsql: Support comments on FOREIGN DATA WRAPPER and SERVER objects.
Date: 2011-04-05 18:47:51
Message-ID: 7102.1302029271@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> On Tue, Apr 5, 2011 at 6:03 AM, Shigeru HANADA
> <hanada(at)metrosystems(dot)co(dot)jp> wrote:
>> * The comment_user_mapping_core.patch includes syntax support, catalog
>> manipulation, pg_dump support, documents and regression tests.

> I don't think it's going to fly to add a function
> pg_usermapping_ownercheck() with a randomly different API than all the
> parallel functions for other object types. There is probably some
> more refactoring that needs to be done here to make this sane, but I'm
> coming around to the view that trying to slip this into 9.1 is not the
> best thing for us to be spending time on, especially considering that
> it doesn't seem to be straightforward to figure out how it should
> actually work. I am inclined to punt this to 9.2.

I agree --- this can clearly contains more worms than we expected.

Supporting user mappings in COMMENT, EXTENSION, etc is not so critical
that we should push a possibly misdesigned notion of ownership into
the system for it. Better to take our time and think about that.

(BTW, it might be useful to reconsider casts while we are thinking about
this. Those don't have a proper notion of ownership either. I'm a bit
inclined to think that we should just bite the bullet and add owner
columns to both these catalogs. But, again, let's not be hasty.)

regards, tom lane


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Shigeru HANADA <hanada(at)metrosystems(dot)co(dot)jp>, Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com>, Thom Brown <thom(at)linux(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [COMMITTERS] pgsql: Support comments on FOREIGN DATA WRAPPER and SERVER objects.
Date: 2011-04-05 21:04:21
Message-ID: 1302037461.27487.44.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On tis, 2011-04-05 at 14:47 -0400, Tom Lane wrote:
> Supporting user mappings in COMMENT, EXTENSION, etc is not so critical
> that we should push a possibly misdesigned notion of ownership into
> the system for it. Better to take our time and think about that.
>
> (BTW, it might be useful to reconsider casts while we are thinking about
> this. Those don't have a proper notion of ownership either. I'm a bit
> inclined to think that we should just bite the bullet and add owner
> columns to both these catalogs. But, again, let's not be hasty.)

As I said elsewhere, I think of user mappings as similar to role grants.
An owner there would be similar to a grantor, so it would make sense.