Proposal to have INCLUDE/EXCLUDE options for altering option values

Started by Ayush Vatsaover 2 years ago7 messageshackers

Thread notes

1 note#feature#minor#enhancement
hackorum-bot#feature#minor#enhancement
hackorum-bot
1 day ago

@global #feature #minor #enhancement

#feature#minor#enhancement
Jump to latest
#1Ayush Vatsa
ayushvatsa1810@gmail.com

Hi PostgreSQL Community,
Recently I have been working on foreign servers regarding my project and
wanted to add some extensions in server options to support query pushdown.
For this, suppose I had 20 extensions in the beginning I used ALTER SERVER
srv OPTIONS (ADD EXTENSIONS 'all 20 extensions'), then again, I had to add
a few or drop some, I had to write names of all the 20 extensions
including/excluding some.
I wonder why we can't have some sort of INCLUDE / EXCLUDE option for this
use case that can be useful for other options as well which have
comma-separated values. I believe this is a useful feature to have for the
users.
Since I needed that support, I took the initiative to contribute to the
community. In addition, I have improved the documentation too as currently
while reading the documentation it looks like ADD can be used multiple
times even to include some values on top of existing values.
Attached is the patch for the same. Looking forward to your feedback.

Regards
Ayush Vatsa
Amazon Web Services (AWS)

Attachments:

v1-0001-Enhance-CREATE-ALTER-statement-with-extended-supp.patchapplication/x-patch; name=v1-0001-Enhance-CREATE-ALTER-statement-with-extended-supp.patchDownload+269-33
#2Ayush Vatsa
ayushvatsa1810@gmail.com
In reply to: Ayush Vatsa (#1)
Re: Proposal to have INCLUDE/EXCLUDE options for altering option values

Added a CF entry for the same - https://commitfest.postgresql.org/48/4955/

Regards
Ayush Vatsa
Amazon Web Services (AWS)

On Fri, 26 Apr 2024 at 11:05, Ayush Vatsa <ayushvatsa1810@gmail.com> wrote:

Show quoted text

Hi PostgreSQL Community,
Recently I have been working on foreign servers regarding my project and
wanted to add some extensions in server options to support query pushdown.
For this, suppose I had 20 extensions in the beginning I used ALTER SERVER
srv OPTIONS (ADD EXTENSIONS 'all 20 extensions'), then again, I had to add
a few or drop some, I had to write names of all the 20 extensions
including/excluding some.
I wonder why we can't have some sort of INCLUDE / EXCLUDE option for this
use case that can be useful for other options as well which have
comma-separated values. I believe this is a useful feature to have for the
users.
Since I needed that support, I took the initiative to contribute to the
community. In addition, I have improved the documentation too as currently
while reading the documentation it looks like ADD can be used multiple
times even to include some values on top of existing values.
Attached is the patch for the same. Looking forward to your feedback.

Regards
Ayush Vatsa
Amazon Web Services (AWS)

#3Ayush Vatsa
ayushvatsa1810@gmail.com
In reply to: Ayush Vatsa (#2)
Re: Proposal to have INCLUDE/EXCLUDE options for altering option values

Hi PostgreSQL Community,
I would like to provide an update on the patch I previously submitted,
along with a clearer explanation of the issue it addresses
and the improvements it introduces.
Current Issue:
PostgreSQL currently supports several options with actions like ADD, SET,
and DROP for foreign servers, user mappings,
foreign tables, etc. For example, the syntax for modifying a server option
is as follows:

ALTER SERVER name [ VERSION 'new_version' ]
[ OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ] ) ]

However, there is a limitations with the current approach:

If a user wants to add new values to an existing option, they can use:
ALTER SERVER foo OPTIONS (ADD extensions 'ext1,ext2');
But when modifying existing values, users must repeat all the existing
values along with the new ones:
ALTER SERVER foo OPTIONS (ADD extensions 'ext1,ext2');
ALTER SERVER foo OPTIONS (SET extensions 'ext1,ext2,ext3');

This repetition can be cumbersome and error-prone when there are large
number of comma separated values.

Proposed Solution:
To address this, I propose introducing two new actions: APPEND and REMOVE.
These will allow users to modify existing
values without needing to repeat all current entries.
ALTER SERVER foo OPTIONS (APPEND extensions 'ext4,ext5,ext6');
--extensions will be like 'ext1,ext2,ext3,ext4,ext5,ext6'
ALTER SERVER foo OPTIONS (REMOVE extensions 'ext1');
--extensions will be like 'ext2,ext4,ext5,ext6'

I had an off-site discussion with Nathan Bossart (bossartn) and have
incorporated his feedback about changing actions
name to be more clear into the updated patch. Furthermore, I noticed that
the documentation for the existing actions
could be clearer, so I have revised it as well. The documentation for the
newly proposed actions is included in a separate patch.
Looking forward to your comments and feedback.

