@@ -15071,17 +15071,15 @@ ATExecSetCompression(AlteredTableInfo *tab,
15071
15071
char *compression;
15072
15072
char typstorage;
15073
15073
Oid cmoid;
15074
- Datum values[Natts_pg_attribute];
15075
- bool nulls[Natts_pg_attribute];
15076
- bool replace[Natts_pg_attribute];
15077
15074
ObjectAddress address;
15078
15075
15079
15076
Assert(IsA(newValue, String));
15080
15077
compression = strVal(newValue);
15081
15078
15082
15079
attrel = table_open(AttributeRelationId, RowExclusiveLock);
15083
15080
15084
- tuple = SearchSysCacheAttName(RelationGetRelid(rel), column);
15081
+ /* copy the cache entry so we can scribble on it below */
15082
+ tuple = SearchSysCacheCopyAttName(RelationGetRelid(rel), column);
15085
15083
if (!HeapTupleIsValid(tuple))
15086
15084
ereport(ERROR,
15087
15085
(errcode(ERRCODE_UNDEFINED_COLUMN),
@@ -15105,32 +15103,32 @@ ATExecSetCompression(AlteredTableInfo *tab,
15105
15103
errmsg("column data type %s does not support compression",
15106
15104
format_type_be(atttableform->atttypid))));
15107
15105
15108
- /* initialize buffers for new tuple values */
15109
- memset(values, 0, sizeof(values));
15110
- memset(nulls, false, sizeof(nulls));
15111
- memset(replace, false, sizeof(replace));
15112
-
15113
15106
/* get the attribute compression method. */
15114
15107
cmoid = GetAttributeCompression(atttableform, compression);
15115
15108
15109
+ /* update pg_attribute entry */
15116
15110
atttableform->attcompression = cmoid;
15117
15111
CatalogTupleUpdate(attrel, &tuple->t_self, tuple);
15118
15112
15119
15113
InvokeObjectPostAlterHook(RelationRelationId,
15120
15114
RelationGetRelid(rel),
15121
- atttableform->attnum);
15122
-
15123
- ReleaseSysCache(tuple);
15115
+ attnum);
15124
15116
15125
- /* apply changes to the index column as well */
15117
+ /*
15118
+ * Apply the change to indexes as well (only for simple index columns,
15119
+ * matching behavior of index.c ConstructTupleDescriptor()).
15120
+ */
15126
15121
SetIndexStorageProperties(rel, attrel, attnum, cmoid, '\0', lockmode);
15122
+
15123
+ heap_freetuple(tuple);
15124
+
15127
15125
table_close(attrel, RowExclusiveLock);
15128
15126
15129
15127
/* make changes visible */
15130
15128
CommandCounterIncrement();
15131
15129
15132
15130
ObjectAddressSubSet(address, RelationRelationId,
15133
- RelationGetRelid(rel), atttableform-> attnum);
15131
+ RelationGetRelid(rel), attnum);
15134
15132
return address;
15135
15133
}
15136
15134
0 commit comments