mirror of
https://github.com/postgres/postgres.git
synced 2025-05-01 01:04:50 +03:00
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.
This commit is contained in:
parent
9dd963ae25
commit
ac897c4834
@ -15071,9 +15071,6 @@ ATExecSetCompression(AlteredTableInfo *tab,
|
|||||||
char *compression;
|
char *compression;
|
||||||
char typstorage;
|
char typstorage;
|
||||||
Oid cmoid;
|
Oid cmoid;
|
||||||
Datum values[Natts_pg_attribute];
|
|
||||||
bool nulls[Natts_pg_attribute];
|
|
||||||
bool replace[Natts_pg_attribute];
|
|
||||||
ObjectAddress address;
|
ObjectAddress address;
|
||||||
|
|
||||||
Assert(IsA(newValue, String));
|
Assert(IsA(newValue, String));
|
||||||
@ -15081,7 +15078,8 @@ ATExecSetCompression(AlteredTableInfo *tab,
|
|||||||
|
|
||||||
attrel = table_open(AttributeRelationId, RowExclusiveLock);
|
attrel = table_open(AttributeRelationId, RowExclusiveLock);
|
||||||
|
|
||||||
tuple = SearchSysCacheAttName(RelationGetRelid(rel), column);
|
/* copy the cache entry so we can scribble on it below */
|
||||||
|
tuple = SearchSysCacheCopyAttName(RelationGetRelid(rel), column);
|
||||||
if (!HeapTupleIsValid(tuple))
|
if (!HeapTupleIsValid(tuple))
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
||||||
@ -15105,32 +15103,32 @@ ATExecSetCompression(AlteredTableInfo *tab,
|
|||||||
errmsg("column data type %s does not support compression",
|
errmsg("column data type %s does not support compression",
|
||||||
format_type_be(atttableform->atttypid))));
|
format_type_be(atttableform->atttypid))));
|
||||||
|
|
||||||
/* initialize buffers for new tuple values */
|
|
||||||
memset(values, 0, sizeof(values));
|
|
||||||
memset(nulls, false, sizeof(nulls));
|
|
||||||
memset(replace, false, sizeof(replace));
|
|
||||||
|
|
||||||
/* get the attribute compression method. */
|
/* get the attribute compression method. */
|
||||||
cmoid = GetAttributeCompression(atttableform, compression);
|
cmoid = GetAttributeCompression(atttableform, compression);
|
||||||
|
|
||||||
|
/* update pg_attribute entry */
|
||||||
atttableform->attcompression = cmoid;
|
atttableform->attcompression = cmoid;
|
||||||
CatalogTupleUpdate(attrel, &tuple->t_self, tuple);
|
CatalogTupleUpdate(attrel, &tuple->t_self, tuple);
|
||||||
|
|
||||||
InvokeObjectPostAlterHook(RelationRelationId,
|
InvokeObjectPostAlterHook(RelationRelationId,
|
||||||
RelationGetRelid(rel),
|
RelationGetRelid(rel),
|
||||||
atttableform->attnum);
|
attnum);
|
||||||
|
|
||||||
ReleaseSysCache(tuple);
|
/*
|
||||||
|
* Apply the change to indexes as well (only for simple index columns,
|
||||||
/* apply changes to the index column as well */
|
* matching behavior of index.c ConstructTupleDescriptor()).
|
||||||
|
*/
|
||||||
SetIndexStorageProperties(rel, attrel, attnum, cmoid, '\0', lockmode);
|
SetIndexStorageProperties(rel, attrel, attnum, cmoid, '\0', lockmode);
|
||||||
|
|
||||||
|
heap_freetuple(tuple);
|
||||||
|
|
||||||
table_close(attrel, RowExclusiveLock);
|
table_close(attrel, RowExclusiveLock);
|
||||||
|
|
||||||
/* make changes visible */
|
/* make changes visible */
|
||||||
CommandCounterIncrement();
|
CommandCounterIncrement();
|
||||||
|
|
||||||
ObjectAddressSubSet(address, RelationRelationId,
|
ObjectAddressSubSet(address, RelationRelationId,
|
||||||
RelationGetRelid(rel), atttableform->attnum);
|
RelationGetRelid(rel), attnum);
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user