Fix the OID cutoff in the type_sanity check for unique catalog text indexes

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Alex Guo <guo(dot)alex(dot)hengchen(at)gmail(dot)com>
Subject: Fix the OID cutoff in the type_sanity check for unique catalog text indexes
Date: 2026-12-04 08:38:44
Message-ID: A15AD99E-A6FE-4FED-B688-BCA76F36AF0C@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

One of my colleagues reported a problem they encountered while migrating a product from PG16 to PG18.

The product is a customized PG distribution. One thing it does is install an extension during initdb. This worked fine with PG16, but after migrating to PG18, the following type_sanity check consistently fails.
```
-- Look for IsCatalogTextUniqueIndexOid() omissions.

CREATE FUNCTION is_catalog_text_unique_index_oid(oid) RETURNS bool
AS :'regresslib', 'is_catalog_text_unique_index_oid'
LANGUAGE C STRICT;

SELECT indexrelid::regclass
FROM pg_index
WHERE (is_catalog_text_unique_index_oid(indexrelid) <>
(indisunique AND
indexrelid < 16384 AND
EXISTS (SELECT 1 FROM pg_attribute
WHERE attrelid = indexrelid AND atttypid = 'text'::regtype)));
```

Commit f4ece891fc2 added this check in PG18. My understanding is that its purpose is to verify that the list in IsCatalogTextUniqueIndexOid() matches the set of unique catalog indexes with a text column. In other words, no other catalog table should have a unique text index.

What puzzles me is the indexrelid < 16384 condition. IsCatalogRelationOid() uses relid < FirstUnpinnedObjectId, where FirstUnpinnedObjectId is 12000. The function’s header comment explains that this range includes the system catalogs and their indexes, as well as their TOAST tables and indexes.

In our case, the extension creates a unique index with a text column. My understanding is that it makes no difference to the buffer-lock assertion in f4ece891fc2 whether we install the extension during initdb or after starting the server, because the assertion is concerned only with catalog relations, and as IsCatalogRelationOid() checks whether the OID is less than 12000, it returns false for the index OID in either case. However, the regression query reports the index when we install the extension during initdb, because its OID falls between 12000 and 16383.

I couldn’t find any discussion of why the test uses FirstNormalObjectId (16384) here. Since IsCatalogRelationOid() uses FirstUnpinnedObjectId (12000), I propose using the same cutoff in the test.

Am I missing anything?

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachment Content-Type Size
v1-0001-Use-the-catalog-OID-cutoff-in-the-type_sanity-che.patch application/octet-stream 2.2 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2026-12-04 08:40:03 Re: several cases of float and integer mixup
Previous Message ZizhuanLiu X-MAN 2026-12-04 08:34:08 Re: examine_variable ignored CollateExpr