From: Andrew Dunstan <andrew@dunslane.net>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: exclusion@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17056: Segmentation fault on altering the type of the foreign table column with a default
Date: Fri, 11 Jun 2021 17:59:07 -0400
Message-ID: <43114f0b-69d8-b040-3a46-caedcc77b9fc@dunslane.net> (raw)
In-Reply-To: <1816295.1623366663@sss.pgh.pa.us>
References: <17056-4f6f7243d322be6b@postgresql.org>
<1806408.1623363029@sss.pgh.pa.us>
<4726f847-68fb-a7fc-c5e9-7b9536046fc4@dunslane.net>
<1816295.1623366663@sss.pgh.pa.us>
On 6/10/21 7:11 PM, Tom Lane wrote:
> Andrew Dunstan <andrew@dunslane.net> writes:
>> On 6/10/21 6:10 PM, Tom Lane wrote:
>>> Hmm. The equivalent DDL on a plain table works fine, but this is
>>> crashing in the code that manipulates attmissingval. I suspect some
>>> confusion about whether a foreign table column should even *have*
>>> attmissingval. Andrew, any thoughts?
>> My initial thought would be that it should not. If the foreign table has
>> rows with missing columns then it should be up to the foreign server to
>> supply them transparently. We have no notion what the foreign semantics
>> of missing columns are.
> Yeah, that was kind of what I thought. Probably only RELKIND_RELATION
> rels should ever have attmissingval; but certainly, anything without
> local storage should not.
>
>> I can take a look at a fix tomorrow. My inclination would be simply to
>> skip setting attmissingval for foreign tables.
> Seems like in addition to that, we'll need a defense in this specific
> code to cope with the case where the foreign column already has an
> attmissingval. Or maybe, the logic to not store a new one will be enough
> to keep us from reaching this crash; but we need to be sure it is enough.
The first piece could be fairly simply accomplished by something like this
inline patch 1: src/backend/catalog/heap.c (+0/-0 lines) download inline-1.patchdiff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.cindex afa830d924..ac89efefe8 100644--- a/src/backend/catalog/heap.c+++ b/src/backend/catalog/heap.c@@ -2287,7 +2287,8 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, valuesAtt[Anum_pg_attribute_atthasdef - 1] = true;
replacesAtt[Anum_pg_attribute_atthasdef - 1] = true;
- if (add_column_mode && !attgenerated)
+ if (rel->rd_rel->relkind == RELKIND_RELATION && add_column_mode &&
+ !attgenerated)
{
expr2 = expression_planner(expr2);
estate = CreateExecutorState();
I'm guessing we want to exclude materialized views and partitioned
tables as well as things without local storage.
How to ignore something that's got into the catalog that shouldn't be
there is less clear. At the point where we fetch missing values all we
have access to is a TupleDesc.
cheers
andrew
--
Andrew Dunstan
EDB: https://www.enterprisedb.com
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-bugs@postgresql.org
Cc: andrew@dunslane.net, tgl@sss.pgh.pa.us, exclusion@gmail.com
Subject: Re: BUG #17056: Segmentation fault on altering the type of the foreign table column with a default
In-Reply-To: <43114f0b-69d8-b040-3a46-caedcc77b9fc@dunslane.net>
References: <17056-4f6f7243d322be6b@postgresql.org> <1806408.1623363029@sss.pgh.pa.us> <4726f847-68fb-a7fc-c5e9-7b9536046fc4@dunslane.net> <1816295.1623366663@sss.pgh.pa.us> <43114f0b-69d8-b040-3a46-caedcc77b9fc@dunslane.net>
* 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