Re: missing rename support

Lists: pgsql-hackers
From: Ali Dar <ali(dot)munir(dot)dar(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: missing rename support
Date: 2013-01-03 13:49:07
Message-ID: CAAj60S5nndCr0me5qsVPy5rPVJjtOGCjDin-zJQGWEP7bhdijw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Dec 3, 2011 at 4:46 PM, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> I noticed the following object types don't have support for an ALTER ...
> RENAME command:
>
> DOMAIN (but ALTER TYPE works)
> FOREIGN DATA WRAPPER
> OPERATOR
> RULE
> SERVER
>
> Are there any restrictions why these couldn't be added?

> I don't think so. There's no ALTER RULE command; should we add one
(matching ALTER TRIGGER) or make this part of ALTER TABLE? I don't
think constraints can be renamed either, which should probably be
addressed along with rules.

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

Find attached an initial patch for ALTER RENAME RULE feature. Please
note that it does not have any documentation yet.

Attachment Content-Type Size
Alter_Rule_Rename.patch application/octet-stream 4.0 KB

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Ali Dar <ali(dot)munir(dot)dar(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: missing rename support
Date: 2013-01-18 18:20:27
Message-ID: 20130118182027.GE16126@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Ali Dar (ali(dot)munir(dot)dar(at)gmail(dot)com) wrote:
> Find attached an initial patch for ALTER RENAME RULE feature. Please
> note that it does not have any documentation yet.

Just took a quick look through this. Seems to be alright, but why do we
allow renaming ON SELECT rules at all, given that they must be named
_RETURN? My thinking would be to check for that case and error out if
someone tries it.

You should try to keep variables lined up:

Relation pg_rewrite_desc;
HeapTuple ruletup;
+ Oid owningRel;

should be:

Relation pg_rewrite_desc;
HeapTuple ruletup;
+ Oid owningRel;

I'd also strongly recommend looking through that entire function very
carefully. Code that's been #ifdef'd out tends to rot.

Thanks,

Stephen


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Ali Dar <ali(dot)munir(dot)dar(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: missing rename support
Date: 2013-01-18 18:54:58
Message-ID: 11703.1358535298@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:
> * Ali Dar (ali(dot)munir(dot)dar(at)gmail(dot)com) wrote:
>> Find attached an initial patch for ALTER RENAME RULE feature. Please
>> note that it does not have any documentation yet.

> Just took a quick look through this. Seems to be alright, but why do we
> allow renaming ON SELECT rules at all, given that they must be named
> _RETURN? My thinking would be to check for that case and error out if
> someone tries it.

Agreed, we should exclude ON SELECT rules.

> You should try to keep variables lined up:

pgindent is probably a better answer than trying to get this right
manually.

regards, tom lane


From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Ali Dar <ali(dot)munir(dot)dar(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: missing rename support
Date: 2013-01-20 19:34:22
Message-ID: CAEZATCXEi7gF4_qyuzuBYBr7kUD7S-nxH0GG=O7HsJG5gs8YuA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 3 January 2013 13:49, Ali Dar <ali(dot)munir(dot)dar(at)gmail(dot)com> wrote:
> Find attached an initial patch for ALTER RENAME RULE feature. Please note
> that it does not have any documentation yet.
>

Hi,

I just got round to looking at this. All-in-all it looks OK. I just
have a few more review comments, in addition to Stephen's comment
about renaming SELECT rules...

This compiler warning should be fixed with another #include:
alter.c:107:4: warning: implicit declaration of function ‘RenameRewriteRule’

In gram.y, I think you can just use qualified_name instead of
makeRangeVarFromAnyName().

In RenameRewriteRule(), I think it's worth doing a check to ensure
that the relation actually is a table or a view (you might have some
other relation kind at that point in the code). If the user
accidentally types the name of an index, say, instead of a table, then
it is better to throw an error saying "xxx is not a table or a view"
rather than reporting that the rule doesn't exist.

I think this could probably use some simple regression tests to test
both the success and failure cases.

It would be nice to extend psql tab completion to support this too,
although perhaps that could be done as a separate patch.

Don't forget the docs!

Regards,
Dean


From: Ali Dar <ali(dot)munir(dot)dar(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: missing rename support
Date: 2013-01-29 15:34:53
Message-ID: CAAj60S4wC=Cwao082t8BATx9aeHmBr3H49GJcbfb-tjMhYOeLw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Please find attached the complete patch for alter rename rule. I have
followed all the suggestions. Followings things are added in this updated
patch:
1) Disallow alter rename of ON SELECT rules.
2) Remove warning.
3) Varibles are lined up.
4) Used qualified_name instead of makeRangeVarFromAnyName.
5) Throw appropriate error if user tries to alter rename rule on irrelavent
object(e.g index).
6) Psql tab support added
7) Regression test cases added.
8) Documentation added.

