@ -580,7 +580,8 @@ static void ATExecSetRelOptions(Relation rel, List *defList,
AlterTableType operation ,
AlterTableType operation ,
LOCKMODE lockmode ) ;
LOCKMODE lockmode ) ;
static void ATExecEnableDisableTrigger ( Relation rel , const char * trigname ,
static void ATExecEnableDisableTrigger ( Relation rel , const char * trigname ,
char fires_when , bool skip_system , LOCKMODE lockmode ) ;
char fires_when , bool skip_system , bool recurse ,
LOCKMODE lockmode ) ;
static void ATExecEnableDisableRule ( Relation rel , const char * rulename ,
static void ATExecEnableDisableRule ( Relation rel , const char * rulename ,
char fires_when , LOCKMODE lockmode ) ;
char fires_when , LOCKMODE lockmode ) ;
static void ATPrepAddInherit ( Relation child_rel ) ;
static void ATPrepAddInherit ( Relation child_rel ) ;
@ -4057,9 +4058,7 @@ AlterTableLookupRelation(AlterTableStmt *stmt, LOCKMODE lockmode)
* be done in this phase . Generally , this phase acquires table locks ,
* be done in this phase . Generally , this phase acquires table locks ,
* checks permissions and relkind , and recurses to find child tables .
* checks permissions and relkind , and recurses to find child tables .
*
*
* ATRewriteCatalogs performs phase 2 for each affected table . ( Note that
* ATRewriteCatalogs performs phase 2 for each affected table .
* phases 2 and 3 normally do no explicit recursion , since phase 1 already
* did it - - - although some subcommands have to recurse in phase 2 instead . )
* Certain subcommands need to be performed before others to avoid
* Certain subcommands need to be performed before others to avoid
* unnecessary conflicts ; for example , DROP COLUMN should come before
* unnecessary conflicts ; for example , DROP COLUMN should come before
* ADD COLUMN . Therefore phase 1 divides the subcommands into multiple
* ADD COLUMN . Therefore phase 1 divides the subcommands into multiple
@ -4067,6 +4066,12 @@ AlterTableLookupRelation(AlterTableStmt *stmt, LOCKMODE lockmode)
*
*
* ATRewriteTables performs phase 3 for those tables that need it .
* ATRewriteTables performs phase 3 for those tables that need it .
*
*
* For most subcommand types , phases 2 and 3 do no explicit recursion ,
* since phase 1 already does it . However , for certain subcommand types
* it is only possible to determine how to recurse at phase 2 time ; for
* those cases , phase 1 sets the cmd - > recurse flag ( or , in some older coding ,
* changes the command subtype of a " Recurse " variant XXX to be cleaned up . )
*
* Thanks to the magic of MVCC , an error anywhere along the way rolls back
* Thanks to the magic of MVCC , an error anywhere along the way rolls back
* the whole operation ; we don ' t have to do anything special to clean up .
* the whole operation ; we don ' t have to do anything special to clean up .
*
*
@ -4487,10 +4492,10 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
errhint ( " Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation. " ) ) ;
errhint ( " Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation. " ) ) ;
/*
/*
* Copy the original subcommand for each table . This avoids conflicts
* Copy the original subcommand for each table , so we can scribble on it .
* when different child tables need to make different pars e
* This avoids conflicts when different child tables need to make
* transformations ( for example , the same column may have different column
* different parse transformations ( for example , the same column may have
* numbers in different children ) .
* different column numbers in different children ) .
*/
*/
cmd = copyObject ( cmd ) ;
cmd = copyObject ( cmd ) ;
@ -4777,8 +4782,9 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
case AT_DisableTrigAll :
case AT_DisableTrigAll :
case AT_DisableTrigUser :
case AT_DisableTrigUser :
ATSimplePermissions ( cmd - > subtype , rel , ATT_TABLE | ATT_FOREIGN_TABLE ) ;
ATSimplePermissions ( cmd - > subtype , rel , ATT_TABLE | ATT_FOREIGN_TABLE ) ;
if ( rel - > rd_rel - > relkind = = RELKIND_PARTITIONED_TABLE )
/* Set up recursion for phase 2; no other prep needed */
ATSimpleRecursion ( wqueue , rel , cmd , recurse , lockmode , context ) ;
if ( recurse )
cmd - > recurse = true ;
pass = AT_PASS_MISC ;
pass = AT_PASS_MISC ;
break ;
break ;
case AT_EnableRule : /* ENABLE/DISABLE RULE variants */
case AT_EnableRule : /* ENABLE/DISABLE RULE variants */
@ -5119,35 +5125,51 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab,
break ;
break ;
case AT_EnableTrig : /* ENABLE TRIGGER name */
case AT_EnableTrig : /* ENABLE TRIGGER name */
ATExecEnableDisableTrigger ( rel , cmd - > name ,
ATExecEnableDisableTrigger ( rel , cmd - > name ,
TRIGGER_FIRES_ON_ORIGIN , false , lockmode ) ;
TRIGGER_FIRES_ON_ORIGIN , false ,
cmd - > recurse ,
lockmode ) ;
break ;
break ;
case AT_EnableAlwaysTrig : /* ENABLE ALWAYS TRIGGER name */
case AT_EnableAlwaysTrig : /* ENABLE ALWAYS TRIGGER name */
ATExecEnableDisableTrigger ( rel , cmd - > name ,
ATExecEnableDisableTrigger ( rel , cmd - > name ,
TRIGGER_FIRES_ALWAYS , false , lockmode ) ;
TRIGGER_FIRES_ALWAYS , false ,
cmd - > recurse ,
lockmode ) ;
break ;
break ;
case AT_EnableReplicaTrig : /* ENABLE REPLICA TRIGGER name */
case AT_EnableReplicaTrig : /* ENABLE REPLICA TRIGGER name */
ATExecEnableDisableTrigger ( rel , cmd - > name ,
ATExecEnableDisableTrigger ( rel , cmd - > name ,
TRIGGER_FIRES_ON_REPLICA , false , lockmode ) ;
TRIGGER_FIRES_ON_REPLICA , false ,
cmd - > recurse ,
lockmode ) ;
break ;
break ;
case AT_DisableTrig : /* DISABLE TRIGGER name */
case AT_DisableTrig : /* DISABLE TRIGGER name */
ATExecEnableDisableTrigger ( rel , cmd - > name ,
ATExecEnableDisableTrigger ( rel , cmd - > name ,
TRIGGER_DISABLED , false , lockmode ) ;
TRIGGER_DISABLED , false ,
cmd - > recurse ,
lockmode ) ;
break ;
break ;
case AT_EnableTrigAll : /* ENABLE TRIGGER ALL */
case AT_EnableTrigAll : /* ENABLE TRIGGER ALL */
ATExecEnableDisableTrigger ( rel , NULL ,
ATExecEnableDisableTrigger ( rel , NULL ,
TRIGGER_FIRES_ON_ORIGIN , false , lockmode ) ;
TRIGGER_FIRES_ON_ORIGIN , false ,
cmd - > recurse ,
lockmode ) ;
break ;
break ;
case AT_DisableTrigAll : /* DISABLE TRIGGER ALL */
case AT_DisableTrigAll : /* DISABLE TRIGGER ALL */
ATExecEnableDisableTrigger ( rel , NULL ,
ATExecEnableDisableTrigger ( rel , NULL ,
TRIGGER_DISABLED , false , lockmode ) ;
TRIGGER_DISABLED , false ,
cmd - > recurse ,
lockmode ) ;
break ;
break ;
case AT_EnableTrigUser : /* ENABLE TRIGGER USER */
case AT_EnableTrigUser : /* ENABLE TRIGGER USER */
ATExecEnableDisableTrigger ( rel , NULL ,
ATExecEnableDisableTrigger ( rel , NULL ,
TRIGGER_FIRES_ON_ORIGIN , true , lockmode ) ;
TRIGGER_FIRES_ON_ORIGIN , true ,
cmd - > recurse ,
lockmode ) ;
break ;
break ;
case AT_DisableTrigUser : /* DISABLE TRIGGER USER */
case AT_DisableTrigUser : /* DISABLE TRIGGER USER */
ATExecEnableDisableTrigger ( rel , NULL ,
ATExecEnableDisableTrigger ( rel , NULL ,
TRIGGER_DISABLED , true , lockmode ) ;
TRIGGER_DISABLED , true ,
cmd - > recurse ,
lockmode ) ;
break ;
break ;
case AT_EnableRule : /* ENABLE RULE name */
case AT_EnableRule : /* ENABLE RULE name */
@ -14660,9 +14682,11 @@ index_copy_data(Relation rel, RelFileLocator newrlocator)
*/
*/
static void
static void
ATExecEnableDisableTrigger ( Relation rel , const char * trigname ,
ATExecEnableDisableTrigger ( Relation rel , const char * trigname ,
char fires_when , bool skip_system , LOCKMODE lockmode )
char fires_when , bool skip_system , bool recurse ,
LOCKMODE lockmode )
{
{
EnableDisableTrigger ( rel , trigname , fires_when , skip_system , lockmode ) ;
EnableDisableTrigger ( rel , trigname , fires_when , skip_system , recurse ,
lockmode ) ;
}
}
/*
/*