Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e20cw-0002cq-Um for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Oct 2017 19:55:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e20cw-0007Av-Aw for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Oct 2017 19:55:42 +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 1e20cB-0004Wv-Jk for pgsql-bugs@postgresql.org; Tue, 10 Oct 2017 19:54:55 +0000 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1e20c7-0003Tn-KY for pgsql-bugs@postgresql.org; Tue, 10 Oct 2017 19:54:54 +0000 Received: by mail-wm0-x232.google.com with SMTP id u138so138664wmu.4 for ; Tue, 10 Oct 2017 12:54:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=3LGQ2W/zv9D7WTtp33ZuwCBQemwomyRCqN1A7WLcGuY=; b=WQh39GMGzVV3ZxrfFUOc63WzLFlnI/OwyG/enG9YMKjKCSWdM2me3rHoKrZrP3FqrC h6ILSkQSq2Ni172SnyEtY5orMjnHnpJDWhjZk4ICFaRwmT+f3VthTpmzTRUhzteQitgu eVLy9rg1LzP+rmc7XDBJ1UGxgA4iFLiEzEfb1NDkeJXF5Us4CRqKQjscJSxpY7m9W4ML YvVOE5sGy3FeD/xShgz2cewFirYRoP6LJXUIp78CvGsZYqVw1h9V2hb5wkW1qO9o+rWg Eqn0qnPtHqmgN0n9MrG7sdZovBSdFbAcrwos6eDYnaErz5onz/L3NfTJdISiuqw7zjRM 2j1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=3LGQ2W/zv9D7WTtp33ZuwCBQemwomyRCqN1A7WLcGuY=; b=c0TJqWTakvLLMnFFcANjQPMlt1s6GFeMT/7fImBjtyRV4Q3esas0zhUZzqtBU45JU3 ClItQZMSFZvlqa9ILxKVe0ug55LO59iM+W1nzZwEQh3G9bfGiGPnCnF7miPurOeYXReh gfEGhTPh/FCJTJ1Psc9lEDXFcaN1J0SUVwF5dm2LlaG1RosSmFT3rsr6kwkkAv/lQu4B mBjKrFCDbYcZiV1dnXpYA0v9feOrh1JUc5+lReIZ9ttZZ6ydS2ERpCrXL2JZjFgpglC2 JrzcJDLqWJlUWVoedoGuXEwNMZyu0PZvCynnb7nlXm5mKIXLtrdbj4kKo+ux+K1rIBOG Bgqw== X-Gm-Message-State: AMCzsaXIs0l8XRwwXUDq0JIMTMi8q/Wxn/v26qWYd0SgjtSH5+sbSVSr +4GrXiw1ZQYv4fDakUmByLjcA6Dsjqw1eyzB04QUPAdFm+Qw06mc/3redP/LptGJfJDHcAER7WT fsmatgrCwaEefTjeDmdrXAHwQ13+rARsMwO1PdoR4Asg9QCBKM2J/KYaPH5P9AnVVN/KzZVtEr+ l5UbyFT9k= X-Google-Smtp-Source: AOwi7QAylnRA/LPew0n4asS6WyaCwMNqPVZiqbOCSibZvURl2nfA6m2NM7CxznCLVIM6z+ojtoWRxg== X-Received: by 10.223.199.15 with SMTP id k15mr15048197wrg.111.1507665290495; Tue, 10 Oct 2017 12:54:50 -0700 (PDT) Received: from [192.168.0.105] (150.123.broadband11.iol.cz. [90.178.123.150]) by smtp.gmail.com with ESMTPSA id v10sm8776877wrb.92.2017.10.10.12.54.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Oct 2017 12:54:49 -0700 (PDT) Subject: Re: 10.0: Logical replication doesn't execute BEFORE UPDATE OF trigger To: Aleksander Alekseev Cc: Masahiko Sawada , PostgreSQL Hackers , pgsql-bugs References: <20171009141341.GA16999@e733.localdomain> <20171010152250.GA30140@e733.localdomain> From: Petr Jelinek Message-ID: <587161d8-1175-abc7-42f5-86b9bea2bf2b@2ndquadrant.com> Date: Tue, 10 Oct 2017 21:54:48 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20171010152250.GA30140@e733.localdomain> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 10/10/17 17:22, Aleksander Alekseev wrote: > Hi Petr, > >> let me start by saying that my view is that this is simply a >> documentation bug. Meaning that I didn't document that it does not work, >> but I also never intended it to work. Main reason is that we can't >> support the semantics of "UPDATE OF" correctly (see bellow). And I think >> it's better to not support something at all rather than making it behave >> differently in different cases. >> >> Now about the proposed patch, I don't think this is correct way to >> support this as it will only work when either PRIMARY KEY column was >> changed or when REPLICA IDENTITY is set to FULL for the table. And even >> then it will have very different semantics from how it works when the >> row is updated by SQL statement (all non-toasted columns will be >> reported as changed regardless of actually being changed or not). >> >> The more proper way to do this would be to run data comparison of the >> new tuple and the existing tuple values which a) will have different >> behavior than normal "UPDATE OF" triggers have because we still can't >> tell what columns were mentioned in the original query and b) will not >> exactly help performance (and perhaps c) one can write the trigger to >> behave this way already without impacting all other use-cases). > > I personally think that solution proposed by Masahiko is much better > than current behavior. Well the proposed patch adds inconsistent behavior - if in your test you'd change the trigger to be UPDATE OF v instead of k and updated v, it would still not be triggered even with this patch. That's IMHO worse than current behavior which at least consistently doesn't work. > We could document current limitations you've > mentioned and probably add a corresponding warning during execution of > ALTER TABLE ... ENABLE REPLICA TRIGGER. I don't insist on this > particular approach though. > > What I really don't like is that PostgreSQL allows to create something > that supposedly should work but in fact doesn't. Such behavior is > obviously a bug. So as an alternative we could just return an error in > response to ALTER TABLE ... ENABLE REPLICA TRIGGER query for triggers > that we know will never be executed. > Well ENABLE REPLICA is not specific to builtin logical replication though. It only depends on the value of session_replication_role GUC. Any session can set that and if that session executes SQL the UPDATE OF triggers will work as expected. It's similar situation to statement triggers IMHO, we allow ENABLE REPLICA statement triggers but they are not triggered by logical replication because there is no statement. And given that UPDATE OF also depends on statement to work as expected (it's specified to be triggered for columns listed in the statement, not for what has been actually changed by the execution) I don't really see the difference between this and statement triggers except that statement trigger behavior is documented. I understand that it's somewhat confusing and I am not saying it's ideal, but I don't see any other behavior that would work for what your test tries to do and still be consistent with rest of the system. -- Petr Jelinek http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs