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 1gkG4D-0003BI-B1 for pgsql-bugs@arkaria.postgresql.org; Thu, 17 Jan 2019 22:23:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gkG4C-0001Yw-1f for pgsql-bugs@arkaria.postgresql.org; Thu, 17 Jan 2019 22:23:16 +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 1gkG4B-0001QX-LI for pgsql-bugs@lists.postgresql.org; Thu, 17 Jan 2019 22:23:15 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gkG47-00032f-FP for pgsql-bugs@lists.postgresql.org; Thu, 17 Jan 2019 22:23:15 +0000 Received: by mail-qt1-x841.google.com with SMTP id l12so13164458qtf.8 for ; Thu, 17 Jan 2019 14:23:10 -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=yS+gyA+97kXnvfvCNPliQhIJX6pq3nBAg1ZVZqXiUUI=; b=Ab1DUTiLLqIeL1/jzRC4WNjkTG2E0RKYgmIrVxnTigGZrApTzbN5VgCiZlkG/qs7do 1oOq1ckbLzPc4Ig6pHRAl/gEkQyzIBgX1i+fTvoaFKM5OW9PtvnW60IN9+4z/DQN99Fl 03ZSwrJ1rjHl4vMQWrKz1935P18BAQkqHJinRG7rxfl5oiK6DmI4MybnVDSUbVlsEVph 80T9aeX9vX/7xcKIpHC3ivUr+L//D/q60HBv4f1TwUvczBuSldKPJK73YEMaAJm5W520 StNJOfix1ByY3lgxDw/D7nc2p/cN5WKQJxRe5pbZ1NCuSAzrSxNLXH4gfqDZZ4qwHG9w iuvA== 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=yS+gyA+97kXnvfvCNPliQhIJX6pq3nBAg1ZVZqXiUUI=; b=g6lr5ppNs6a2KqruBMEm5TedgcAYEZsF36+Ac+r97Tw8ugjBT9uGnBwE7ziEVfOEp4 4nfItgnzPhLdEQ5onlZniPSftlTyNgAa8qYOkb2XSIq7AKlYdjVESav/SrIdw4IiCz9N +LkCr2URbfbm8ME3Iv49AZVt+Qy1am7m2HtrkIizBsnvTMbVLR43WUnOfHes26aAvEWb L4WwCSV0K4L5mmzB3i58OY4kL9DaKcIUrj0idxMiKITlHFS7WroTnUQ0Q+GkqmDMea5K DbQ/i56cErQ6+Pxi/t8qmGnKpd9boMQbQS4W5N8FiF9RG/c/lKL/uYkuyCcAFqVWeFV7 z5gQ== X-Gm-Message-State: AJcUukc7FSkD5UIHSn1+siyeIs/DjcOMK8P2rFBOoH5evYoNh9eytWjH tQfBuRs2CwdDYrzbghR1u26yZA== X-Google-Smtp-Source: ALg8bN629SE9dDygTDbp0bwsX0CuWrV5NbXzQWdOpbOoE22V/wBo5cWCsLoBvyPBXCe3wgOhDB1xDg== X-Received: by 2002:ac8:3d91:: with SMTP id v17mr13062595qtf.204.1547763789618; Thu, 17 Jan 2019 14:23:09 -0800 (PST) Received: from alvin.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id d85sm20743064qkb.89.2019.01.17.14.23.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 17 Jan 2019 14:23:08 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id E5A4595C; Thu, 17 Jan 2019 19:23:06 -0300 (-03) Date: Thu, 17 Jan 2019 19:23:06 -0300 From: Alvaro Herrera To: Amit Langote Cc: Tom Lane , Jesper Pedersen , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15587: Partitions with ALTER TABLE ADD CONSTRAINT Message-ID: <201901172223.lm3iihkw7hn4@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="gr4h3ox77briqjuh" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <0757116d-f94e-ba78-b6d9-17ffcf8ff5bc@lab.ntt.co.jp> User-Agent: NeoMutt/20180716-1013-2c1e88 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --gr4h3ox77briqjuh Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2019-Jan-16, Amit Langote wrote: > Why not just move the code in clone_fk_constraints() that checks if the > constraint equivalent of the parent's constraint is present in the > partition and simply attach the two without creating a new copy for the > partition to a new function in tablecmds.c and call the function from both > clone_fk_constraints() and ATAddForeignKeyConstraint()? Attached is what > I'm thinking. Well, the whole point of my proposal is that the FK-creating code recurses to partitions by calling ATAddForeignKeyConstraint, and IMO that's the wrong level to recurse at; we should instead recurse by calling clone_fk_constraints() as a whole. That's not readibly possible with the current code arrangement because of layering, but after backpatching (as attached) the two patches I mentioned, I end up with the following, which I think is much cleaner. (Also, this code layout plays much better with my project to continue to extend FKs so that they are allowed to point to partitioned tables; see the other thread). The attached patches are for pg11; they don't apply to master. The changes are uninteresting. The tests added by the final commit clearly show dupe FKs being created in some of the cases, if you run them without applying the code fixes, and none afterwards. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --gr4h3ox77briqjuh Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Refactor-duplicate-code-into-DeconstructFkConstraint.patch"