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 1emmeI-0002HO-5c for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Feb 2018 20:30:26 +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 1emmeH-000731-2k for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Feb 2018 20:30:25 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1emmeG-00072f-OU for pgsql-hackers@lists.postgresql.org; Fri, 16 Feb 2018 20:30:24 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1emme9-00021C-Fd for pgsql-hackers@postgresql.org; Fri, 16 Feb 2018 20:30:23 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 8321120C5C; Fri, 16 Feb 2018 15:30:16 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Fri, 16 Feb 2018 15:30:16 -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=fm2; bh=bM5cqW sxT/g+GjykjnZjXJIAu/bQSZOoMdiFPoIYjg8=; b=WjPxr1CekE9jiyIcH9Tfjt 42W3ShXV+tp+d0/pb2haZhGw7OJpgdLJHN/9sckH6X39+Mj4l1mjRHgh1lBwYsQK DLdfqd3r1Kmhx/U7+5RnsXthz3fwMqVKkmM8xGzI14TOtQOzWebjJByhenaKBxmK 3oPph1rnfOMmfHSFMKpqVMH3u+lSgjSEhmtfjWrkJcLEE4uAtsc6+zrJuQvNXIyO 6nX/fO+Gv//jq3cfJ1Fk00O4zMFbFjUNvYxwH+UP9wQ4Znj9SiBBmlx/xGDzn/1m +goQjyGdjsSlfrbYnmEY4G5VzEbS+G0OpEIFkWm5cFYy2l+/oQcs9PWuxYecw59w == 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 2DB892469C; Fri, 16 Feb 2018 15:30:16 -0500 (EST) Subject: Re: FOR EACH ROW triggers on partitioned tables To: Alvaro Herrera , Amit Langote References: <20180215215525.3anqmydfi6pfrmvf@alvherre.pgsql> Cc: Robert Haas , Pg Hackers , Simon Riggs From: Peter Eisentraut Organization: 2ndQuadrant Message-ID: <812dce79-717e-6905-afee-8c3cb27aab1a@2ndquadrant.com> Date: Fri, 16 Feb 2018 15:30:15 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180215215525.3anqmydfi6pfrmvf@alvherre.pgsql> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2/15/18 16:55, Alvaro Herrera wrote: > Amit Langote wrote: >> Do you mean to fire these triggers only if the parent table (not a child >> table/partition) is addressed in the DML, right? If the table directly >> addressed in the DML is a partition whose parent has a row-level trigger, >> then that trigger should not get fired I suppose. > > No, I think that would be strange and cause data inconsistencies. > Inserting directly into the partition is seen as a performance > optimization (compared to inserted into the partitioned table), so we > don't get to skip firing the triggers defined on the parent because the > behavior would become different. In other words, the performance > optimization breaks the database. > > Example: suppose the trigger is used to maintain an audit record trail. Although this situation could probably be addressed by not giving permission to write directly into the partitions, I can't think of an example where one would want a trigger that is only fired when writing into the partition root rather than into the partition directly. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services