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 1evOTt-0005ig-R2 for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Mar 2018 14:31:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1evOTs-0000BX-Gs for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Mar 2018 14:31:16 +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.89) (envelope-from ) id 1evOTs-0000BN-9j for pgsql-hackers@lists.postgresql.org; Mon, 12 Mar 2018 14:31:16 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1evOTo-0008KL-Nc for pgsql-hackers@postgresql.org; Mon, 12 Mar 2018 14:31:15 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 70AC320EE8; Mon, 12 Mar 2018 10:31:10 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute7.internal (MEProxy); Mon, 12 Mar 2018 10:31:10 -0400 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=TwiqHC 05Ozez7vuew6hYy8EqYwTBQW/unpvcFA07WNg=; b=BXeVJDaczzJnYkHieYj+w1 jlSdiy6hmfVuONbeh0W5Zx6ifk91HjeX/4t6EYLyE/rt7YWYcNS8eZWBKwoZTNhR 8aMXhwnwjkhAw4y8VyKrzX6RXw15AplKB5pnLBHWmeH/e3REUJis7P4Axn8AW2vE Mk08zRC8v5n2sCW0tyFbPouIrxeYkECKFur7cqb96RpKYgPKYrazNZ5K0mTU9Pbk 3FKwbX+s/Zc1PwTCey8PCv2xOqWeUrXo36QsyPcH+ngfLDzbmntiMcEQPuuRn+Dp P1UsQSvAIU5XZ0RAXovQ6fAjhJ8HlwaqjvUbKs2PuY1fybXamUP2D8oMp8URwbxA == 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 02B1C7E0F0; Mon, 12 Mar 2018 10:31:09 -0400 (EDT) Subject: Re: FOR EACH ROW triggers on partitioned tables To: Alvaro Herrera , Thomas Munro References: <20180309204143.n4xwudjl5oawf55p@alvherre.pgsql> Cc: Robert Haas , Pg Hackers , Simon Riggs From: Peter Eisentraut Organization: 2ndQuadrant Message-ID: <223101be-9f90-6965-87a5-a5d44dc66597@2ndquadrant.com> Date: Mon, 12 Mar 2018 10:31:08 -0400 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: <20180309204143.n4xwudjl5oawf55p@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 3/9/18 15:41, Alvaro Herrera wrote: >> One thing I'd like to add before claiming this committable (backend- >> side) is enabling constraint triggers. AFAICT that requires a bit of >> additional logic, but it shouldn't be too terrible. This would allow >> for deferrable unique constraints, for example. > > v7 supports constraint triggers. I added an example using a UNIQUE > DEFERRABLE constraint, and another one using plain CREATE CONSTRAINT TRIGGER. > It's neat to see that the WHEN clause is executed at the time of the > operation, and the trigger action is deferred (or not) till COMMIT time. I'm not sure why you have the CommandCounterIncrement() changes in separate patches. It looks like there are some test cases that are essentially duplicates, e.g., +create trigger failed before insert or update or delete on parted_trig + for each row execute procedure trigger_nothing(); +create trigger trig_ins_before_1 before insert on parted_stmt_trig + for each row execute procedure trigger_notice(); Perhaps the latter is supposed to be testing statement triggers instead? Some documentation updates are needed, at least in catalogs.sgml and CREATE TRIGGER reference page. The argument names of CreateTrigger() are slightly different in the .h and .c files. I'm wondering about deferrable unique constraint triggers. In index.c, the CreateTrigger() call doesn't pass any parent trigger OID. How is this meant to work? I mean, it does work, it seems. Some comments maybe. In CloneRowTriggersToPartition(), for this piece + /* + * We only clone a) FOR EACH ROW triggers b) timed AFTER events, c) + * that are not constraint triggers. + */ + if (!TRIGGER_FOR_ROW(trigForm->tgtype) || + !TRIGGER_FOR_AFTER(trigForm->tgtype) || + OidIsValid(trigForm->tgconstraint)) + continue; I would rather have some elog(ERROR)'s if it finds triggers it can't support instead of silently skipping them. What is the story with transition tables? Why are they not supported? I don't understand this comment in CreateTrigger(): + /* + * Disallow use of transition tables. If this partitioned table + * has any partitions, the error would occur below; but if it + * doesn't then we would only hit that code when the first CREATE + * TABLE ... PARTITION OF is executed, which is too late. Check + * early to avoid the problem. + */ Earlier in the thread, others have indicated that transition tables should work. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services