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 1j07QF-0001IF-MD for pgsql-bugs@arkaria.postgresql.org; Fri, 07 Feb 2020 17:28: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 1j07QC-0003QC-7B for pgsql-bugs@arkaria.postgresql.org; Fri, 07 Feb 2020 17:28:04 +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 1j07QB-0003N4-Ro for pgsql-bugs@lists.postgresql.org; Fri, 07 Feb 2020 17:28:03 +0000 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j07Q4-0000tO-BI for pgsql-bugs@lists.postgresql.org; Fri, 07 Feb 2020 17:28:03 +0000 Received: by mail-qk1-x741.google.com with SMTP id v195so2938618qkb.11 for ; Fri, 07 Feb 2020 09:27:55 -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=npfkY4d+/+AwxHrKxCLNE3m7RtVafwUefn/v4+w1DxM=; b=M1b5j73noherG0NIaxChIzsbcEfXO2gT49OqZLmep/1S8LK38GEfGwDf25MVsjFnnD NIBw4SKf3XbSJwy3t8tw3SvSq38c9lJLdElhggNs8XQIMIKpg9ZrJb2nk3EifRZorJA0 OpnjjIQtm2up2ojQ7BAEYEZQA73WhhZ1fAtcedxneRGUaDH2VdyrP0KmRX29J5V3igIR Xk5RQUOTzKkkmwU5QzW/K3eC3QhEey3VZkfrGbRgRodRBhJdGtReH67invuk+t+CHph1 G14EsDoZSDQQjoRlWluML6IAbV+5mcouc/MqRP812JhmnlAD5WXX6QB/hnmT0baCgClX 3TfQ== 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=npfkY4d+/+AwxHrKxCLNE3m7RtVafwUefn/v4+w1DxM=; b=ff3FPmZwWuJhLkhWoQ6YbR55rIT4B0sRIplX4twekyS8n4MYlEKcQq+FAKAnygRMT0 t6DCKt4kD3MoOd2zqwLdNMMRXuQURXhSZXh/1VfbWJyNOp2cPYvuEQbtiQxCkJNnrJkc n/IDrpetVSJwkW/+e1GsUdD+DDgoTQLfpUnZG1HC72oCENnhQc5Wrq9p9+0mi9LONycV XgRxFivF/M6UiWFLKJnzrcMPIRLEJRmyjEbIB0PXH09BAVbXYuaEFFQk0pHYaV5XP9i+ aKIQ1LOhP65YQHLArbGC25WaHymglVhZo1n83sKJRU3AIZ5nploKl7l6HAspiriCG+IB fy4A== X-Gm-Message-State: APjAAAVI4oEARNiY9/nfdi/17A7w34TbxYHfEJ6T1y9CBBke6yYSauXQ H81Xu1XifX8MKu7zovjPVqOccCWqjtc= X-Google-Smtp-Source: APXvYqy88ZYokkJ5VvdGnzfsEZvLxKHcaf+yEOYIKduW3TSgqO+9PbqQs/IfRPIH7Rg+HmayZnQSpQ== X-Received: by 2002:a37:6c6:: with SMTP id 189mr7784075qkg.179.1581096474319; Fri, 07 Feb 2020 09:27:54 -0800 (PST) Received: from nimloth.alvh.no-ip.org ([179.56.51.3]) by smtp.gmail.com with ESMTPSA id i4sm1646580qkf.111.2020.02.07.09.27.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Feb 2020 09:27:53 -0800 (PST) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id D38C0300A71; Fri, 7 Feb 2020 14:27:51 -0300 (-03) Date: Fri, 7 Feb 2020 14:27:51 -0300 From: Alvaro Herrera To: Jehan-Guillaume de Rorthais Cc: pgsql-bugs@lists.postgresql.org Subject: Re: FK violation in partitioned table after truncating a referenced partition Message-ID: <20200207172751.GA26691@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200207171933.77aaaba6@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-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. 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! (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 ... > This is out of the scope of this bug fix in my humble opinion. This would be a > whole new feature, even if it could be done without a new syntax. Sure. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services