aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorÁlvaro Herrera <alvherre@alvh.no-ip.org>2025-01-09 14:17:12 +0100
committerÁlvaro Herrera <alvherre@alvh.no-ip.org>2025-01-09 14:17:12 +0100
commitebd8fc7e47fdad6adb68aad341d95c541d7325c3 (patch)
tree11d69ed7b478eb15fff0a883924f9771c16f1db9 /src
parent6313a76b355e3640aba4cc80456a65c2bbc55a80 (diff)
downloadpostgresql-ebd8fc7e47fdad6adb68aad341d95c541d7325c3.tar.gz
postgresql-ebd8fc7e47fdad6adb68aad341d95c541d7325c3.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/tablecmds.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 4181c110eb7..54575fcd287 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -433,7 +433,7 @@ static AlterTableCmd *ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab,
static void ATRewriteTables(AlterTableStmt *parsetree,
List **wqueue, LOCKMODE lockmode,
AlterTableUtilityContext *context);
-static void ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode);
+static void ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap);
static AlteredTableInfo *ATGetQueueEntry(List **wqueue, Relation rel);
static void ATSimplePermissions(AlterTableType cmdtype, Relation rel, int allowed_targets);
static void ATSimpleRecursion(List **wqueue, Relation rel,
@@ -5901,7 +5901,7 @@ ATRewriteTables(AlterTableStmt *parsetree, List **wqueue, LOCKMODE lockmode,
* modifications, and test the current data within the table
* against new constraints generated by ALTER TABLE commands.
*/
- ATRewriteTable(tab, OIDNewHeap, lockmode);
+ ATRewriteTable(tab, OIDNewHeap);
/*
* Swap the physical files of the old and new heaps, then rebuild
@@ -5934,7 +5934,7 @@ ATRewriteTables(AlterTableStmt *parsetree, List **wqueue, LOCKMODE lockmode,
*/
if (tab->constraints != NIL || tab->verify_new_notnull ||
tab->partition_constraint != NULL)
- ATRewriteTable(tab, InvalidOid, lockmode);
+ ATRewriteTable(tab, InvalidOid);
/*
* If we had SET TABLESPACE but no reason to reconstruct tuples,
@@ -6033,10 +6033,11 @@ ATRewriteTables(AlterTableStmt *parsetree, List **wqueue, LOCKMODE lockmode,
/*
* ATRewriteTable: scan or rewrite one table
*
- * OIDNewHeap is InvalidOid if we don't need to rewrite
+ * A rewrite is requested by passing a valid OIDNewHeap; in that case, caller
+ * must already hold AccessExclusiveLock on it.
*/
static void
-ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
+ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
{
Relation oldrel;
Relation newrel;
@@ -6061,7 +6062,11 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
newTupDesc = RelationGetDescr(oldrel); /* includes all mods */
if (OidIsValid(OIDNewHeap))
- newrel = table_open(OIDNewHeap, lockmode);
+ {
+ Assert(CheckRelationOidLockedByMe(OIDNewHeap, AccessExclusiveLock,
+ false));
+ newrel = table_open(OIDNewHeap, NoLock);
+ }
else
newrel = NULL;