@@ -7383,6 +7383,7 @@ ATExecSetStorage(Relation rel, const char *colName, Node *newValue, LOCKMODE loc
73837383 Form_pg_attribute attrtuple;
73847384 AttrNumber attnum;
73857385 ObjectAddress address;
7386+ ListCell *lc;
73867387
73877388 Assert(IsA(newValue, String));
73887389 storagemode = strVal(newValue);
@@ -7442,6 +7443,52 @@ ATExecSetStorage(Relation rel, const char *colName, Node *newValue, LOCKMODE loc
74427443
74437444 heap_freetuple(tuple);
74447445
7446+ /*
7447+ * Apply the change to indexes as well (only for simple index columns,
7448+ * matching behavior of index.c ConstructTupleDescriptor()).
7449+ */
7450+ foreach(lc, RelationGetIndexList(rel))
7451+ {
7452+ Oid indexoid = lfirst_oid(lc);
7453+ Relation indrel;
7454+ AttrNumber indattnum = 0;
7455+
7456+ indrel = index_open(indexoid, lockmode);
7457+
7458+ for (int i = 0; i < indrel->rd_index->indnatts; i++)
7459+ {
7460+ if (indrel->rd_index->indkey.values[i] == attnum)
7461+ {
7462+ indattnum = i + 1;
7463+ break;
7464+ }
7465+ }
7466+
7467+ if (indattnum == 0)
7468+ {
7469+ index_close(indrel, lockmode);
7470+ continue;
7471+ }
7472+
7473+ tuple = SearchSysCacheCopyAttNum(RelationGetRelid(indrel), indattnum);
7474+
7475+ if (HeapTupleIsValid(tuple))
7476+ {
7477+ attrtuple = (Form_pg_attribute) GETSTRUCT(tuple);
7478+ attrtuple->attstorage = newstorage;
7479+
7480+ CatalogTupleUpdate(attrelation, &tuple->t_self, tuple);
7481+
7482+ InvokeObjectPostAlterHook(RelationRelationId,
7483+ RelationGetRelid(rel),
7484+ attrtuple->attnum);
7485+
7486+ heap_freetuple(tuple);
7487+ }
7488+
7489+ index_close(indrel, lockmode);
7490+ }
7491+
74457492 table_close(attrelation, RowExclusiveLock);
74467493
74477494 ObjectAddressSubSet(address, RelationRelationId,
0 commit comments