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 1h4W9n-0003ta-Ow for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Mar 2019 19:36:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h4W9j-000228-5d for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Mar 2019 19:36:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h4W9i-00021h-R6 for pgsql-hackers@lists.postgresql.org; Thu, 14 Mar 2019 19:36:42 +0000 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h4W9f-0008Ux-KF for pgsql-hackers@postgresql.org; Thu, 14 Mar 2019 19:36:41 +0000 Received: by mail-qt1-x842.google.com with SMTP id u7so7469866qtg.9 for ; Thu, 14 Mar 2019 12:36:39 -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=7d0LlpCv3a3yoY+SqhHysO57FbghO5c6z2KvazNyrJ8=; b=KkO5XJ54gliBsX/mYbFNTSxRRcnibM+AkQZENSnIFfx0Xm/WlDK4kQRjC+bgxNTtKu KCpjvRRwCSOhQy4VdAm4tG0tBxdzl+XIX9khN2P1n1HYg45hrOgKhbEtTLdNtim6EWuQ 2CzQzikoHUVXr4HjIidK/roV2mD2bsDPeEU3NpyaZ8mWmq7isL2dfnea2GoRiYH4xdKL ytwp/coSXkDnc/JXAGkwjJEpy+Qsb3JhHaYSV/Dj3t+4qRYl5FT2tSfsL3ifJ6F+NUfr hvubsBOqGJSwMoQ/cbioumd8jKXaqC1bSV0mbGR0kZfkf7ZKpJu1bcWpP9O8WTQtbZIO +06g== 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=7d0LlpCv3a3yoY+SqhHysO57FbghO5c6z2KvazNyrJ8=; b=gYZYZnfwEoGc+CHkNFu6pWDDXn0BWwFREAM0GnMK3g8WSegQQ4SvgIdJmh5a5Ee67z 04LfjsDNwm+K0ImmoGPnOW15n79Z1t7otfhCpcrbAS/3KN9QUTQIiYBeHrmMgtSWp/RI AJl0VRMgJMynE4OznF2aupl2LEF4xjLM1YRGta2u3KgVIjOzCYC1BVu4FsQEkFIm+asR 0fWPvIuTeq+Fd/Xnmnk13Bo2fgTYeGabrR58KQ0xhhz7LaPJcv6k0SWILBFJIljtY7uZ erHri+jjqCBnBIekZ5wY+CwdBcn8dhtOQg0ZN0/OzToiEtksRgM3+z6fVhYT+Dzkaq7m hyPw== X-Gm-Message-State: APjAAAUprz8AWBYdF5dOzrQ7mhiBM3qmcpIEzG32F+F8z62J+rcGLZNE TMSqPwmieFwODnYfUqhNQnFbnw== X-Google-Smtp-Source: APXvYqz2fcAv2A5oD5UiUE6QrhH1bZy3Scp0qsFly2OkJR6pavwrEDuz9GX4gY9yY8KUbwWVeNI6BQ== X-Received: by 2002:a0c:9910:: with SMTP id h16mr40443241qvd.245.1552592198573; Thu, 14 Mar 2019 12:36:38 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id o19sm5136470qkl.65.2019.03.14.12.36.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 12:36:37 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 195A2121E75; Thu, 14 Mar 2019 16:36:35 -0300 (-03) Date: Thu, 14 Mar 2019 16:36:35 -0300 From: Alvaro Herrera To: Robert Haas Cc: Amit Langote , Pg Hackers Subject: Re: partitioned tables referenced by FKs Message-ID: <20190314193635.GA8910@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-Mar-14, Robert Haas wrote: > On Thu, Mar 14, 2019 at 1:40 PM Alvaro Herrera wrote: > > 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. Have a > > look at the triggers in pg_trigger that appear when you do "references > > pk1" vs. when you do "references pk". The constraint itself might > > appear identical, but the former adds check triggers that are not > > present for the latter. > > It's probably not uncommon to have FKs between compatibly-partitioned > tables, though, and in that case they are really equivalent. For > example, if you have an orders table and an order_lines table and the > latter has an FK pointing at the former, and both are partitioned on > the order number, then it must be that every order_line references an > order in the matching partition. Even if it's not practical to use > the FK itself, it's a good excuse for skipping any validation scan you > otherwise might have performed. Well, I suppose that can be implemented as an optimization on top of what we have, but I think that we should first get this feature right, and later we can see about improving it. In any case, since the RI queries are run via SPI, any unnecessary partitions should get pruned by partition pruning based on each partition's constraint. So I'm not so certain that this is a problem worth spending much time/effort/risk of bugs on. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services