Thread: Unused(?) field Form_pg_sequence.sequence_name, not updated by seq rename

Unused(?) field Form_pg_sequence.sequence_name, not updated by seq rename

From
Craig Ringer
Date:
Hi all

Does anyone know why Form_pg_sequence has a field sequence_name that duplicates the sequence's name from pg_class ?

It's assigned when the sequence is created by copying it from pg_class. It isn't subsequently referenced anywhere as far as I can see. It isn't updated by ALTER SEQUENCE ... RENAME TO, so it isn't necessarily actually the correct sequence name either.

It gets written as part of the Form_pg_sequence each time we write a sequence advance to WAL, but just seems to be a waste of space.

Am I missing something obvious or should it just be removed? Or perhaps replaced with the sequence's Oid in pg_class, since that'd be quite handy for logical decoding of sequences.

If we need to keep it for some reason then it should probably be updated by ALTER SEQUENCE.


--
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services
Craig Ringer <craig@2ndquadrant.com> writes:
> Does anyone know why Form_pg_sequence has a field sequence_name that
> duplicates the sequence's name from pg_class ?

It's historical, for sure.  We won't be removing it in the foreseeable
future because of on-disk-compatibility issues.  But you might want to
read the pghackers archives, five or ten years back, where we speculated
about redoing sequences to combine them all into one system catalog
(ie, store one row per sequence not one relation per).  Aside from
application compatibility issues, the stumbling block seemed to be how to
separate transactional from nontransactional updates.  That particular
problem is also why ALTER SEQUENCE RENAME can't update the sequence's copy
of the relation name: the wrong things happen if you roll back.
        regards, tom lane



Re: Unused(?) field Form_pg_sequence.sequence_name, not updated by seq rename

From
Michael Paquier
Date:
On Tue, Dec 15, 2015 at 2:05 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Craig Ringer <craig@2ndquadrant.com> writes:
>> Does anyone know why Form_pg_sequence has a field sequence_name that
>> duplicates the sequence's name from pg_class ?
>
> It's historical, for sure.  We won't be removing it in the foreseeable
> future because of on-disk-compatibility issues.  But you might want to
> read the pghackers archives, five or ten years back, where we speculated
> about redoing sequences to combine them all into one system catalog
> (ie, store one row per sequence not one relation per).  Aside from
> application compatibility issues, the stumbling block seemed to be how to
> separate transactional from nontransactional updates.  That particular
> problem is also why ALTER SEQUENCE RENAME can't update the sequence's copy
> of the relation name: the wrong things happen if you roll back.

That's a little bit older than 5/10 years visibly, see commit 7415105.
But yes as the sequence data is stored as a single always-visible
tuple on its relfilenode, there is no way to remove it without
breaking on-disk compatibility, but moving back in time, it would have
been surely possible to rely on the sequence OID instead.
-- 
Michael



Re: Unused(?) field Form_pg_sequence.sequence_name, not updated by seq rename

From
Simon Riggs
Date:
On 15 December 2015 at 04:40, Craig Ringer <craig@2ndquadrant.com> wrote:
 
It gets written as part of the Form_pg_sequence each time we write a sequence advance to WAL, but just seems to be a waste of space.

Agreed
 
Am I missing something obvious or should it just be removed? Or perhaps replaced with the sequence's Oid in pg_class, since that'd be quite handy for logical decoding of sequences.

If the name is wrong then probably other fields are wrong also when we do ALTER SEQUENCE? 

We should add the fields you need, but don't alter anything in Form_pg_sequence.

--
Simon Riggs                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services