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 1j0BDK-0005vO-7D for pgsql-bugs@arkaria.postgresql.org; Fri, 07 Feb 2020 21:31:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j0BDJ-0001rV-0K for pgsql-bugs@arkaria.postgresql.org; Fri, 07 Feb 2020 21:31:01 +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 1j0BDI-0001rO-L9 for pgsql-bugs@lists.postgresql.org; Fri, 07 Feb 2020 21:31:00 +0000 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j0BDF-0005QS-NZ for pgsql-bugs@lists.postgresql.org; Fri, 07 Feb 2020 21:31:00 +0000 Received: by mail-qt1-x843.google.com with SMTP id c5so524563qtj.6 for ; Fri, 07 Feb 2020 13:30:57 -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=zEPaf23UsaNKwMFxV4PipqRWYAwmxprO2ssz2v8qDXs=; b=Xa9DcIIpjZt5+U1V+qUzSdJ0qaogsXwr9+B7gsByBUcMrOW2pTMVrg7NHp3daJ6KkJ vaYsDnejKQUKywUNZkbGNKk9lcBeOmrVaMy+pVy8saQuUWs6fAW4pvhcUAsPWtW3F+D8 BX+O/VdyNufSqCFU2UGCoai3tTiaLp9psKPhNuKmkaQEIazKJ7+pdXCIdAYKR7Dmv4uh bOnYBhO5sYyTv/erJFZ8TA+UK4l+njwNADZWL9zQGI0aIpPbEL0ILRM3gYw1/3t6wt2c pRWSbg9EU/vO+biq6HH4ocC3LIdygzJQ9en7dApj5OuZ185eyIPGj+sN/ha2D9MvQA+m nb2g== 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=zEPaf23UsaNKwMFxV4PipqRWYAwmxprO2ssz2v8qDXs=; b=cU0JhfSwQPuePO4aYU2p8JUDTyEMJMPwoyOV87wsuPUEq5dUy6a3U48A4Ujk1qq+PO dyqjqfcJUnR7qRbhOZjCTd7I9ZtUpFBxKvv68uJPx0KTgACZl+nng8vnZwGviqvtUJ5i tuABud81qYzh/F2fVAEMiCQ77bDSCw1gZCCLHYoPta7n8yE/ZGluRqoyusGQZOwQTNOR tN2ghQQaW4FBdtGxNm/mbFD4iLXgDNuAX1z6FGl8vOUBnUOs2eiaTJgwn801yi0KJctR Uqq3mwWU8EdliUanJ21Jy8ICIupyfN7w1MkRuDxOBo25moo+xdtsOkXjNECElCoqNo2p 6lTQ== X-Gm-Message-State: APjAAAUdml9RDbLwI/T4rQRQPgcaz7eJPSQr5HidHvu2IlKa2M11584H Uu5xiwCZnzjYmYtXi6jCVMMQx4wzalQ= X-Google-Smtp-Source: APXvYqzYwa8kTPyasg0He9TMi9Ohv48jDJJg0N8kh3JW+xuo+zRQViMu1u1CL75b76MTjFb7MgQpdQ== X-Received: by 2002:ac8:365c:: with SMTP id n28mr382096qtb.260.1581111055991; Fri, 07 Feb 2020 13:30:55 -0800 (PST) Received: from nimloth.alvh.no-ip.org ([190.217.182.22]) by smtp.gmail.com with ESMTPSA id w41sm2017115qtj.49.2020.02.07.13.30.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Feb 2020 13:30:55 -0800 (PST) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 22E24300930; Fri, 7 Feb 2020 18:30:51 -0300 (-03) Date: Fri, 7 Feb 2020 18:30:51 -0300 From: Alvaro Herrera To: Jehan-Guillaume de Rorthais Cc: pgsql-bugs@lists.postgresql.org Subject: Re: Another FK violation when referencing a multi-level partitioned table Message-ID: <20200207213051.GA32185@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200206004948.238352db@firost> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-Feb-06, Jehan-Guillaume de Rorthais wrote: Hello, > When working on the patch to fix another FK violation [1], I found that FK > constraints were not properly cloned to partition not directly hooked to the > root table. Uh. > Surprisingly, the comment explains how this should be done in two steps, but > the code corrupted the first step by skipping inherited constraints and lacks > the second step: > > * [...]to avoid duplicates. So do it in two > * steps: first construct the list of constraints to clone, then go over > * that list cloning those whose parents are not in the list. (We must > * not rely on the parent being seen first, since the catalog scan could > * return children first.) > */ Strange that this escaped testing previously. > Please, find in attachment a proposal patch to fix this FK violation. You fix looks correct to me, so pushed. I took a minute to apply some minor corrections to the comments, too. Thanks for reporting! -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services