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 1j08HU-0004Fx-2i for pgsql-bugs@arkaria.postgresql.org; Fri, 07 Feb 2020 18:23:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j08HS-0001Jo-RB for pgsql-bugs@arkaria.postgresql.org; Fri, 07 Feb 2020 18:23:06 +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 1j08HS-0001Jg-4j for pgsql-bugs@lists.postgresql.org; Fri, 07 Feb 2020 18:23:06 +0000 Received: from mail.dalibo.com ([212.85.157.172]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j08HN-0007D5-PK for pgsql-bugs@lists.postgresql.org; Fri, 07 Feb 2020 18:23:05 +0000 Received: from firost (unknown [88.190.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id DABEF1F9C3; Fri, 7 Feb 2020 19:22:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1581099777; bh=LBT3bPT9eekR7mkYoeMc1q8hpUBP/KI8GnDykwweL3I=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=LcAvPxR4sd3oSdn23O0Y+zKPDop+ddaXUAjlyrgY747U+sNO/vrDnzWBDbswaHxBw H8XuwQlXLxfjcgEAouGzKyajYNy5XOFL66+Bs3eokxB5Ucs7PS8MO1TCwFC5Ireg0P NzOYrSHqz7KxLvzYx+TYcTpPcqho0bqfSIxUxW54= Date: Fri, 7 Feb 2020 19:22:57 +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: <20200207192257.1145eadd@firost> In-Reply-To: <20200207172751.GA26691@alvherre.pgsql> References: <20200207171933.77aaaba6@firost> <20200207172751.GA26691@alvherre.pgsql> Organization: Dalibo MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/Hh5OBOP+/TWFwYf/ezBKPvu" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --MP_/Hh5OBOP+/TWFwYf/ezBKPvu Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline On Fri, 7 Feb 2020 14:27:51 -0300 Alvaro Herrera wrote: > On 2020-Feb-07, Jehan-Guillaume de Rorthais wrote: > > > Maybe I would just add: > > > > /* > > * If this constraint has a parent constraint which we have not seen > > * yet, keep track of it for the second loop, below. > > + * Tracking parent constraint allows to climb up to the top-level > > + * level constraint and look for all possible relation referencing > > + * the partioned table. > > */ > > LGTM. Added. > BTW I was thinking that perhaps it would make sense to go up all levels > at once when we see a "parented" constraint; this would avoid having to > restart several times when there's N-levels partitioning. It might be > an issue if pg_constraint is large, because, you see, there's a seqscan > there! Indeed. See v4 in attachment. It saves 3 seqscans during the whole tests we added. > (Maybe now's the time to add an index to confrelid, but of > course only in master). This probably doesn't matter much normally > because nobody uses that many partition levels ... I have a colleague that enjoys experimenting with limits. But I'm not sure I'll have feedback from him before next minor release (next week?). Regards, --MP_/Hh5OBOP+/TWFwYf/ezBKPvu Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0001-v4-Fix-TRUNCATE-on-a-partition-to-apply-CASCADE-to-part.patch