Regards,
Ali Dar

On Mon, Jan 21, 2013 at 12:34 AM, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>wrote:

> On 3 January 2013 13:49, Ali Dar <ali(dot)munir(dot)dar(at)gmail(dot)com> wrote:
> > Find attached an initial patch for ALTER RENAME RULE feature. Please note
> > that it does not have any documentation yet.
> >
>
> Hi,
>
> I just got round to looking at this. All-in-all it looks OK. I just
> have a few more review comments, in addition to Stephen's comment
> about renaming SELECT rules...
>
> This compiler warning should be fixed with another #include:
> alter.c:107:4: warning: implicit declaration of function
> ‘RenameRewriteRule’
>
> In gram.y, I think you can just use qualified_name instead of
> makeRangeVarFromAnyName().
>
> In RenameRewriteRule(), I think it's worth doing a check to ensure
> that the relation actually is a table or a view (you might have some
> other relation kind at that point in the code). If the user
> accidentally types the name of an index, say, instead of a table, then
> it is better to throw an error saying "xxx is not a table or a view"
> rather than reporting that the rule doesn't exist.
>
> I think this could probably use some simple regression tests to test
> both the success and failure cases.
>
> It would be nice to extend psql tab completion to support this too,
> although perhaps that could be done as a separate patch.
>
> Don't forget the docs!
>
> Regards,
> Dean
>

Attachment Content-Type Size
alter-rule-rename_complete.patch application/octet-stream 13.1 KB

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Ali Dar <ali(dot)munir(dot)dar(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: missing rename support
Date: 2013-02-03 15:04:48
Message-ID: CAEZATCVaSsSi5LNAwQUCpAP7mHt4mYZq_Z6yRFs_Q_NtwxiwWA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 29 January 2013 15:34, Ali Dar <ali(dot)munir(dot)dar(at)gmail(dot)com> wrote:
> Please find attached the complete patch for alter rename rule. I have
> followed all the suggestions.

This looks good. I've tested it, and it appears to work as intended.
I'm happy with the code, and the new docs and regression tests look
OK.

I have a couple of minor tweaks (see attached):

* On the new manual page, I replaced "table" with "table or view".

* In the new tab-completion code, I modified the query so that it
completes with tables as well as views, and limited the results to
just those relations that have a rule with the name specified,
otherwise the list of completions could be very long.

If you're happy with these changes, I think this is ready for committer review.

Regards,
Dean

Attachment Content-Type Size
alter-rule-rename_complete.v2.patch application/octet-stream 14.0 KB

From: Ali Dar <ali(dot)munir(dot)dar(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: missing rename support
Date: 2013-02-04 12:48:44
Message-ID: CAAj60S5W6Q=atye3gYtRd478R85WyRxoGd1-Zm1RuoqDPciVOw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

The tweaks made by you seems fine. I'm good with it.

Regards,
Ali Dar

On Sun, Feb 3, 2013 at 8:04 PM, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>wrote:

> On 29 January 2013 15:34, Ali Dar <ali(dot)munir(dot)dar(at)gmail(dot)com> wrote:
> > Please find attached the complete patch for alter rename rule. I have
> > followed all the suggestions.
>
> This looks good. I've tested it, and it appears to work as intended.
> I'm happy with the code, and the new docs and regression tests look
> OK.
>
> I have a couple of minor tweaks (see attached):
>
> * On the new manual page, I replaced "table" with "table or view".
>
> * In the new tab-completion code, I modified the query so that it
> completes with tables as well as views, and limited the results to
> just those relations that have a rule with the name specified,
> otherwise the list of completions could be very long.
>
> If you're happy with these changes, I think this is ready for committer
> review.
>
> Regards,
> Dean
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Ali Dar <ali(dot)munir(dot)dar(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: missing rename support
Date: 2013-02-09 05:09:43
Message-ID: 16616.1360386583@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> writes:
> [ alter-rule-rename_complete.v2.patch ]

Committed with assorted editorialization. Aside from cosmetic issues,
the main changes were:

* use RangeVarGetRelidExtended with a callback to perform the lookup
and locking of the target relation. This is a new API that the original
version of RenameRewriteRule couldn't have known about. I borrowed the
code pretty much verbatim from renametrig(), and am now wondering
whether there shouldn't be some attempt to unify the callbacks for this.

* call CacheInvalidateRelcache to ensure that other sessions notice the
rule tuple update. It may be that this isn't necessary because nothing
looks at the rule name fields in relcache entries ... but I wouldn't bet
on that, and in any case it seems like bad practice to let stale cache
entries hang around.

regards, tom lane