Skip to content

Commit 1ef61dd

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 29d58fd commit 1ef61dd

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/backend/commands/tablecmds.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ static void MergeConstraintsIntoExisting(Relation child_rel, Relation parent_rel
303303
static void StoreCatalogInheritance(Oid relationId, List *supers,
304304
bool child_is_partition);
305305
static void StoreCatalogInheritance1(Oid relationId, Oid parentOid,
306-
int16 seqNumber, Relation inhRelation,
306+
int32 seqNumber, Relation inhRelation,
307307
bool child_is_partition);
308308
static int findAttrByName(const char *attributeName, List *schema);
309309
static void AlterIndexNamespaces(Relation classRel, Relation rel,
@@ -2352,7 +2352,7 @@ StoreCatalogInheritance(Oid relationId, List *supers,
23522352
bool child_is_partition)
23532353
{
23542354
Relation relation;
2355-
int16 seqNumber;
2355+
int32 seqNumber;
23562356
ListCell *entry;
23572357

23582358
/*
@@ -2393,7 +2393,7 @@ StoreCatalogInheritance(Oid relationId, List *supers,
23932393
*/
23942394
static void
23952395
StoreCatalogInheritance1(Oid relationId, Oid parentOid,
2396-
int16 seqNumber, Relation inhRelation,
2396+
int32 seqNumber, Relation inhRelation,
23972397
bool child_is_partition)
23982398
{
23992399
TupleDesc desc = RelationGetDescr(inhRelation);
@@ -2408,7 +2408,7 @@ StoreCatalogInheritance1(Oid relationId, Oid parentOid,
24082408
*/
24092409
values[Anum_pg_inherits_inhrelid - 1] = ObjectIdGetDatum(relationId);
24102410
values[Anum_pg_inherits_inhparent - 1] = ObjectIdGetDatum(parentOid);
2411-
values[Anum_pg_inherits_inhseqno - 1] = Int16GetDatum(seqNumber);
2411+
values[Anum_pg_inherits_inhseqno - 1] = Int32GetDatum(seqNumber);
24122412

24132413
memset(nulls, 0, sizeof(nulls));
24142414

0 commit comments

Comments
 (0)