Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lO3Xq-0004K8-Hy for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Mar 2021 19:15:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lO3Xp-0002UV-Fq for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Mar 2021 19:15:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lO3Xp-0002UO-4y for pgsql-hackers@lists.postgresql.org; Sun, 21 Mar 2021 19:15:25 +0000 Received: from mail-io1-xd34.google.com ([2607:f8b0:4864:20::d34]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lO3Xm-0004je-Ul for pgsql-hackers@lists.postgresql.org; Sun, 21 Mar 2021 19:15:24 +0000 Received: by mail-io1-xd34.google.com with SMTP id f19so11697919ion.3 for ; Sun, 21 Mar 2021 12:15:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=EEFtNtQbM824URdqVQVQhb2cY3Bhd/axIn3D7cNAEr8=; b=vJNX+w8fJ1EnhxKVLCOgaNyoNR5U7bSu/YEOwVzrzfv2X4unwjGzcWcPU/WckIYUPg 7qg9A2F3XbSnBx75eG/5QV1XzzpSVDtiJi12sbHmFMphakPamS27lvUPpHP8y8q6rli0 Pv5ynxt/C2KR6be2hPFgMNTHu3xy/KMeG3o5RBckOs/fNGZ/UzZlgQLHcubmaEfXysnn RKu1wjOWY40NznMT+OhvpHKbtNPTfLEyGRg3Yy4mzVp6o3XMllZsXKvDf70PB36ZMBai VirFDjmtnDcn7fs2AW1yF5j+iypZD1DAfPQ7PU7aMymV28Cww4DB3uoSBHumJCHx0RCP VxpQ== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=EEFtNtQbM824URdqVQVQhb2cY3Bhd/axIn3D7cNAEr8=; b=ZvqGacan+2ujpUKrfIUdOpdWWkDu1Q2mIMSojfjPXgC5NTpdsAzem6J/Id0xvS5+Su TKCtmBoifLJ2LgMcCIXBOkJ7431YqM2q5AmEi3Xm/+V8yrOOyVqtVFs4Tyw59Zq1pVUS nhG9s5EBkyX808jtqC2xURQw2/3ZczKXZl5ct/qcGTPkA68S4V9ooNK8DTqM4e1J2vFf DxYIZ1t0xkybTwTQlXPPxRZ+Up12CETpyWoOkDlGjuZO4Kn+MQ+Evq0VAzlT5JDa14Uc nHuTRrnl5zyMbJV1p2t/OSRMedHXTYQ6tUwSN4SZRvJEfPaw47eSuDu/BO+hH5qZKZ0h ZBqA== X-Gm-Message-State: AOAM533FugqeL6NsqDyZYcUp2Ji+vY5hWAuhVuM8+zu6xxLKI4gghegf /REGgoWCHKr1OCa/BZF2KU2qNA== X-Google-Smtp-Source: ABdhPJz4pOSoIdzb9eu6cobuZeTGAH5/UpvZlgGwoTaS8RO42CQ+yAGURGsNhRQFqAx3KwSGp5yd8A== X-Received: by 2002:a5e:8712:: with SMTP id y18mr8497092ioj.65.1616354121281; Sun, 21 Mar 2021 12:15:21 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id 128sm6326151iov.1.2021.03.21.12.15.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Mar 2021 12:15:20 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id AD1378010CC; Sun, 21 Mar 2021 14:15:19 -0500 (CDT) Date: Sun, 21 Mar 2021 14:15:19 -0500 From: Justin Pryzby To: Alvaro Herrera Cc: Amit Langote , pgsql-hackers@lists.postgresql.org Subject: Re: ALTER TABLE .. DETACH PARTITION CONCURRENTLY Message-ID: <20210321191519.GA4146@telsasoft.com> References: <20210321182903.GD11765@telsasoft.com> <20210321190712.GA8502@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210321190712.GA8502@alvherre.pgsql> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Mar 21, 2021 at 01:14:20PM -0500, Justin Pryzby wrote: > On Sun, Mar 21, 2021 at 03:01:15PM -0300, Alvaro Herrera wrote: > > > But note that it doesn't check if an existing constraint "implies" the new > > > constraint - maybe it should. > > > > Hm, I'm not sure I want to do that, because that means that if I later > > have to attach the partition again with the same partition bounds, then > > I might have to incur a scan to recheck the constraint. I think we want > > to make the new constraint be as tight as possible ... > > The ATTACH PARTITION checks if any existing constraint impilies the (proposed) > partition bounds, not just if constraints are equal. So I'm suggesting to do > the same here. On Sun, Mar 21, 2021 at 04:07:12PM -0300, Alvaro Herrera wrote: > On 2021-Mar-21, Justin Pryzby wrote: > > On Sun, Mar 21, 2021 at 03:22:00PM -0300, Alvaro Herrera wrote: > > > So if we do that on DETACH, what would happen on ATTACH? > > > > Do you mean what happens to the constraint that was already there ? > > Nothing, since it's not ours to mess with. Checking ImpliedBy() rather than > > equal() doesn't change that. > > No, I meant what happens regarding checking existing values in the > table: is the table scanned even if the partition constraint is implied > by existing table constraints? I'm still not sure we're talking about the same thing. Your patch adds a CHECK constraint during DETACH CONCURRENTLY, and I suggested that it should avoid adding it if it's redundant with an existing constraint, even if not equal(). The current behavior (since v10) is this: postgres=# ALTER TABLE p ATTACH PARTITION p1 FOR VALUES FROM (1)TO(2); DEBUG: partition constraint for table "p1" is implied by existing constraints ALTER TABLE And that wouldn't change, except the CHECK constraint would be added automatically during detach (if it wasn't already implied). Maybe the CHECK constraint should be added without CONCURRENTLY, too. One fewer difference in behavior. -- Justin