Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ebd8fc7

Browse files
committed
Simplify signature of RewriteTable
This function doesn't need the lockmode to be passed: it was being used to lock the new heap, but that's bogus, because the only caller has already obtained the appropriate lock on the new heap (which is unimportant anyway, because the relation's creation is not yet committed and so no other session can see it). Noticed while reviewed Antonin Houska's patch to add VACUUM FULL CONCURRENTLY.
1 parent 6313a76 commit ebd8fc7

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/backend/commands/tablecmds.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ static AlterTableCmd *ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab,
433433
static void ATRewriteTables(AlterTableStmt *parsetree,
434434
List **wqueue, LOCKMODE lockmode,
435435
AlterTableUtilityContext *context);
436-
static void ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode);
436+
static void ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap);
437437
static AlteredTableInfo *ATGetQueueEntry(List **wqueue, Relation rel);
438438
static void ATSimplePermissions(AlterTableType cmdtype, Relation rel, int allowed_targets);
439439
static void ATSimpleRecursion(List **wqueue, Relation rel,
@@ -5901,7 +5901,7 @@ ATRewriteTables(AlterTableStmt *parsetree, List **wqueue, LOCKMODE lockmode,
59015901
* modifications, and test the current data within the table
59025902
* against new constraints generated by ALTER TABLE commands.
59035903
*/
5904-
ATRewriteTable(tab, OIDNewHeap, lockmode);
5904+
ATRewriteTable(tab, OIDNewHeap);
59055905

59065906
/*
59075907
* Swap the physical files of the old and new heaps, then rebuild
@@ -5934,7 +5934,7 @@ ATRewriteTables(AlterTableStmt *parsetree, List **wqueue, LOCKMODE lockmode,
59345934
*/
59355935
if (tab->constraints != NIL || tab->verify_new_notnull ||
59365936
tab->partition_constraint != NULL)
5937-
ATRewriteTable(tab, InvalidOid, lockmode);
5937+
ATRewriteTable(tab, InvalidOid);
59385938

59395939
/*
59405940
* If we had SET TABLESPACE but no reason to reconstruct tuples,
@@ -6033,10 +6033,11 @@ ATRewriteTables(AlterTableStmt *parsetree, List **wqueue, LOCKMODE lockmode,
60336033
/*
60346034
* ATRewriteTable: scan or rewrite one table
60356035
*
6036-
* OIDNewHeap is InvalidOid if we don't need to rewrite
6036+
* A rewrite is requested by passing a valid OIDNewHeap; in that case, caller
6037+
* must already hold AccessExclusiveLock on it.
60376038
*/
60386039
static void
6039-
ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
6040+
ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
60406041
{
60416042
Relation oldrel;
60426043
Relation newrel;
@@ -6061,7 +6062,11 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
60616062
newTupDesc = RelationGetDescr(oldrel); /* includes all mods */
60626063

60636064
if (OidIsValid(OIDNewHeap))
6064-
newrel = table_open(OIDNewHeap, lockmode);
6065+
{
6066+
Assert(CheckRelationOidLockedByMe(OIDNewHeap, AccessExclusiveLock,
6067+
false));
6068+
newrel = table_open(OIDNewHeap, NoLock);
6069+
}
60656070
else
60666071
newrel = NULL;
60676072

0 commit comments

Comments
 (0)