mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Add Asserts to verify that catalog cache keys are unique and not null.
The catcache code is effectively assuming this already, so let's insist that the catalog and index are actually declared that way. Having done that, the comments in indexing.h about non-unique indexes not being used for catcaches are completely redundant not just mostly so; and we didn't have such a comment for every such index anyway. So let's get rid of them. Per discussion of whether we should identify primary keys for catalogs. We might or might not take that further step, but this change in itself will allow quicker detection of misdeclared catcaches, so it seems worth doing in any case.
This commit is contained in:
18
src/backend/utils/cache/catcache.c
vendored
18
src/backend/utils/cache/catcache.c
vendored
@ -931,7 +931,13 @@ CatalogCacheInitializeCache(CatCache *cache)
|
||||
CatalogCacheInitializeCache_DEBUG2;
|
||||
|
||||
if (cache->cc_key[i] > 0)
|
||||
keytype = tupdesc->attrs[cache->cc_key[i] - 1]->atttypid;
|
||||
{
|
||||
Form_pg_attribute attr = tupdesc->attrs[cache->cc_key[i] - 1];
|
||||
|
||||
keytype = attr->atttypid;
|
||||
/* cache key columns should always be NOT NULL */
|
||||
Assert(attr->attnotnull);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cache->cc_key[i] != ObjectIdAttributeNumber)
|
||||
@ -1003,6 +1009,16 @@ InitCatCachePhase2(CatCache *cache, bool touch_index)
|
||||
*/
|
||||
LockRelationOid(cache->cc_reloid, AccessShareLock);
|
||||
idesc = index_open(cache->cc_indexoid, AccessShareLock);
|
||||
|
||||
/*
|
||||
* While we've got the index open, let's check that it's unique (and
|
||||
* not just deferrable-unique, thank you very much). This is just to
|
||||
* catch thinkos in definitions of new catcaches, so we don't worry
|
||||
* about the pg_am indexes not getting tested.
|
||||
*/
|
||||
Assert(idesc->rd_index->indisunique &&
|
||||
idesc->rd_index->indimmediate);
|
||||
|
||||
index_close(idesc, AccessShareLock);
|
||||
UnlockRelationOid(cache->cc_reloid, AccessShareLock);
|
||||
}
|
||||
|
Reference in New Issue
Block a user