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 1h5sqV-0000rf-7n for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Mar 2019 14:02:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h5sqT-0002Pq-FB for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Mar 2019 14:02:29 +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 1h5sqT-0002Pd-3C for pgsql-hackers@lists.postgresql.org; Mon, 18 Mar 2019 14:02:29 +0000 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h5sqL-0005qS-SU for pgsql-hackers@postgresql.org; Mon, 18 Mar 2019 14:02:28 +0000 Received: by mail-qk1-x743.google.com with SMTP id g1so5418494qki.5 for ; Mon, 18 Mar 2019 07:02:21 -0700 (PDT) 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=EZeJzYdpzSL+ct6i8EHKnQgU/qRDZjJpoKfy9WcFtsk=; b=hoaSzPg5cbCOHIQ0y91nmL6t1hbZFyVKl11PcjA5ONzuNCsvjsR/kayMGnXOpuhkCw IK7DmtU1RbdYUHfMOXGev9XsTt37LEqktqWdoZeX4fuwnS9iE/n85DQiKPHcbld//oyW nLyU4dSirw6a1vMJX0or55VqhLhQajkqTgqGMDj6LSohpTSJ0pYZG/Ko7nTPsQyG/kJX FHbP1+48haoYKUxuvi5XR/trOTsaFb256SG57Z6HBOfPTA+Rvn9tHLj9kf+4/sP/ixRx WTAP2CuKmXtN/ZRUFhdwwuYFsZJPwqD4o9ijIwuMffyXju2msa4Jj/oxIAGSREQIKyEe 9mPw== 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=EZeJzYdpzSL+ct6i8EHKnQgU/qRDZjJpoKfy9WcFtsk=; b=W7CxpvMr/eia13X4T/9fgU+WWk+ZMA+Isb0o8ezTJ28Squ/eV2O7o9xQAACB03jk5I pl59RTsNvxtztqasGG17Qo0axN6KEs8UgEheBX2iVhs4sQws0jGvLYGOYtKucacQSwwQ iKOPl02jebwLFiEKjLw8oSmzhEtS3qLlx+k6P+Ea73xLtvJWYZdbOhslphvWFUqUVAIw eaU8/B2P/K/13IX9ZVI0d9Sp8fwOqsL2+TZJ2BiXLk+GNe93Ea77NRBJE6kKpzBM+70g eAsl9xSI0dBsk4KQs8TNaV7TjeiD3VVlniHLFgKZ9RxiWwqTONHrwDuYSJDFpp6BshqT qstQ== X-Gm-Message-State: APjAAAUTH4VIwuuvzufBdeM+0IdWKNW6KqvG6Vc+/sjWxgNQOGdp1Bio t8UIwpeAYNpNEK6NaDhibI+kbXCpkyrgAw== X-Google-Smtp-Source: APXvYqze9p05yt4fgGotUcmHodzMWSqcqarBlR88ImX2ARIFWjomenG8V+1JPQo5H/Q5lZnfOsU2lQ== X-Received: by 2002:a37:9682:: with SMTP id y124mr12371867qkd.288.1552917739207; Mon, 18 Mar 2019 07:02:19 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id n201sm5085489qka.10.2019.03.18.07.02.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Mar 2019 07:02:18 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 594DC121CD1; Mon, 18 Mar 2019 11:02:15 -0300 (-03) Date: Mon, 18 Mar 2019 11:02:15 -0300 From: Alvaro Herrera To: Amit Langote Cc: Pg Hackers Subject: Re: partitioned tables referenced by FKs Message-ID: <20190318140215.GA23336@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1ecdd004-9ef6-88ad-f5ef-fc221350fef5@lab.ntt.co.jp> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi Amit On 2019-Mar-18, Amit Langote wrote: > On 2019/03/15 2:31, Alvaro Herrera wrote: > > Once I was finished, fixed bugs and tested it, I realized that that was > > a stupid thing to have done -- because THOSE ARE DIFFERENT CONSTRAINTS. > > When you say "fk (a) references pk1" you're saying that all the values > > in fk(a) must appear in pk1. OTOH when you say "fk references pk" you > > mean that the values might appear anywhere in pk, not just pk1. > > Sure, then just drop the check trigger that queries only pk1, in favor of > one that checks pk, that's already in place due to the parent constraint. > Actually, if one doesn't drop it (that is, by way of dropping the > constraint that created it), they won't be able to insert into fk anything > but the subset of rows that pk1 allows as a partition; That's true, and it is the correct behavior. What they should be doing (to prevent the insertion into the referencing relation from failing all the time) is drop the constraint, as you suggest. Converting the constraint so that it refers to a completely different set of permitted values is second-guessing the user about what they wanted to do; what if we get it wrong, and they really wanted the FK to reference just exactly the subset of values that they specified, and not a much larger superset of that? -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services