diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2020-02-27 13:23:33 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2020-02-27 13:23:33 -0300 |
commit | b9b408c487244ef8e6d613d183c56eb2c62990b1 (patch) | |
tree | 670ad0ca3429b507878944127a9d76c940c21207 /src/backend/commands/tablecmds.c | |
parent | c4b0edb07ed53063ea4c86cd7918ad6ea01d8979 (diff) | |
download | postgresql-b9b408c487244ef8e6d613d183c56eb2c62990b1.tar.gz postgresql-b9b408c487244ef8e6d613d183c56eb2c62990b1.zip |
Record parents of triggers
This let us get rid of a recently introduced ugly hack (commit
1fa846f1c9af).
Author: Álvaro Herrera
Reviewed-by: Amit Langote, Tom Lane
Discussion: https://postgr.es/m/20200217215641.GA29784@alvherre.pgsql
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 59 |
1 files changed, 5 insertions, 54 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index b7c8d663fc4..02a7c04fdb7 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16448,54 +16448,6 @@ out: } /* - * isPartitionTrigger - * Subroutine for CloneRowTriggersToPartition: determine whether - * the given trigger has been cloned from another one. - * - * We use pg_depend as a proxy for this, since we don't have any direct - * evidence. This is an ugly hack to cope with a catalog deficiency. - * Keep away from children. Do not stare with naked eyes. Do not propagate. - */ -static bool -isPartitionTrigger(Oid trigger_oid) -{ - Relation pg_depend; - ScanKeyData key[2]; - SysScanDesc scan; - HeapTuple tup; - bool found = false; - - pg_depend = table_open(DependRelationId, AccessShareLock); - - ScanKeyInit(&key[0], Anum_pg_depend_classid, - BTEqualStrategyNumber, - F_OIDEQ, - ObjectIdGetDatum(TriggerRelationId)); - ScanKeyInit(&key[1], Anum_pg_depend_objid, - BTEqualStrategyNumber, - F_OIDEQ, - ObjectIdGetDatum(trigger_oid)); - - scan = systable_beginscan(pg_depend, DependDependerIndexId, - true, NULL, 2, key); - while ((tup = systable_getnext(scan)) != NULL) - { - Form_pg_depend dep = (Form_pg_depend) GETSTRUCT(tup); - - if (dep->refclassid == TriggerRelationId) - { - found = true; - break; - } - } - - systable_endscan(scan); - table_close(pg_depend, AccessShareLock); - - return found; -} - -/* * CloneRowTriggersToPartition * subroutine for ATExecAttachPartition/DefineRelation to create row * triggers on partitions @@ -16537,11 +16489,10 @@ CloneRowTriggersToPartition(Relation parent, Relation partition) /* * Internal triggers require careful examination. Ideally, we don't - * clone them. - * - * However, if our parent is a partitioned relation, there might be - * internal triggers that need cloning. In that case, we must skip - * clone it if the trigger on parent depends on another trigger. + * clone them. However, if our parent is itself a partition, there + * might be internal triggers that must not be skipped; for example, + * triggers on our parent that are in turn clones from its parent (our + * grandparent) are marked internal, yet they are to be cloned. * * Note we dare not verify that the other trigger belongs to an * ancestor relation of our parent, because that creates deadlock @@ -16549,7 +16500,7 @@ CloneRowTriggersToPartition(Relation parent, Relation partition) */ if (trigForm->tgisinternal && (!parent->rd_rel->relispartition || - !isPartitionTrigger(trigForm->oid))) + !OidIsValid(trigForm->tgparentid))) continue; /* |