From: | Sami Imseih <samimseih(at)gmail(dot)com> |
---|---|
To: | Benoit Lobréau <benoit(dot)lobreau(at)gmail(dot)com> |
Cc: | Shayon Mukherjee <shayonj(at)gmail(dot)com>, Michail Nikolaev <michail(dot)nikolaev(at)gmail(dot)com>, David Rowley <dgrowleyml(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Peter Eisentraut <peter(at)eisentraut(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Proposal to Enable/Disable Index using ALTER INDEX (with patch) |
Date: | 2025-01-31 04:48:18 |
Message-ID: | CAA5RZ0s7P2e-=-7JPb4D1bMuLLW=Ln3VQ-C21C0BGzd_gQQdWQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
> I had the "BEGIN; ALTER INDEX; EXPLAIN; ROLLBACK;" scenario in mind, but
> didn't realise we acquire an AccessExclusiveLock on the index. Therefore, it's
> not possible to change the visibility within a single transaction....
> unless you don’t mind blocking all access to the relation.
>
> I read the comments at the top of "AlterTableGetLockLevel" and in the
> documentation and I understand that this behavior seems unavoidable.
> I suppose this is what was meant by the "globally visible effects" of an ALTER
> INDEX in the old discussion ? [1]
What is being discussed here is different from what I can tell. This
is referring
to the index changing status ( visible/invisible ) and those changes being
visible by another transaction.
However, the current patch may be too restrictive. Why do we need
an AccessExclusiveLock on the table to perform the change. We are
only changing the catalog and not the underlying data. This is a lot like
ALTER INDEX RENAME, which only takes a ShareUpdateExclusiveLock.
Can we do the same here?
I am also still reviewing and have a few comments on v9
1/ Missing ATSimpleRecursion call in PrepCmd for
case AT_SetIndexVisible:
case AT_SetIndexInvisible:
Without the recursion call, the visibility changes on a
parent will not apply to the partitions. We are also
missing tests for partitions.
2/ In ATExecSetIndexVisibility
Change:
elog(ERROR, "could not find tuple for index %u", indexOid);
To:
elog(ERROR, "cache lookup failed for index %u", indexOid);
I see both message formats are used all over the place,
but in tablecmds.c, the "cache lookup" variant is the one
used, so let's do that for consistency.
3/ In ATExecSetIndexVisibility
if (indexForm->indcheckxmin)
+ {
+ heap_freetuple(indexTuple);
+ table_close(pg_index, RowExclusiveLock);
+ ereport(ERROR,
There is no need to close the table or free the tuple, as
these are "cleaned up" when the transaction aborts.
4/ In ATExecSetIndexVisibility
I have a suggestion below:
What about we open both heapOid and IndexRelationId
at the start and close them at the end. Also,
inside the block for indexForm->indisvisible != visible,
do the work to invalidate the cache, invoke the post
alter hook and increment the command counter. This will
also allow us to get rid of the update boolean as well.
What do you think?
Regards,
Sami
From | Date | Subject | |
---|---|---|---|
Next Message | Andrei Lepikhov | 2025-01-31 04:57:46 | Re: Removing unneeded self joins |
Previous Message | Michael Paquier | 2025-01-31 04:37:03 | Re: [PATCH] Optionally record Plan IDs to track plan changes for a query |