Re: Duplicate OIDs in pg_attribute - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Duplicate OIDs in pg_attribute
Date
Msg-id 26644.981506804@sss.pgh.pa.us
Whole thread Raw
In response to Duplicate OIDs in pg_attribute  (Joe Mitchell <jmitchell@greatbridge.com>)
Responses Re: Duplicate OIDs in pg_attribute  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-hackers
Joe Mitchell <jmitchell@greatbridge.com> writes:
> I noticed that pg_attribute has rows with the same OID!

Joe previously asked me about this off-list, and I replied thus:

This appears to be due to the incredibly grotty coding used in
AppendAttributeTuples in src/backend/catalog/index.c --- rather than
building tuples in any of several sane fashions, it's using an unholy
combination of memmove and heap_modifytuple to update a single tuple
object into successive states that correspond to the rows it needs to
add to the table.  Unfortunately the OID assigned by the first
heap_insert gets carried along to the subsequent states, so the later
calls to heap_insert don't think they should assign new OIDs.

Good catch, Joe!  This bug has probably been there since the beginning
of time.  It's evidently got no serious consequences (since in reality,
OID uniqueness is not assumed for this table), but it ought to be fixed.
A quick-hack solution would be to zero out the tuple's OID before each
heap_insert, but really AppendAttributeTuples should be rewritten to
construct each tuple independently in the first place.

A quick 'glimpse' shows no other uses of heap_modifytuple except to
update an existing tuple, so evidently no one was foolish enough to
copy this technique.

I recommend putting this on the TODO for 7.2.  We can't fix it now
unless we want to force an initdb.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Re: [SQL] PL/PGSQL function with parameters
Next
From: Bruce Momjian
Date:
Subject: Re: Include files for SPI are not installed