Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c2m2D-0007zG-9a for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Nov 2016 21:28:25 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1c2m2C-00067p-1x for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Nov 2016 21:28:24 +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 1c2m2B-00067i-CD for pgsql-hackers@postgresql.org; Fri, 04 Nov 2016 21:28:23 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1c2m24-0003fl-I9 for pgsql-hackers@postgresql.org; Fri, 04 Nov 2016 21:28:22 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id uA4LSAP8016809; Fri, 4 Nov 2016 17:28:10 -0400 From: Tom Lane To: Michael Paquier cc: Jim Nasby , Pg Hackers , Karl Lehenbauer Subject: Re: Fix bug in handling of dropped columns in pltcl triggers In-reply-to: References: Comments: In-reply-to Michael Paquier message dated "Tue, 01 Nov 2016 22:29:59 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <16807.1478294889.1@sss.pgh.pa.us> Date: Fri, 04 Nov 2016 17:28:09 -0400 Message-ID: <16808.1478294889@sss.pgh.pa.us> X-Pg-Spam-Score: -4.2 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Michael Paquier writes: > On Tue, Nov 1, 2016 at 4:17 AM, Jim Nasby wrote: >> While reviewing code coverage in pltcl, I uncovered a bug in trigger >> function return handling. If you returned the munged name of a dropped >> column, that would silently be ignored. It would be unusual to hit this, >> since dropped columns end up with names like ".......pg.dropped.2.......", >> but since that's still a legitimate name for a column silently ignoring it >> seems rather bogus. > It seems to me that this patch breaks $TG_relatts and what existing > applications would except from it: I'm not sure how it would do that. What's being changed here is the code for processing the returned tuple; it doesn't change what is put into $TG_relatts. Also, per the manual, > (Empty list > elements also appear in the positions of columns that have been > dropped, so that the attribute numbering is correct for columns > to their right.) If the trigger function were blindly using that information without any exception for dropped columns, then what it would provide here as the column name is an empty string, not ".......pg.dropped.2.......", so that it would get a failure anyway. This change wouldn't affect that. So I'm inclined to agree that we should change this, but I think Jim's patch doesn't go far enough: what we really ought to do is change SPI_fnumber itself to reject matches to dropped columns. I just did a survey of callers, and only a small minority of them are explicitly testing for a match to a dropped column, but it doesn't look to me like any of the rest are really prepared to do something reasonable with one. I find it impossible to think of a situation where a caller would want to treat a match to a dropped column as valid. My proposal therefore is for SPI_fnumber to ignore (not match to) dropped columns, and to remove any caller-side attisdropped tests that thereby become redundant. It's possible that it'd make sense for pltcl_trigger_handler to ignore empty-string column names in the returned list, so that the behavior with stupid trigger functions would be a bit more forgiving; but that is more or less independent of this patch. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers