Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcd03c6e

Browse files
committed
Let ALTER TABLE Phase 2 routines manage the relation pointer
Struct AlteredRelationInfo gains a new Relation member, to be used onlyby Phase 2 (ATRewriteCatalogs); this allows ATExecCmd() subroutines openand close the relation internally.A future commit will use this facility to implement an ALTER TABLEsubcommand that closes and reopens the relation across transactionboundaries.(It is possible to keep the relation open past phase 2 to be used byphase 3 instead of having to reopen it that point, but there are someminor complications with that; it's not clear that there is much to bewon from doing that, though.)Author: Álvaro Herrera <alvherre@alvh.no-ip.org>Discussion:https://postgr.es/m/20200803234854.GA24158@alvherre.pgsql
1 parent4669cac commitcd03c6e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ typedef struct AlteredTableInfo
157157
Oidrelid;/* Relation to work on */
158158
charrelkind;/* Its relkind */
159159
TupleDescoldDesc;/* Pre-modification tuple descriptor */
160+
/* Transiently set during Phase 2, normally set to NULL */
161+
Relationrel;
160162
/* Information saved by Phase 1 for Phase 2: */
161163
List *subcmds[AT_NUM_PASSES]; /* Lists of AlterTableCmd */
162164
/* Information saved by Phases 1/2 for Phase 3: */
@@ -354,7 +356,7 @@ static void ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
354356
AlterTableUtilityContext *context);
355357
static void ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
356358
AlterTableUtilityContext *context);
357-
static void ATExecCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
359+
static void ATExecCmd(List **wqueue, AlteredTableInfo *tab,
358360
AlterTableCmd *cmd, LOCKMODE lockmode, int cur_pass,
359361
AlterTableUtilityContext *context);
360362
static AlterTableCmd *ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab,
@@ -4569,7 +4571,6 @@ ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
45694571
{
45704572
AlteredTableInfo *tab = (AlteredTableInfo *) lfirst(ltab);
45714573
List *subcmds = tab->subcmds[pass];
4572-
Relationrel;
45734574
ListCell *lcmd;
45744575

45754576
if (subcmds == NIL)
@@ -4578,10 +4579,10 @@ ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
45784579
/*
45794580
* Appropriate lock was obtained by phase 1, needn't get it again
45804581
*/
4581-
rel = relation_open(tab->relid, NoLock);
4582+
tab->rel = relation_open(tab->relid, NoLock);
45824583

45834584
foreach(lcmd, subcmds)
4584-
ATExecCmd(wqueue, tab, rel,
4585+
ATExecCmd(wqueue, tab,
45854586
castNode(AlterTableCmd, lfirst(lcmd)),
45864587
lockmode, pass, context);
45874588

@@ -4593,7 +4594,11 @@ ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
45934594
if (pass == AT_PASS_ALTER_TYPE)
45944595
ATPostAlterTypeCleanup(wqueue, tab, lockmode);
45954596

4596-
relation_close(rel, NoLock);
4597+
if (tab->rel)
4598+
{
4599+
relation_close(tab->rel, NoLock);
4600+
tab->rel = NULL;
4601+
}
45974602
}
45984603
}
45994604

@@ -4619,11 +4624,12 @@ ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
46194624
* ATExecCmd: dispatch a subcommand to appropriate execution routine
46204625
*/
46214626
static void
4622-
ATExecCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
4627+
ATExecCmd(List **wqueue, AlteredTableInfo *tab,
46234628
AlterTableCmd *cmd, LOCKMODE lockmode, int cur_pass,
46244629
AlterTableUtilityContext *context)
46254630
{
46264631
ObjectAddress address = InvalidObjectAddress;
4632+
Relationrel = tab->rel;
46274633

46284634
switch (cmd->subtype)
46294635
{
@@ -5730,6 +5736,7 @@ ATGetQueueEntry(List **wqueue, Relation rel)
57305736
*/
57315737
tab = (AlteredTableInfo *) palloc0(sizeof(AlteredTableInfo));
57325738
tab->relid = relid;
5739+
tab->rel = NULL;/* set later */
57335740
tab->relkind = rel->rd_rel->relkind;
57345741
tab->oldDesc = CreateTupleDescCopyConstr(RelationGetDescr(rel));
57355742
tab->newrelpersistence = RELPERSISTENCE_PERMANENT;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp