@@ -590,7 +590,8 @@ static ObjectAddress ATExecClusterOn(Relation rel, const char *indexName,
590
590
static void ATExecDropCluster(Relation rel, LOCKMODE lockmode);
591
591
static void ATPrepSetAccessMethod(AlteredTableInfo *tab, Relation rel, const char *amname);
592
592
static void ATExecSetAccessMethodNoStorage(Relation rel, Oid newAccessMethodId);
593
- static bool ATPrepChangePersistence(Relation rel, bool toLogged);
593
+ static void ATPrepChangePersistence(AlteredTableInfo *tab, Relation rel,
594
+ bool toLogged);
594
595
static void ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel,
595
596
const char *tablespacename, LOCKMODE lockmode);
596
597
static void ATExecSetTableSpace(Oid tableOid, Oid newTableSpace, LOCKMODE lockmode);
@@ -4953,33 +4954,13 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
4953
4954
pass = AT_PASS_MISC;
4954
4955
break;
4955
4956
case AT_SetLogged: /* SET LOGGED */
4956
- ATSimplePermissions(cmd->subtype, rel, ATT_TABLE | ATT_SEQUENCE);
4957
- if (tab->chgPersistence)
4958
- ereport(ERROR,
4959
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4960
- errmsg("cannot change persistence setting twice")));
4961
- tab->chgPersistence = ATPrepChangePersistence(rel, true);
4962
- /* force rewrite if necessary; see comment in ATRewriteTables */
4963
- if (tab->chgPersistence)
4964
- {
4965
- tab->rewrite |= AT_REWRITE_ALTER_PERSISTENCE;
4966
- tab->newrelpersistence = RELPERSISTENCE_PERMANENT;
4967
- }
4968
- pass = AT_PASS_MISC;
4969
- break;
4970
4957
case AT_SetUnLogged: /* SET UNLOGGED */
4971
4958
ATSimplePermissions(cmd->subtype, rel, ATT_TABLE | ATT_SEQUENCE);
4972
4959
if (tab->chgPersistence)
4973
4960
ereport(ERROR,
4974
4961
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4975
4962
errmsg("cannot change persistence setting twice")));
4976
- tab->chgPersistence = ATPrepChangePersistence(rel, false);
4977
- /* force rewrite if necessary; see comment in ATRewriteTables */
4978
- if (tab->chgPersistence)
4979
- {
4980
- tab->rewrite |= AT_REWRITE_ALTER_PERSISTENCE;
4981
- tab->newrelpersistence = RELPERSISTENCE_UNLOGGED;
4982
- }
4963
+ ATPrepChangePersistence(tab, rel, cmd->subtype == AT_SetLogged);
4983
4964
pass = AT_PASS_MISC;
4984
4965
break;
4985
4966
case AT_DropOids: /* SET WITHOUT OIDS */
@@ -16894,12 +16875,9 @@ ATExecSetCompression(Relation rel,
16894
16875
* This verifies that we're not trying to change a temp table. Also,
16895
16876
* existing foreign key constraints are checked to avoid ending up with
16896
16877
* permanent tables referencing unlogged tables.
16897
- *
16898
- * Return value is false if the operation is a no-op (in which case the
16899
- * checks are skipped), otherwise true.
16900
16878
*/
16901
- static bool
16902
- ATPrepChangePersistence(Relation rel, bool toLogged)
16879
+ static void
16880
+ ATPrepChangePersistence(AlteredTableInfo *tab, Relation rel, bool toLogged)
16903
16881
{
16904
16882
Relation pg_constraint;
16905
16883
HeapTuple tuple;
@@ -16923,12 +16901,12 @@ ATPrepChangePersistence(Relation rel, bool toLogged)
16923
16901
case RELPERSISTENCE_PERMANENT:
16924
16902
if (toLogged)
16925
16903
/* nothing to do */
16926
- return false ;
16904
+ return;
16927
16905
break;
16928
16906
case RELPERSISTENCE_UNLOGGED:
16929
16907
if (!toLogged)
16930
16908
/* nothing to do */
16931
- return false ;
16909
+ return;
16932
16910
break;
16933
16911
}
16934
16912
@@ -17011,7 +16989,13 @@ ATPrepChangePersistence(Relation rel, bool toLogged)
17011
16989
17012
16990
table_close(pg_constraint, AccessShareLock);
17013
16991
17014
- return true;
16992
+ /* force rewrite if necessary; see comment in ATRewriteTables */
16993
+ tab->rewrite |= AT_REWRITE_ALTER_PERSISTENCE;
16994
+ if (toLogged)
16995
+ tab->newrelpersistence = RELPERSISTENCE_PERMANENT;
16996
+ else
16997
+ tab->newrelpersistence = RELPERSISTENCE_UNLOGGED;
16998
+ tab->chgPersistence = true;
17015
16999
}
17016
17000
17017
17001
/*
0 commit comments