Re: ALTER tbl rewrite loses CLUSTER ON index
Amit Langote <amitlangote09@gmail.com>
From: Amit Langote <amitlangote09@gmail.com>
To: Justin Pryzby <pryzby@telsasoft.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2020-02-05T06:53:45Z
Lists: pgsql-hackers
Attachments
- preserve-CLUSTER-ON-during-ALTER-TABLE.patch (text/plain) patch
Hi Justin, On Mon, Feb 3, 2020 at 1:17 AM Justin Pryzby <pryzby@telsasoft.com> wrote: > Other options are preserved by ALTER (and CLUSTER ON is and most obviously > should be preserved by CLUSTER's rewrite), so I think (SET) CLUSTER should be > preserved by ALTER, too. Yes. create table foo (a int primary key); cluster foo; ERROR: there is no previously clustered index for table "foo" cluster foo using foo_pkey; alter table foo alter a type bigint; cluster foo; ERROR: there is no previously clustered index for table "foo" With your patch, this last error doesn't occur. Like you, I too suspect that losing indisclustered like this is unintentional, so should be fixed. > As far as I can see, this should be the responsibility of something in the > vicinity of ATPostAlterTypeParse/RememberIndexForRebuilding. > > Attach patch sketches a fix. While your sketch hits pretty close, it could be done a bit differently. For one, I don't like the way it's misusing changedIndexOids and changedIndexDefs. Instead, we can do something similar to what RebuildConstraintComments() does for constraint comments. For example, we can have a PreserveClusterOn() that adds a AT_ClusterOn command into table's AT_PASS_OLD_INDEX pass commands. Attached patch shows what I'm thinking. I also added representative tests. Thanks, Amit
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