Skip to content

Commit

Permalink
alvherre's tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
alvherre committed Jan 5, 2022
1 parent b1489aa commit 3451612
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
26 changes: 19 additions & 7 deletions src/backend/commands/tablecmds.c
Expand Up @@ -10091,7 +10091,7 @@ CloneFkReferenced(Relation parentRel, Relation partitionRel)
* parent OIDs for similar triggers that will be created on the
* partition in addFkRecurseReferenced().
*/
GetForeignKeyActionTriggers(trigrel, constrForm->oid,
GetForeignKeyActionTriggers(trigrel, constrOid,
constrForm->confrelid, constrForm->conrelid,
&deleteTriggerOid, &updateTriggerOid);

Expand Down Expand Up @@ -10559,9 +10559,15 @@ GetForeignKeyActionTriggers(Relation trigrel,
if (trgform->tgrelid != confrelid)
continue;
if (TRIGGER_FOR_DELETE(trgform->tgtype))
{
Assert(*deleteTriggerOid == InvalidOid);
*deleteTriggerOid = trgform->oid;
}
else if (TRIGGER_FOR_UPDATE(trgform->tgtype))
{
Assert(*updateTriggerOid == InvalidOid);
*updateTriggerOid = trgform->oid;
}
if (OidIsValid(*deleteTriggerOid) && OidIsValid(*updateTriggerOid))
break;
}
Expand Down Expand Up @@ -10608,9 +10614,15 @@ GetForeignKeyCheckTriggers(Relation trigrel,
if (trgform->tgrelid != conrelid)
continue;
if (TRIGGER_FOR_INSERT(trgform->tgtype))
{
Assert(*insertTriggerOid == InvalidOid);
*insertTriggerOid = trgform->oid;
}
else if (TRIGGER_FOR_UPDATE(trgform->tgtype))
{
Assert(*updateTriggerOid == InvalidOid);
*updateTriggerOid = trgform->oid;
}
if (OidIsValid(*insertTriggerOid) && OidIsValid(*updateTriggerOid))
break;
}
Expand Down Expand Up @@ -11670,10 +11682,10 @@ createForeignKeyActionTriggers(Relation rel, Oid refRelOid, Constraint *fkconstr
break;
}

trigAddress= CreateTrigger(fk_trigger, NULL, refRelOid,
RelationGetRelid(rel),
constraintOid, indexOid, InvalidOid,
parentDelTrigger, NULL, true, false);
trigAddress = CreateTrigger(fk_trigger, NULL, refRelOid,
RelationGetRelid(rel),
constraintOid, indexOid, InvalidOid,
parentDelTrigger, NULL, true, false);
if (deleteTrigOid)
*deleteTrigOid = trigAddress.objectId;

Expand Down Expand Up @@ -18722,8 +18734,8 @@ DropClonedTriggersFromPartition(Oid partitionId)

/*
* Ignore internal triggers that are implementation objects of foreign
* keys, because they will be when the foreign keys are themselves
* detached.
* keys, because these will be detached when the foreign keys
* themselves are.
*/
if (OidIsValid(pg_trigger->tgconstrrelid))
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/backend/commands/trigger.c
Expand Up @@ -776,8 +776,8 @@ CreateTriggerFiringOn(CreateTrigStmt *stmt, const char *queryString,
* in_partition, because then we're recursing from a partitioned table
* and the check was made at the parent level.
*/
if ((existing_isInternal || existing_isClone) && !isInternal &&
!in_partition)
if ((existing_isInternal || existing_isClone) &&
!isInternal && !in_partition)
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("trigger \"%s\" for relation \"%s\" is an internal or a child trigger",
Expand Down
6 changes: 3 additions & 3 deletions src/bin/pg_dump/pg_dump.c
Expand Up @@ -7262,7 +7262,7 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
"SELECT t.tgrelid, t.tgname, "
"t.tgfoid::pg_catalog.regproc AS tgfname, "
"pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
"t.tgenabled, t.tableoid, t.oid, t.tgisinternal\n"
"t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition\n"
"FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
"JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
"LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
Expand All @@ -7283,7 +7283,7 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
"SELECT t.tgrelid, t.tgname, "
"t.tgfoid::pg_catalog.regproc AS tgfname, "
"pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
"t.tgenabled, t.tableoid, t.oid, t.tgisinternal "
"t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition "
"FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
"JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
"LEFT JOIN pg_catalog.pg_depend AS d ON "
Expand All @@ -7302,7 +7302,7 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
"SELECT t.tgrelid, t.tgname, "
"t.tgfoid::pg_catalog.regproc AS tgfname, "
"pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
"t.tgenabled, false as tgisinternal, "
"t.tgenabled, false as tgispartition, "
"t.tableoid, t.oid "
"FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
"JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
Expand Down
13 changes: 7 additions & 6 deletions src/bin/psql/describe.c
Expand Up @@ -3001,14 +3001,15 @@ describeOneTableDetails(const char *schemaname,
" AND u.tgparentid = 0) AS parent" :
"NULL AS parent"),
oid);

/*
* tgisnternal is set to true for inherited triggers of partitions in
* the servers between v11 and v13, though still must be shown to the
* user. So we use another property that is true for such inherited
* triggers to avoid them being hidden, which is their dependendence
* on another trigger.
* tgisinternal is set true for inherited triggers of partitions in
* servers between v11 and v14, though these must still be shown to
* the user. So we use another property that is true for such
* inherited triggers to avoid them being hidden, which is their
* dependendence on another trigger.
*/
if (pset.sversion >= 110000 && pset.sversion < 140000)
if (pset.sversion >= 110000 && pset.sversion < 150000)
appendPQExpBufferStr(&buf, "(NOT t.tgisinternal OR (t.tgisinternal AND t.tgenabled = 'D') \n"
" OR EXISTS (SELECT 1 FROM pg_catalog.pg_depend WHERE objid = t.oid \n"
" AND refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass))");
Expand Down

0 comments on commit 3451612

Please sign in to comment.