Re: ALTER TABLE ADD COLUMN fast default

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>, Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: ALTER TABLE ADD COLUMN fast default
Date: 2021-04-04 00:41:24
Message-ID: 87pmzaq4gx.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

[warning, reviving a thread from 2018]

>>>>> "Andrew" == Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com> writes:

> On Wed, Feb 21, 2018 at 7:48 PM, Andres Freund <andres(at)anarazel(dot)de> wrote:
>> Hi,

Andrew> Comments interspersed.

>>> @@ -4059,10 +4142,6 @@ AttrDefaultFetch(Relation relation)
>>>
>>> systable_endscan(adscan);
>>> heap_close(adrel, AccessShareLock);
>>> -
>>> - if (found != ndef)
>>> - elog(WARNING, "%d attrdef record(s) missing for rel %s",
>>> - ndef - found, RelationGetRelationName(relation));
>>> }
>>
>> Hm, it's not obvious why this is a good thing?

I didn't find an answer to this in the thread archive, and the above
change apparently did make it into the final patch.

I just got through diagnosing a SEGV crash with someone on IRC, and the
cause turned out to be exactly this - a table had (for some reason we
could not determine within the available resources) lost its pg_attrdef
record for the one column it had with a default (which was a serial
column, so none of the fast-default code is actually implicated). Any
attempt to alter the table resulted in a crash in equalTupleDesc on this
line:

if (strcmp(defval1->adbin, defval2->adbin) != 0)

due to trying to compare adbin values which were NULL pointers.

So, questions: why was the check removed in the first place?

(Why was it previously only a warning when it causes a crash further
down the line on any alteration?)

Does equalTupleDesc need to be more defensive about this, or does the
above check need to be reinstated?

(The immediate issue was fixed by "update pg_attribute set
atthasdef=false ..." for the offending attribute and then adding it back
with ALTER TABLE, which seems to have cured the crash.)

--
Andrew (irc:RhodiumToad)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2021-04-04 01:20:14 Re: ModifyTable overheads in generic plans
Previous Message Andres Freund 2021-04-03 23:29:42 Allowing dsm allocations in single user mode