Re: ALTER tbl rewrite loses CLUSTER ON index
Justin Pryzby <pryzby@telsasoft.com>
From: Justin Pryzby <pryzby@telsasoft.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>, Amit Langote <amitlangote09@gmail.com>, Tom Lane <tgl@sss.pgh.pa.us>, pgsql-hackers@postgresql.org
Date: 2020-04-02T06:52:09Z
Lists: pgsql-hackers
On Thu, Apr 02, 2020 at 03:14:21PM +0900, Michael Paquier wrote:
> Now, regarding patch 0002, note that you have a problem for this part:
> - tuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(indexOid));
> - if (!HeapTupleIsValid(tuple)) /* probably can't happen */
> - {
> - relation_close(OldHeap, AccessExclusiveLock);
> - pgstat_progress_end_command();
> - return;
> - }
> - indexForm = (Form_pg_index) GETSTRUCT(tuple);
> - if (!indexForm->indisclustered)
> + if (!get_index_isclustered(indexOid))
> {
> - ReleaseSysCache(tuple);
> relation_close(OldHeap, AccessExclusiveLock);
> pgstat_progress_end_command();
> return;
> }
> - ReleaseSysCache(tuple);
>
> On an invalid tuple for pg_index, the new code would issue an error,
> while the old code would just return. And it seems to me that this
> can lead to problems because the parent relation is processed and
> locked at the beginning of cluster_rel(), *after* we know the index
> OID to work on.
> The refactoring is fine for the other two areas
> though, so I think that there is still value to apply
> get_index_isclustered() within mark_index_clustered() and cluster(),
> and I would suggest to keep 0002 to that.
>
> Justin, what do you think?
Sounds right. Or else get_index_isclustered() could be redefined to take a
boolean "do_elog" flag, and if syscache fails and that's false, then return
false instead of ERROR.
--
Justin
Commits
-
Refactor cluster.c to use new routine get_index_isclustered()
- 8ef9451f58ee 13.0 landed
-
Preserve clustered index after rewrites with ALTER TABLE
- 3f77a670241d 9.5.22 landed
- 61a161fe4421 9.6.18 landed
- cef2b8d52c59 10.13 landed
- 41faafbd75a5 11.8 landed
- 3e62dd3a937b 12.3 landed
- a40caf5f862c 13.0 landed
-
Preserve replica identity index across ALTER TABLE rewrite
- 1cc9c2412cc9 13.0 cited
-
Remove RangeIOData->typiofunc
- a77315fdf2a1 13.0 cited
-
Preserve pg_index.indisclustered across REINDEX CONCURRENTLY
- f087d63a45b5 12.3 landed
- d79fb88ac738 13.0 landed