Skip to content

Commit 9a215fb

Browse files
committed
Fix StoreCatalogInheritance1 to use 32bit inhseqno
For no apparent reason, this function was using a 16bit-wide inhseqno value, rather than the correct 32 bit width which is what is stored in the pg_inherits catalog. This becomes evident if you try to create a table with more than 65535 parents, because this error appears: ERROR: duplicate key value violates unique constraint «pg_inherits_relid_seqno_index» DETAIL: Key (inhrelid, inhseqno)=(329371, 0) already exists. Needless to say, having so many parents is an uncommon situations, which explains why this error has never been reported despite being having been introduced with the Postgres95 1.01 sources in commit d31084e: https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/commands/creatinh.c;hb=d31084e9d111#l349 Backpatch all the way back. David Rowley noticed this while reviewing a patch of mine. Discussion: https://postgr.es/m/CAKJS1f8Dn7swSEhOWwzZzssW7747YB=2Hi+T7uGud40dur69-g@mail.gmail.com
1 parent a0f5890 commit 9a215fb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/backend/commands/tablecmds.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ static void MergeAttributesIntoExisting(Relation child_rel, Relation parent_rel)
269269
static void MergeConstraintsIntoExisting(Relation child_rel, Relation parent_rel);
270270
static void StoreCatalogInheritance(Oid relationId, List *supers);
271271
static void StoreCatalogInheritance1(Oid relationId, Oid parentOid,
272-
int16 seqNumber, Relation inhRelation);
272+
int32 seqNumber, Relation inhRelation);
273273
static int findAttrByName(const char *attributeName, List *schema);
274274
static void AlterIndexNamespaces(Relation classRel, Relation rel,
275275
Oid oldNspOid, Oid newNspOid, ObjectAddresses *objsMoved);
@@ -1900,7 +1900,7 @@ static void
19001900
StoreCatalogInheritance(Oid relationId, List *supers)
19011901
{
19021902
Relation relation;
1903-
int16 seqNumber;
1903+
int32 seqNumber;
19041904
ListCell *entry;
19051905

19061906
/*
@@ -1940,7 +1940,7 @@ StoreCatalogInheritance(Oid relationId, List *supers)
19401940
*/
19411941
static void
19421942
StoreCatalogInheritance1(Oid relationId, Oid parentOid,
1943-
int16 seqNumber, Relation inhRelation)
1943+
int32 seqNumber, Relation inhRelation)
19441944
{
19451945
TupleDesc desc = RelationGetDescr(inhRelation);
19461946
Datum values[Natts_pg_inherits];
@@ -1954,7 +1954,7 @@ StoreCatalogInheritance1(Oid relationId, Oid parentOid,
19541954
*/
19551955
values[Anum_pg_inherits_inhrelid - 1] = ObjectIdGetDatum(relationId);
19561956
values[Anum_pg_inherits_inhparent - 1] = ObjectIdGetDatum(parentOid);
1957-
values[Anum_pg_inherits_inhseqno - 1] = Int16GetDatum(seqNumber);
1957+
values[Anum_pg_inherits_inhseqno - 1] = Int32GetDatum(seqNumber);
19581958

19591959
memset(nulls, 0, sizeof(nulls));
19601960

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy