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 1jQFT4-0004ga-Az for pgsql-hackers@arkaria.postgresql.org; Sun, 19 Apr 2020 19:19:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jQFT3-0008SQ-67 for pgsql-hackers@arkaria.postgresql.org; Sun, 19 Apr 2020 19:19:01 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jQFT2-0008SI-RL for pgsql-hackers@lists.postgresql.org; Sun, 19 Apr 2020 19:19:00 +0000 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jQFT0-0000XR-7f for pgsql-hackers@lists.postgresql.org; Sun, 19 Apr 2020 19:18:59 +0000 Received: by mail-qk1-x741.google.com with SMTP id b62so8387028qkf.6 for ; Sun, 19 Apr 2020 12:18:57 -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=afJJj8wqOd/aorx/OPEn5FdAbnFm8r9f3lGnKWFha00=; b=Y4Lx1g6p1wpnG4L/IE9KH8Hhzdocy64Zgu5gj1oc0lkb+bQMJ/nLfKLYh+HBpwoNiU bq1OVPJ8wEbDb8ntNoSF7nzoTsHxzXX+XFzJt9hflDwgq3GfxbDbAJyOmGh3PyveJLIF zZ/Vr+iVzkE2FxvwdYOeCF6lsLkGHcy5/MNQA26OnqDG4fEKPTAW0lvDEO34KkQrzJDg nb54KrTdFM+p0kQaMYl1N2imCMgXKMhlEcryPAg89m8SlfmL+knK9loWfNGU1QEtSPu6 a4591HCZtd5SXderr1oCxRu/F3hvQzNorUKIAuvf9nbjx2vTcVtbprUGda5Q1ZEvEpMM qspg== 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=afJJj8wqOd/aorx/OPEn5FdAbnFm8r9f3lGnKWFha00=; b=CB/yTQ9u8y8PU0D3x3+uzkDxWVJl+pu0LpCAL4BMiuDIwH7MdZmlWkrqVx+bDSlp+j ydTwUGV2ehYg42nVnJB2ObW3LBGE9qwqMY6WjFURBywPYItUSqNsOKGnR+IoVP7BcpqR iHpUEEuoC+wcrRrRDBtYiVNRgojTwX99vFbQwdouBRV7Oe1tOM0Q7e9oFsPdwmHtq8ka XbAK1NcAo5FiCvB/nejJ2+iowKipFHWTUXEQeWOWdvRODkvapT/jRxPGeC92Ap2HdHbB C08SgHBBgfrBd/3TkcBKIsRHYONdXUp/3yoENjztA9oXDxeIKqc3o4thIuMJoaBezbzl bOhg== X-Gm-Message-State: AGi0PuYsjjhJHqq5YhIRjqRL6fPaQWV2p7sKlQH6+2YPtCAU0+nJTSZ2 6BbtR2N0MDxeyjFeitqSTYsjF9llNDo= X-Google-Smtp-Source: APiQypL0sivtMD7tQRLCDJ6T/Snl9KywR95rn+BM30cLRQOsj1/l9gmmMJYaTcopHuaRscQ92+G/hg== X-Received: by 2002:a37:6f41:: with SMTP id k62mr12247845qkc.239.1587323937181; Sun, 19 Apr 2020 12:18:57 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id y17sm17659607qky.33.2020.04.19.12.18.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 Apr 2020 12:18:56 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 6D52580143B; Sun, 19 Apr 2020 14:18:54 -0500 (CDT) Date: Sun, 19 Apr 2020 14:18:54 -0500 From: Justin Pryzby To: Alvaro Herrera Cc: pgsql-hackers@lists.postgresql.org Subject: Re: DETACH PARTITION and FOR EACH ROW triggers on partitioned tables Message-ID: <20200419191854.GA14956@telsasoft.com> References: <20200408152412.GZ2228@telsasoft.com> <20200408160239.GA13987@alvherre.pgsql> <20200408164433.GE2228@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200408164433.GE2228@telsasoft.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Apr 08, 2020 at 11:44:33AM -0500, Justin Pryzby wrote: > On Wed, Apr 08, 2020 at 12:02:39PM -0400, Alvaro Herrera wrote: > > On 2020-Apr-08, Justin Pryzby wrote: > > > > > This seems to be a bug in master, v12, and (probably) v11, where "FOR EACH FOR" > > > was first allowed on partition tables (86f575948). > > > > > > I thought this would work like partitioned indexes (8b08f7d48), where detaching > > > a partition makes its index non-inherited, and attaching a partition marks a > > > pre-existing, matching partition as inherited rather than creating a new one. > > > > Hmm. Let's agree to what behavior we want, and then we implement that. > > It seems to me there are two choices: > > > > 1. on detach, keep the trigger but make it independent of the trigger on > > parent. (This requires that the trigger is made dependent on the > > trigger on parent, if the table is attached as partition again; > > otherwise you'd end up with multiple copies of the trigger if you > > detach/attach multiple times). > > > > 2. on detach, remove the trigger from the partition. > > > > I think (2) is easier to implement, but (1) is the more convenient > > behavior. > > At telsasoft, we don't care (we uninherit tables before ALTERing parents to > avoid disruptive locking and to avoid worst-case disk use). I realized that I was wrong about what would be most desirable for us, for an uncommon case: Our loader INSERTs into the child table, not the parent (I think I did that to try to implement UPSERT before partitioned indexes in v11). All but the newest partitions are DETACHed when we need to promote a column. It's probably rare that we'd be inserting into a table old enough to be detached, and normally that would be ok, but if a trigger were missing, it would misbehave. In our use-case, we're creating trigger on the parent as a convenient way to maintain them on the partitions, which doesn't work if a table exists but detached.. So we'd actually prefer the behavior of indexes/constraints, where the trigger is preserved if the child is detached. I'm not requesting to do that just for our use case, which may be atypical or not a good model, but adding our one data point. -- Justin