Regards
Ayush Vatsa
AWS

Attachments:

v2-0001-Enhance-ALTER-statement-with-extended-support-for.patchapplication/octet-stream; name=v2-0001-Enhance-ALTER-statement-with-extended-support-for.patchDownload+132-14
v2-0002-fix-alter_server-alter_foreign_data_wrapper-alter.patchapplication/octet-stream; name=v2-0002-fix-alter_server-alter_foreign_data_wrapper-alter.patchDownload+167-29
#4Ayush Vatsa
ayushvatsa1810@gmail.com
In reply to: Ayush Vatsa (#3)
Re: Proposal to have INCLUDE/EXCLUDE options for altering option values

Hello PostgreSQL Community,
I noticed that my last commit needs rebase through cfbot -
http://cfbot.cputube.org/ayush-vatsa.html
PFA the rebased patch for the same.

Regards
Ayush Vatsa
AWS

Attachments:

t49533_4
v3-0002-fix-alter_server-alter_foreign_data_wrapper-alter.patchapplication/octet-stream; name=v3-0002-fix-alter_server-alter_foreign_data_wrapper-alter.patchDownload+167-29
v3-0001-Enhance-ALTER-statement-with-extended-support-for.patchapplication/octet-stream; name=v3-0001-Enhance-ALTER-statement-with-extended-support-for.patchDownload+132-14
#5Robert Haas
robertmhaas@gmail.com
In reply to: Ayush Vatsa (#4)
Re: Proposal to have INCLUDE/EXCLUDE options for altering option values

On Mon, Aug 26, 2024 at 12:34 PM Ayush Vatsa <ayushvatsa1810@gmail.com> wrote:

I noticed that my last commit needs rebase through cfbot - http://cfbot.cputube.org/ayush-vatsa.html
PFA the rebased patch for the same.

Hi Ayush,

Thanks for working on this. One problem that I notice is that your
documentation changes seem to suppose that all options are lists, but
actually most of them aren't, and these new variants wouldn't be
applicable to non-list cases. They also suppose that everybody's using
comma-separated lists specifically, but that's not required and some
extensions might be doing something different. Also, I'm not convinced
that this problem would arise often enough in practice that it's worth
adding a feature to address it. A user who has this problem can pretty
easily do some scripting to address it - e.g. SELECT the current
option value, split it on commas, add or remove whatever, and then SET
the new option value. If that were something lots of users were doing
all the time, then I think it might make a lot of sense to have a
built-in solution to make it easier, but I doubt that's the case.

--
Robert Haas
EDB: http://www.enterprisedb.com

#6Euler Taveira
euler@eulerto.com
In reply to: Ayush Vatsa (#4)
Re: Proposal to have INCLUDE/EXCLUDE options for altering option values

On Mon, Aug 26, 2024, at 1:34 PM, Ayush Vatsa wrote:

I noticed that my last commit needs rebase through cfbot - http://cfbot.cputube.org/ayush-vatsa.html
PFA the rebased patch for the same.

There is no list concept for OPTIONS. What happen if you use it in a non-list
value?

ALTER SERVER foo OPTIONS(ADD bar '1');
ALTER SERVER foo OPTIONS(REMOVE bar '1');

Error? Remove option 'bar'?

This proposal is not idempotent. It means that at the end of the SQL commands,
the final state is not predictable. That's disappointed since some tools rely on
this property to create migration scripts.

The syntax is not SQL standard. It does not mean that we cannot extend the
standard but sometimes it is a sign that it is not very useful or the current syntax
already covers all cases.

AFAICS this proposal also represents a tiny use case. The options to define a
foreign server don't generally include a list as value. And if so, it is not
common to change the foreign server options.

I also think that REMOVE is a synonym for DROP. It would be confuse to explain
that REMOVE is for list elements and DROP is for the list.

I'm not convinced that this new syntax improves the user experience.

--
Euler Taveira
EDB https://www.enterprisedb.com/

#7Ayush Vatsa
ayushvatsa1810@gmail.com
In reply to: Euler Taveira (#6)
Re: Proposal to have INCLUDE/EXCLUDE options for altering option values

I'm not convinced
that this problem would arise often enough in practice that it's worth
adding a feature to address it. A user who has this problem can pretty
easily do some scripting to address it

AFAICS this proposal also represents a tiny use case.

Thanks Robert and Euler for the feedback.
Ack, Initially while working on the solution I thought this can be a common
problem. But I agree if the use case is small we can postpone supporting
such syntax for the future.
I can then withdraw the patch.

Regards
Ayush Vatsa
AWS