Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gsXoD-0006YF-4Y for pgsql-hackers@arkaria.postgresql.org; Sat, 09 Feb 2019 18:57:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gsXoB-0002rX-Bh for pgsql-hackers@arkaria.postgresql.org; Sat, 09 Feb 2019 18:56:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gsXoA-0002pb-Tl for pgsql-hackers@lists.postgresql.org; Sat, 09 Feb 2019 18:56:59 +0000 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gsXo2-0006Tb-PN for pgsql-hackers@postgresql.org; Sat, 09 Feb 2019 18:56:58 +0000 Received: by mail-qt1-x842.google.com with SMTP id b8so7751276qtr.9 for ; Sat, 09 Feb 2019 10:56:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=nAPhVL+ouBnKvv3BF23NPUS68n3Z0z9uCfL36CXQyVo=; b=w1n4fNlOb/vD0TVehkou1tLG2XueUTkK4O+Luzm9hapdcpNckxNV1iekDDM3+laQ68 fuRU9G+Ok7uF8H9TD+lhr044nEXUPhMZuaccIozp4qWjvpQifqmSvr76KkqCCsN6POC5 YLfd8laOHeNCw/yeGMgHD1xWAsbRsz+UtYDFlcq4Hja8u+u6ov/R0PgkrNWOjZFuOE+1 R1zywaqceHU2yi/zWV56VYMc4IG2xS0u0KZS5yDz/IeJdVwqY0l7ey2N40RIjg7iVKJe mRi83P7It56zrAyNUu6djz6eK60t8VJUOu2jHmK/eniRPgmzamzG4Z/EKDJnauoddiVa h+hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=nAPhVL+ouBnKvv3BF23NPUS68n3Z0z9uCfL36CXQyVo=; b=ua+zKeEC2YGybvhP2GaXK/oniEWNy8Km9cVZ7iZw0hCp8RVakJuX2DSOGB661wRPgr Rl/Rhs1jUB0zavYtTh5pa9eZ2HE9U91+THUcQNd2Wil35RC+i59Wo7F+6ViSqkCyF4t+ SbpXKpYnBgO/ZWgemhNshv9KeGsQ9XRdyj1Gg7n9xxeXtC94KWiHo/1Z+DzmiOs8/7YD uxVBqmcp5WOhrTaiPBAKrOHh2raHJYn/8MPmbxL9IDIe2yIylaAZWVRRHQNxLfuf1d3N tgV0iYhmRaPRDq6y4gSf8eA0798F3R3rdfce/1adoRiL1DXB9a74dqiEux0QYyG52xVJ AowA== X-Gm-Message-State: AHQUAubd4b0NDpidoEfcJU5L7OQ4flfCK5glCj+4bEMKIXITgARySuj5 05T1HWEc/IdwY6gum6OfDNILdw== X-Google-Smtp-Source: AHgI3IbkMjaS1bbXtJwxDxiKn8Iw9POyeTPgToQZB88oQQH/QNmlii/LjeKCykk1powBDOIh7/6aQQ== X-Received: by 2002:ac8:7384:: with SMTP id t4mr21096451qtp.203.1549738608699; Sat, 09 Feb 2019 10:56:48 -0800 (PST) Received: from nimloth.alvh.no-ip.org ([201.186.80.67]) by smtp.gmail.com with ESMTPSA id m14sm4541852qka.21.2019.02.09.10.56.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Feb 2019 10:56:48 -0800 (PST) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 5CC7612466A; Sat, 9 Feb 2019 15:56:46 -0300 (-03) Date: Sat, 9 Feb 2019 15:56:46 -0300 From: Alvaro Herrera To: Tom Lane Cc: Amit Langote , Peter Geoghegan , PostgreSQL Hackers Subject: Re: Fixing findDependentObjects()'s dependency on scan order (regressions in DROP diagnostic messages) Message-ID: <20190209185646.GA12234@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="J2SCkAp4GZ/dPZZf" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190209174123.GA6498@alvherre.pgsql> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --J2SCkAp4GZ/dPZZf Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2019-Feb-09, Alvaro Herrera wrote: > I'll put this in the comment. Attached. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --J2SCkAp4GZ/dPZZf Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-fix-trigger-drop.patch" diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 910e5deaa3f..0d32262c4c3 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8008,10 +8008,12 @@ CloneFkReferencing(Relation pg_constraint, Relation parentRel, ReleaseSysCache(partcontup); /* - * Looks good! Attach this constraint. Note that the action - * triggers are no longer needed, so remove them. We identify - * them because they have our constraint OID, as well as being - * on the referenced rel. + * Looks good! Attach this constraint. The action triggers are + * no longer needed -- the parent table already has equivalent + * ones, and those will be able to reach the partition, therefore + * the ones in the partition are redundant, so remove them. We + * identify them because they have our constraint OID, as well as + * being on the referenced rel. */ trigrel = heap_open(TriggerRelationId, RowExclusiveLock); ScanKeyInit(&key, @@ -8024,17 +8026,30 @@ CloneFkReferencing(Relation pg_constraint, Relation parentRel, while ((trigtup = systable_getnext(scan)) != NULL) { Form_pg_trigger trgform = (Form_pg_trigger) GETSTRUCT(trigtup); + ObjectAddress trigger; if (trgform->tgconstrrelid != fk->conrelid) continue; if (trgform->tgrelid != fk->confrelid) continue; - deleteDependencyRecordsForClass(TriggerRelationId, - HeapTupleGetOid(trigtup), - ConstraintRelationId, - DEPENDENCY_INTERNAL); - CatalogTupleDelete(trigrel, &trigtup->t_self); + /* + * The constraint is originally set up to contain this trigger + * as an implementation object, so there's a dependency record + * that links the two; however, since the trigger is no longer + * needed, we remove the dependency link in order to be able + * to drop the trigger while keeping the constraint intact. + */ + deleteDependencyRecordsFor(TriggerRelationId, + HeapTupleGetOid(trigtup), + false); + /* make dependency deletion visible to performDeletion */ + CommandCounterIncrement(); + ObjectAddressSet(trigger, TriggerRelationId, + HeapTupleGetOid(trigtup)); + performDeletion(&trigger, DROP_RESTRICT, 0); + /* make trigger drop visible, in case the loop iterates */ + CommandCounterIncrement(); } systable_endscan(scan); --J2SCkAp4GZ/dPZZf--