309
309
const char *colName, TypeName *typename);
310
310
static void ATPostAlterTypeCleanup(List **wqueue, AlteredTableInfo *tab);
311
311
static void ATPostAlterTypeParse(char *cmd, List **wqueue);
312
static void change_owner_fix_column_acls(Oid relationOid,
313
Oid oldOwnerId, Oid newOwnerId);
312
314
static void change_owner_recurse_to_sequences(Oid relationOid,
314
316
static void ATExecClusterOn(Relation rel, const char *indexName);
6374
6376
heap_freetuple(newtuple);
6379
* We must similarly update any per-column ACLs to reflect the new
6380
* owner; for neatness reasons that's split out as a subroutine.
6382
change_owner_fix_column_acls(relationOid,
6383
tuple_class->relowner,
6377
6387
* Update owner dependency reference, if any. A composite type has
6378
6388
* none, because it's tracked for the pg_type entry instead of here;
6379
6389
* indexes and TOAST tables don't have their own entries either.
6443
* change_owner_fix_column_acls
6445
* Helper function for ATExecChangeOwner. Scan the columns of the table
6446
* and fix any non-null column ACLs to reflect the new owner.
6449
change_owner_fix_column_acls(Oid relationOid, Oid oldOwnerId, Oid newOwnerId)
6451
Relation attRelation;
6454
HeapTuple attributeTuple;
6456
attRelation = heap_open(AttributeRelationId, RowExclusiveLock);
6457
ScanKeyInit(&key[0],
6458
Anum_pg_attribute_attrelid,
6459
BTEqualStrategyNumber, F_OIDEQ,
6460
ObjectIdGetDatum(relationOid));
6461
scan = systable_beginscan(attRelation, AttributeRelidNumIndexId,
6462
true, SnapshotNow, 1, key);
6463
while (HeapTupleIsValid(attributeTuple = systable_getnext(scan)))
6465
Form_pg_attribute att = (Form_pg_attribute) GETSTRUCT(attributeTuple);
6466
Datum repl_val[Natts_pg_attribute];
6467
bool repl_null[Natts_pg_attribute];
6468
bool repl_repl[Natts_pg_attribute];
6474
/* Ignore dropped columns */
6475
if (att->attisdropped)
6478
aclDatum = heap_getattr(attributeTuple,
6479
Anum_pg_attribute_attacl,
6480
RelationGetDescr(attRelation),
6482
/* Null ACLs do not require changes */
6486
memset(repl_null, false, sizeof(repl_null));
6487
memset(repl_repl, false, sizeof(repl_repl));
6489
newAcl = aclnewowner(DatumGetAclP(aclDatum),
6490
oldOwnerId, newOwnerId);
6491
repl_repl[Anum_pg_attribute_attacl - 1] = true;
6492
repl_val[Anum_pg_attribute_attacl - 1] = PointerGetDatum(newAcl);
6494
newtuple = heap_modify_tuple(attributeTuple,
6495
RelationGetDescr(attRelation),
6496
repl_val, repl_null, repl_repl);
6498
simple_heap_update(attRelation, &newtuple->t_self, newtuple);
6499
CatalogUpdateIndexes(attRelation, newtuple);
6501
heap_freetuple(newtuple);
6503
systable_endscan(scan);
6504
heap_close(attRelation, RowExclusiveLock);
6433
6508
* change_owner_recurse_to_sequences
6435
6510
* Helper function for ATExecChangeOwner. Examines pg_depend searching