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: v1-0001-Use-the-catalog-OID-cutoff-in-the-type_sanity-che.patch
Description: Binary data

Reply via email to