forked from postgres/postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
Introduce the ability to set index visibility using ALTER INDEX #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shayonj
wants to merge
1
commit into
master
Choose a base branch
from
s/enable-disable-index
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76503e7
to
498d2ec
Compare
4e9c6f2
to
15da0f3
Compare
24c3439
to
848b143
Compare
a036bf8
to
4e7be6e
Compare
3199d30
to
0a096b3
Compare
e5d2fa2
to
e64b19d
Compare
348c1f2
to
99ab5b6
Compare
99ab5b6
to
28dabf9
Compare
52dac01
to
6445a66
Compare
a0669d9
to
70b1b61
Compare
f59758a
to
3792fbd
Compare
3792fbd
to
13b1752
Compare
b241e6a
to
b183375
Compare
b183375
to
73422a3
Compare
This patch introduces the ability to make an index INVISIBLE ( or VISIBLE ) to the planner, making the index not eligible for planning but will continue to be maintained when the underlying data changes. This behavior is accomplished by introducing new grammar ALTER INDEX ... VISIBLE|INVISIBLE and CREATE INDEX ... VISIBLE|INVISIBLE. Additionally, there is also support for force_invisible_index GUC parameter that forces the planner to use invisible indexes. This is useful for testing and validating index behavior without changing their visibility state. Discussion: https://www.postgresql.org/message-id/flat/EF2313B8-A017-4869-9B7F-A24EDD8795DE%40gmail.com#dbe65017ffa7b65a4f3f29e64ed2fce5
73422a3
to
ee130c6
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch introduces index visibility control using ALTER INDEX and CREATE INDEX
commands.
Original motivation for the problem and proposal for a patch
can be found at [1].
This patch passes all the existing specs and the newly added regression tests. The patch
is ready for review and test. It compiles, so the patch can be applied for testing as well.
Note: The patch has gone through a few iterations. Earlier versions of the patch had the ENABLE/DISABLE grammar.
The current version has the VISIBLE/INVISIBLE grammar. So, you will the local variable names using the new grammar accordingly.
Implementation details:
New Grammar:
Default state is visible. Indexes are only invisible when explicitly
instructed via CREATE INDEX ... INVISIBLE or ALTER INDEX ... INVISIBLE.
Primary Key and Unique constraint indexes are always visible. The
VISIBLE/INVISIBLE grammar is supported for these types of indexes and they can
be made invisible via ALTER INDEX ... INVISIBLE.
ALTER INDEX ... VISIBLE/INVISIBLE performs update on the relevant row in pg_index
catalog
pg_get_indexdef() supports the new functionality and grammar. This change is
reflected in \d output for tables and pg_dump. We show the INVISIBLE syntax accordingly.
Added force_invisible_index GUC parameter that forces the planner to use invisible
indexes. This is useful for testing and validating index behavior without changing
their visibility state. Based on feedback from Sami S [2]
Updated create_index.sql regression test to cover the new grammar and verify
that invisible indexes are not used in queries. The test covers:
Adds a new indisvisible attribute to the IndexOptInfo structure.
Modifies get_relation_info in plancat.c to skip invisible indexes entirely, thus reducing the number of places we need to check if an index is invisible or not. Inspired by the conversations start at [3].
No changes are made to stop the index from getting maintained. This way we ensure no
data loss or corruption when index is made visible again.
TOAST indexes are supported and visible by default as well.
REINDEX CONCURRENTLY is supported as well and existing state of pg_index.indisvisible
is carried over accordingly.
See the changes in create_index.sql to get an idea of the grammar and sql statements.
See the changes in create_index.out to get an idea of the catalogue states and EXPLAIN
output to see when an index is getting used or isn't (when invisible).
Incorporated DavidR's feedback from [4] around documentation and also you will see that by skipping invisible indexes entirely from get_relation_info in plancat.c (as mentioned above), we address the other mentioned issues as well.
Lastly, protects against the case where indcheckxmin is true by raising ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE.
Supports index visibility status on \d (h/t to Benoit Lobréau for the patch)
Looking forward to any and all feedback on this patch, including but not limited to code quality, tests, fundamental logic.
[1] https://www.postgresql.org/message-id/CANqtF-oXKe0M%3D0QOih6H%2BsZRjE2BWAbkW_1%2B9nMEAMLxUJg5jA%40mail.gmail.com
[2] https://www.postgresql.org/message-id/CAA5RZ0udzydObMDi65C59-oq54B9ZmjSZ1wVH3h%2Bv4XiVm6QDA%40mail.gmail.com
[3] https://www.postgresql.org/message-id/3465209.1727202064%40sss.pgh.pa.us
[4] https://www.postgresql.org/message-id/CAApHDvpUNu%3DiVcdJ74sypvgeaCF%2Btfpyb8VRhZaF7DTd1xVr7g%40mail.gmail.com