pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael Paquier <michael.paquier@gmail.com>
Cc: Jim Nasby <Jim.Nasby@bluetreble.com>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>
Cc: Karl Lehenbauer <karl@flightaware.com>
Subject: Re: Fix bug in handling of dropped columns in pltcl triggers
Date: Fri, 04 Nov 2016 17:28:09 -0400
Message-ID: <16808.1478294889@sss.pgh.pa.us> (raw)
In-Reply-To: <CAB7nPqTggoAOxkYWQrzpZwdiwCMXGWGQ06-6X6uNHo85eFAXGw@mail.gmail.com>
References: <b2de8258-c4c0-1cb8-7b97-e8538e5c975c@BlueTreble.com>
	<CAB7nPqTggoAOxkYWQrzpZwdiwCMXGWGQ06-6X6uNHo85eFAXGw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

Michael Paquier <michael.paquier@gmail.com> writes:
> On Tue, Nov 1, 2016 at 4:17 AM, Jim Nasby <Jim.Nasby@bluetreble.com> 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



view thread (6+ messages)  latest in thread

Message-ID: <16808.1478294889@sss.pgh.pa.us>
Permalink:  ../16808.1478294889@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/16808.1478294889@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, michael.paquier@gmail.com, Jim.Nasby@bluetreble.com, karl@flightaware.com
  Subject: Re: Fix bug in handling of dropped columns in pltcl triggers
  In-Reply-To: <16808.1478294889@sss.pgh.pa.us>
  References: <b2de8258-c4c0-1cb8-7b97-e8538e5c975c@BlueTreble.com> <CAB7nPqTggoAOxkYWQrzpZwdiwCMXGWGQ06-6X6uNHo85eFAXGw@mail.gmail.com> <16808.1478294889@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox