Proposal to Enable/Disable Index using ALTER INDEX - Mailing list pgsql-hackers

From Shayon Mukherjee
Subject Proposal to Enable/Disable Index using ALTER INDEX
Date
Msg-id CANqtF-oXKe0M=0QOih6H+sZRjE2BWAbkW_1+9nMEAMLxUJg5jA@mail.gmail.com
Whole thread Raw
Responses Re: Proposal to Enable/Disable Index using ALTER INDEX
Re: Proposal to Enable/Disable Index using ALTER INDEX
List pgsql-hackers
Hello hackers,

This is my first time posting here, and I’d like to propose a new feature related to PostgreSQL indexes. If this idea resonates, I’d be happy to follow up with a patch as well.

Problem:
Adding and removing indexes is a common operation in PostgreSQL. On larger databases, however, these operations can be resource-intensive. When evaluating the performance impact of one or more indexes, dropping them might not be ideal since as a user you may want a quicker way to test their effects without fully committing to removing & adding them back again. Which can be a time taking operation on larger tables.

Proposal:
I propose adding an ALTER INDEX command that allows for enabling or disabling an index globally. This could look something like:

ALTER INDEX index_name ENABLE;
ALTER INDEX index_name DISABLE;

A disabled index would still receive updates and enforce constraints as usual but would not be used for queries. This allows users to assess whether an index impacts query performance before deciding to drop it entirely.

Implementation:
To keep this simple, I suggest toggling the indisvalid flag in pg_index during the enable/disable operation.

Additional Considerations:
- Keeping the index up-to-date while it’s disabled seems preferable, as it avoids the need to rebuild the index if it’s re-enabled later. The alternative would be dropping and rebuilding the index upon re-enabling, which I believe would introduce additional overhead in terms of application logic & complexity.
- I am also proposing to reuse the existing indisvalid flag to avoid adding new state and the maintenance that comes with it, but I’m open to feedback if this approach has potential downsides.
- To keep the scope minimal for now, I propose that we only allow enabling and disabling indexes globally, and not locally, by supporting it exclusively in ALTER INDEX. I would love to know if this would break any SQL grammar promises that I might be unaware of.

I would love to learn if this sounds like a good idea and how it can be improved further. Accordingly, as a next step I would be very happy to propose a patch as well.

Best regards,  
Shayon Mukherjee

pgsql-hackers by date:

Previous
From: Daniel Gustafsson
Date:
Subject: Re: Retire support for OpenSSL 1.1.1 due to raised API requirements
Next
From: David Rowley
Date:
Subject: Re: Proposal to Enable/Disable Index using ALTER INDEX