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.92) (envelope-from ) id 1jBjrc-0001ir-SW for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Mar 2020 18:44:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jBjrb-0007NL-Iv for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Mar 2020 18:44:23 +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 1jBjra-0007ND-Ft for pgsql-hackers@lists.postgresql.org; Tue, 10 Mar 2020 18:44:23 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jBjrX-0002Oo-QP for pgsql-hackers@lists.postgresql.org; Tue, 10 Mar 2020 18:44:21 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 544E421B74; Tue, 10 Mar 2020 14:44:18 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Tue, 10 Mar 2020 14:44:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=RzCRgZaX52iYzV5ASGNDi7s8yxhk/wwdb58VpPyFN po=; b=kfFrppvW1W9yOkL1WiDvRubK2FnxV3E7RaiDFmNBM9FEpND5Ko8vhzUjR z5N3tg5bMpHZoA9p2b2HQtXv26vLA2FN6H9xlgTAtsLlBMELaGeTfbRIjL5HRo1n epq+1khnBaDVTXNMFubQz0F27OOm8XRXzG2U+2NK5bcD0q6GAhxotMbugLXdaVM9 OnpB/cJ2oZu5RnpmD0YgA2fpgvPXAPz/u1i3clSGZylF2QMhhmTnNZdmWMn3+kwS eWGUWbQtMCioBYX4GkQHRF+60IEY56lLNz8NOFujzeFOn4tQQkSLmZs29NMTLzgz ExQF7EJ3GlgUlcJ7wyXCLuMgNcH+Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedruddvtddguddtlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefuvfhfhfhokffffgggjggtgfesthejredttdefheenucfhrhhomheprfgv thgvrhcugfhishgvnhhtrhgruhhtuceophgvthgvrhdrvghishgvnhhtrhgruhhtsedvnh guqhhurggurhgrnhhtrdgtohhmqeenucffohhmrghinhepvdhnughquhgrughrrghnthdr tghomhenucfkphepleefrddvgedvrddvudefrddvgedunecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomhepphgvthgvrhdrvghishgvnhhtrhgruhht sedvnhguqhhurggurhgrnhhtrdgtohhm X-ME-Proxy: Received: from april.pezone.net (p5df2d5f1.dip0.t-ipconnect.de [93.242.213.241]) by mail.messagingengine.com (Postfix) with ESMTPA id 4F21A3061856; Tue, 10 Mar 2020 14:44:17 -0400 (EDT) Subject: Re: BEFORE ROW triggers for partitioned tables To: Alvaro Herrera , Pg Hackers References: <20200227165158.GA2071@alvherre.pgsql> From: Peter Eisentraut Organization: 2ndQuadrant Message-ID: <2421844e-0798-5c2a-24b8-d061dafe2939@2ndquadrant.com> Date: Tue, 10 Mar 2020 19:44:15 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20200227165158.GA2071@alvherre.pgsql> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-02-27 17:51, Alvaro Herrera wrote: > Enabling BEFORE triggers FOR EACH ROW in partitioned tables is very easy > -- just remove the check against them. With that, they work fine. This looks good to me in principle. It's a useful thing to support. > 1. Just let it be. If the user does something silly, it's their problem > if they get an ugly error message. > > 2. If the partition keys are changed, raise an error. The trigger is > allowed to change everything but those columns. Then there's no > conflict, and it allows desirable use cases. > > 3. Allow the partition keys to change, as long as the tuple ends up in > the same partition. This is the same as (1) except the error message is > nicer. > > The attached patch implements (2). That seems alright to me. > * The new function I added, ReportTriggerPartkeyChange(), contains one > serious bug (namely: it doesn't map attribute numbers properly if > partitions are differently defined). Also, it has a performance issue, > namely that we do heap_getattr() potentially repeatedly -- maybe it'd be > better to "slotify" the tuple prior to doing the checks. The attribute ordering issue obviously needs to be addressed, but the performance issue is probably not so important. How many levels of partitioning are we expecting? > Another > possible controversial point is that its location in commands/trigger.c > isn't great. (Frankly, I don't understand why the executor trigger > firing functions are in commands/ at all.) yeah ... -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services