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 1j0Big-00070q-4X for pgsql-bugs@arkaria.postgresql.org; Fri, 07 Feb 2020 22:03:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j0Bie-0007pW-Sz for pgsql-bugs@arkaria.postgresql.org; Fri, 07 Feb 2020 22:03:24 +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 1j0Bie-0007pP-9e for pgsql-bugs@lists.postgresql.org; Fri, 07 Feb 2020 22:03:24 +0000 Received: from mail.dalibo.com ([212.85.157.172]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j0BiX-0007SR-QS for pgsql-bugs@lists.postgresql.org; Fri, 07 Feb 2020 22:03:23 +0000 Received: from firost (unknown [88.190.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id 6B0B91F9C3; Fri, 7 Feb 2020 23:03:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1581112995; bh=zM+hfH6bFcvh1oHXjw54uu0PAkXQgaxyaV/hys3Ys08=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=OoXH4HPbF1yXO1cnp/mn2Fx2QLAqgajVGrPCpOPJqAV+0svCjBeE/bmL4Kk7ShgEA 5UovptgSfmICBbK6YsPV9D3evjpwm9q+jYhcqkvXBcCazawws3rx7Dk8W2kaMjoqzP X3t77wLowCPS8DpKCXN6mwBN1+7oJzu8CG0J5vzM= Date: Fri, 7 Feb 2020 23:03:14 +0100 From: Jehan-Guillaume de Rorthais To: Alvaro Herrera Cc: pgsql-bugs@lists.postgresql.org Subject: Re: FK violation in partitioned table after truncating a referenced partition Message-ID: <20200207230314.350a59bc@firost> In-Reply-To: <20200207201948.GA16783@alvherre.pgsql> References: <20200207192257.1145eadd@firost> <20200207201948.GA16783@alvherre.pgsql> Organization: Dalibo MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, 7 Feb 2020 17:19:48 -0300 Alvaro Herrera wrote: > There's another key point I forgot -- which is that we only need to > search for constraints on the topmost partitioned table, not each of its > partitions. The reason is that pg_constraint rows exist on the other > side that reference that relation, for each partition on the other side. Yes, I figured this as well when drawing things during debug time. By this time, I kept it this way because I wasn't sure about potential complications with sub-partitioning and FK to sub-partition only. > So we can do this: [...] > that is, keep appending to the parent_cons list, and not touch the oids > list, until we get to the top of the hierarchy. Then when we redo the > first loop, we'll get all partitions on the other side because they all > have pg_constraint rows that reference the topmost rel. (That is to > say, all the intermediate-partition OIDs should be useless in the 'oids' > list anyway.) It makes the oids list smaller (depending on the partitioning depth). As it is scanned for each FK in pg_constraint, it surely squeeze some more time. I'll stick around irw the other FK violation thread. Please, keep me in the loop. Thank you for the discussion and commit. Regards,