Skip to content

Commit f6a8454

Browse files
committed
Add sanity asserts for index OID and attnums during cache init
There was already a check on the relation OID, but not its index OID and the attributes that can be used during the syscache lookups. The two assertions added by this commit are cheap, and actually useful for developers to fasten the detection of incorrect data in a new entry added in the syscache list, as these assertions are triggered during the initial cache loading (initdb, or just backend startup), not requiring a syscache that uses the new entry. While on it, the relation OID check is switched to use OidIsValid(). Author: Aleksander Alekseev Reviewed-by: Dagfinn Ilmari Mannsåker, Zhang Mingli, Michael Paquier Discussion: https://postgr.es/m/CAJ7c6TOjUTJ0jxvWY6oJeP2-840OF8ch7qscZQsuVuotXTOS_g@mail.gmail.com
1 parent 31de7e6 commit f6a8454

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/backend/utils/cache/catcache.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,10 @@ InitCatCache(int id,
825825
cp->cc_nbuckets = nbuckets;
826826
cp->cc_nkeys = nkeys;
827827
for (i = 0; i < nkeys; ++i)
828+
{
829+
Assert(AttributeNumberIsValid(key[i]));
828830
cp->cc_keyno[i] = key[i];
831+
}
829832

830833
/*
831834
* new cache is initialized as far as we can go for now. print some

src/backend/utils/cache/syscache.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,9 @@ InitCatalogCache(void)
720720
* Assert that every enumeration value defined in syscache.h has been
721721
* populated in the cacheinfo array.
722722
*/
723-
Assert(cacheinfo[cacheId].reloid != 0);
723+
Assert(OidIsValid(cacheinfo[cacheId].reloid));
724+
Assert(OidIsValid(cacheinfo[cacheId].indoid));
725+
/* .nbuckets and .key[] are checked by InitCatCache() */
724726

725727
SysCache[cacheId] = InitCatCache(cacheId,
726728
cacheinfo[cacheId].reloid,

0 commit comments

Comments
 (0)