Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1egG4L-0004mo-28 for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jan 2018 20:30:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1egG4J-0007wR-Ko for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jan 2018 20:30:19 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1egG4J-0007w6-7n for pgsql-hackers@lists.postgresql.org; Mon, 29 Jan 2018 20:30:19 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1egG4F-00040F-40 for pgsql-hackers@postgresql.org; Mon, 29 Jan 2018 20:30:18 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id CEBF320E8E; Mon, 29 Jan 2018 15:30:13 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Mon, 29 Jan 2018 15:30:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=mpRVoL rCZAzrXZPzp3qH4ew2BMQ8mf+S2MFZ+9ApUdE=; b=k05KYTL1VuBcCeaJWnZKXI qTdUdwF9Nsi9lrI7ca5gAkL5hfn1ef+l1rJF+9ArgMTR5YKf4w2N7jvMyfawpMwN 6wGBD6RKZTWMi7Hy9m8ubS+opmsQRaKznprU4rQg7e8fPuNMx9J+BCnSIOdQNRMW 8uKPn0HvLF1RATt2RWYipfjpbgx6lNPMknL31NfkKQIe+Fq7tSTxIljXZwLOhiey QH78G7MOqoGIZPiH2AeJMBvPVq0S6C3VAV7QGhSeS7h8W1inq11Hh9FBIg8vp0JY 5FD2nW98m398HCX18QTFxoeWNnb1lDbgkZwK8LeoC18joPCK5h3R+eXl0tDU6ZeA == X-ME-Sender: Received: from april.local (c-73-13-66-39.hsd1.pa.comcast.net [73.13.66.39]) by mail.messagingengine.com (Postfix) with ESMTPA id 8582A248AF; Mon, 29 Jan 2018 15:30:13 -0500 (EST) Subject: Re: FOR EACH ROW triggers on partitioned tables To: Alvaro Herrera References: <20180123221027.2qenwwpvgplrrx3d@alvherre.pgsql> Cc: Pg Hackers , Simon Riggs From: Peter Eisentraut Organization: 2ndQuadrant Message-ID: <171cb95a-35ec-2ace-3add-a8d16279f0bf@2ndquadrant.com> Date: Mon, 29 Jan 2018 15:30:12 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <20180123221027.2qenwwpvgplrrx3d@alvherre.pgsql> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/23/18 17:10, Alvaro Herrera wrote: > The main question is this: when running the trigger function, it is > going to look as it is running in the context of the partition, not in > the context of the parent partitioned table (TG_RELNAME etc). That > seems mildly ugly: some users may be expecting that the partitioning > stuff is invisible to the rest of the system, so if you have triggers on > a regular table and later on decide to partition that table, the > behavior of triggers will change, which is maybe unexpected. Maybe this > is not really a problem, but I'm not sure and would like further > opinions. One could go either way on this, but I think reporting the actual table partition is acceptable and preferable. If you are writing a generic trigger function, maybe to dump out all columns, you want to know the physical table and its actual columns. It's easy[citation needed] to get the partition root for a given table, if the trigger code needs that. The other way around is not possible. Some other comments are reading the patch: It seems to generally follow the patterns of the partitioned indexes patch, which is good. I think WHEN clauses on partition triggers should be OK. I don't see a reason to disallow them. Similarly, transition tables should be OK. You only get the current partition to look at, of course. The function name CloneRowTriggersOnPartition() confused me. A more accurate phrasing might be CloneRowTriggersToPartition(), or maybe reword altogether. New CommandCounterIncrement() call in AttachPartitionEnsureIndexes() should be explained. Or maybe it belongs in ATExecAttachPartition() between the calls to AttachPartitionEnsureIndexes() and CloneRowTriggersOnPartition()? Prohibition against constraint triggers is unclear. The subsequent foreign-key patches mess with that further. It's not clear to me why constraint triggers shouldn't be allowed like normal triggers. Obvious missing things: documentation, pg_dump, psql updates -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services