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 1h6dbo-0004Gq-0w for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Mar 2019 15:58:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h6dbm-0003G0-Mr for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Mar 2019 15:58:26 +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 1h6dbm-0003Ft-Ak for pgsql-hackers@lists.postgresql.org; Wed, 20 Mar 2019 15:58:26 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h6dbj-0000W4-9v for pgsql-hackers@postgresql.org; Wed, 20 Mar 2019 15:58:25 +0000 Received: by mail-qt1-x841.google.com with SMTP id v20so3065382qtv.12 for ; Wed, 20 Mar 2019 08:58:23 -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=xONQW8ZuR45efnuQ7+khVTRO9sbiXyOSryv6i4eC4+M=; b=UoBiwsvkDovsLfDBanuynywydwzpbsahldEZUVhpC3evTc5xjCLkEH9hzgA2sXqOWs G61V2kdMmL0rAoVpKeiok5nguTyeXh1AETSCn/fzAs0aNTOe3mpwPWDIandSpLAfBC8F I65ES9Fi4xubSu+dlCCvL3ZB+qZNxWU5J4qBQh+ukVkZHF2mWapSs7eigy0svyKuhmLL vCr1ILhVEEh8s5iN6OlDXonIoNZfplOa0bKAycZ5cEronuMctIuiIb75XBHtT+F+N8wa dfzU4X7pBP1ccExU2ZLMeZLth9HEMYU4f3MPFjwx+jET9Y+whkj7tY8kbqnk7H5CKr0T ukRw== 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=xONQW8ZuR45efnuQ7+khVTRO9sbiXyOSryv6i4eC4+M=; b=WTgCKfOo+X03HpogjDCTqmANiTDktG7Pq+FUbLnxOTlOGnsAgDDXEJFNwHuoAIyMLn 1bGtEmGjgNV8taAw23lMCM8T52BEKZiO/t/6dAC33WuWkVeWzAjo4zcg5IQZhfKTU3LT jsRECID+weyu/Fw4pjlzsZWTCWCLnAv1wCh+Y7IGGzgyXk2orLULa7aLJVeDDKU25AzN nGq5EGPCvJOEQkRO0hyFrqwIreTV2SyU8FtvkhiaFsu/+GwUph2XDth/COkE3s0fze3p ChnCcSA8UN04CXh0GAWOBrxx5k/V1MNtDltpXa5/k1ZafilKMFNlpYZPmQgnSzh5y/Pe vDnA== X-Gm-Message-State: APjAAAVNp2ocLdsNcwlbYcLZ92/WixcywULvRHS142Bf7d/Dc3a5xIBm H+DfHqgBmjtoe5UWZcV7n+mZMQ== X-Google-Smtp-Source: APXvYqy+IaRrBVFOpZ+4SmjKLlnp4mgU7Qre88Jud4mZwKWcTW+ZXB1dpA196V1dLL7a+rLZc/PRCQ== X-Received: by 2002:ac8:3697:: with SMTP id a23mr7828856qtc.18.1553097501631; Wed, 20 Mar 2019 08:58:21 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([191.126.227.196]) by smtp.gmail.com with ESMTPSA id p188sm1321427qkb.43.2019.03.20.08.58.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 08:58:20 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 43A45120693; Wed, 20 Mar 2019 12:53:30 -0300 (-03) Date: Wed, 20 Mar 2019 12:53:30 -0300 From: Alvaro Herrera To: Amit Langote Cc: Amit Langote , Pg Hackers Subject: Re: partitioned tables referenced by FKs Message-ID: <20190320155330.GA8821@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190319121311.GA11582@alvherre.pgsql> 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-19, Alvaro Herrera wrote: > I think this is fixable by using a two-step strategy where we first > compile a list of constraints being dropped, and in the second step we > know to ignore those when checking partitions that are being dropped. > Now, maybe the order of objects visited guarantees that the constraint > is seen (by drop) before each corresponding partition, and in that case > we don't need two steps, just one. I'll have a look at that. I tried this, it's pretty horrible. I think it's not completely impossible, but seems to require a "suppression list" of constraints, that is, a list of constraints that ought not to be checked because they're also being dropped in the same command. Here's what ugly: when you drop a partition, its part of the FK constraint (the corresponding pg_constraint row) is also dropped, but its parent constraint is what remains. We need to know to suppress the error when the *parent constraint* is dropped, but *not* suppress the error when only the child constraint is dropped. I can only think of ugly data structure to support this, and adding enough hooks in dependency.c to support this is going to be badly received. I think a better idea is to prevent DROP of a partition that's referenced by a foreign key, period. We would only allow ALTER..DETACH (they can drop the partition once it's detached). It seems to me that the check can be done more naturally during detach than during drop, because we're not constrained to do it within the dependency.c system. However, this still doesn't solve the "DROP TABLE pk CASCADE" problem, unless we register the dependencies differently. I've been trying to understand how to make that work. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services