Skip to content

Commit ac897c4

Browse files
committed
Fix assorted silliness in ATExecSetCompression().
It's not okay to scribble directly on a syscache entry. Nor to continue accessing said entry after releasing it. Also get rid of not-used local variables. Per valgrind testing.
1 parent 9dd963a commit ac897c4

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/backend/commands/tablecmds.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15071,17 +15071,15 @@ ATExecSetCompression(AlteredTableInfo *tab,
1507115071
char *compression;
1507215072
char typstorage;
1507315073
Oid cmoid;
15074-
Datum values[Natts_pg_attribute];
15075-
bool nulls[Natts_pg_attribute];
15076-
bool replace[Natts_pg_attribute];
1507715074
ObjectAddress address;
1507815075

1507915076
Assert(IsA(newValue, String));
1508015077
compression = strVal(newValue);
1508115078

1508215079
attrel = table_open(AttributeRelationId, RowExclusiveLock);
1508315080

15084-
tuple = SearchSysCacheAttName(RelationGetRelid(rel), column);
15081+
/* copy the cache entry so we can scribble on it below */
15082+
tuple = SearchSysCacheCopyAttName(RelationGetRelid(rel), column);
1508515083
if (!HeapTupleIsValid(tuple))
1508615084
ereport(ERROR,
1508715085
(errcode(ERRCODE_UNDEFINED_COLUMN),
@@ -15105,32 +15103,32 @@ ATExecSetCompression(AlteredTableInfo *tab,
1510515103
errmsg("column data type %s does not support compression",
1510615104
format_type_be(atttableform->atttypid))));
1510715105

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-
1511315106
/* get the attribute compression method. */
1511415107
cmoid = GetAttributeCompression(atttableform, compression);
1511515108

15109+
/* update pg_attribute entry */
1511615110
atttableform->attcompression = cmoid;
1511715111
CatalogTupleUpdate(attrel, &tuple->t_self, tuple);
1511815112

1511915113
InvokeObjectPostAlterHook(RelationRelationId,
1512015114
RelationGetRelid(rel),
15121-
atttableform->attnum);
15122-
15123-
ReleaseSysCache(tuple);
15115+
attnum);
1512415116

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+
*/
1512615121
SetIndexStorageProperties(rel, attrel, attnum, cmoid, '\0', lockmode);
15122+
15123+
heap_freetuple(tuple);
15124+
1512715125
table_close(attrel, RowExclusiveLock);
1512815126

1512915127
/* make changes visible */
1513015128
CommandCounterIncrement();
1513115129

1513215130
ObjectAddressSubSet(address, RelationRelationId,
15133-
RelationGetRelid(rel), atttableform->attnum);
15131+
RelationGetRelid(rel), attnum);
1513415132
return address;
1513515133
}
1513615134

0 commit comments

Comments
 (0)