Skip to content

Commit 1284d18

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 2c1c4b0 commit 1284d18

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
@@ -270,7 +270,7 @@ static void MergeAttributesIntoExisting(Relation child_rel, Relation parent_rel)
270270
static void MergeConstraintsIntoExisting(Relation child_rel, Relation parent_rel);
271271
static void StoreCatalogInheritance(Oid relationId, List *supers);
272272
static void StoreCatalogInheritance1(Oid relationId, Oid parentOid,
273-
int16 seqNumber, Relation inhRelation);
273+
int32 seqNumber, Relation inhRelation);
274274
static int findAttrByName(const char *attributeName, List *schema);
275275
static void AlterIndexNamespaces(Relation classRel, Relation rel,
276276
Oid oldNspOid, Oid newNspOid, ObjectAddresses *objsMoved);
@@ -1926,7 +1926,7 @@ static void
19261926
StoreCatalogInheritance(Oid relationId, List *supers)
19271927
{
19281928
Relation relation;
1929-
int16 seqNumber;
1929+
int32 seqNumber;
19301930
ListCell *entry;
19311931

19321932
/*
@@ -1966,7 +1966,7 @@ StoreCatalogInheritance(Oid relationId, List *supers)
19661966
*/
19671967
static void
19681968
StoreCatalogInheritance1(Oid relationId, Oid parentOid,
1969-
int16 seqNumber, Relation inhRelation)
1969+
int32 seqNumber, Relation inhRelation)
19701970
{
19711971
TupleDesc desc = RelationGetDescr(inhRelation);
19721972
Datum values[Natts_pg_inherits];
@@ -1980,7 +1980,7 @@ StoreCatalogInheritance1(Oid relationId, Oid parentOid,
19801980
*/
19811981
values[Anum_pg_inherits_inhrelid - 1] = ObjectIdGetDatum(relationId);
19821982
values[Anum_pg_inherits_inhparent - 1] = ObjectIdGetDatum(parentOid);
1983-
values[Anum_pg_inherits_inhseqno - 1] = Int16GetDatum(seqNumber);
1983+
values[Anum_pg_inherits_inhseqno - 1] = Int32GetDatum(seqNumber);
19841984

19851985
memset(nulls, 0, sizeof(nulls));
19861986

0 commit comments

Comments
 (0)