Re-pgindent catcache.c after previous commit.

Discussion: https://postgr.es/m/1393953.1698353013@sss.pgh.pa.us
Discussion: https://postgr.es/m/CAGjhLkOoBEC9mLsnB42d3CO1vcMx71MLSEuigeABbQ8oRdA6gw@mail.gmail.com
This commit is contained in:
Tom Lane 2024-01-13 13:54:11 -05:00
parent 98e03f9574
commit 475b3ea3c0
1 changed files with 98 additions and 98 deletions

View File

@ -1367,34 +1367,34 @@ SearchCatCacheMiss(CatCache *cache,
cur_skey[2].sk_argument = v3; cur_skey[2].sk_argument = v3;
cur_skey[3].sk_argument = v4; cur_skey[3].sk_argument = v4;
scandesc = systable_beginscan(relation, scandesc = systable_beginscan(relation,
cache->cc_indexoid, cache->cc_indexoid,
IndexScanOK(cache, cur_skey), IndexScanOK(cache, cur_skey),
NULL, NULL,
nkeys, nkeys,
cur_skey); cur_skey);
ct = NULL; ct = NULL;
stale = false; stale = false;
while (HeapTupleIsValid(ntp = systable_getnext(scandesc))) while (HeapTupleIsValid(ntp = systable_getnext(scandesc)))
{
ct = CatalogCacheCreateEntry(cache, ntp, scandesc, NULL,
hashValue, hashIndex);
/* upon failure, we must start the scan over */
if (ct == NULL)
{ {
stale = true; ct = CatalogCacheCreateEntry(cache, ntp, scandesc, NULL,
break; hashValue, hashIndex);
/* upon failure, we must start the scan over */
if (ct == NULL)
{
stale = true;
break;
}
/* immediately set the refcount to 1 */
ResourceOwnerEnlargeCatCacheRefs(CurrentResourceOwner);
ct->refcount++;
ResourceOwnerRememberCatCacheRef(CurrentResourceOwner, &ct->tuple);
break; /* assume only one match */
} }
/* immediately set the refcount to 1 */
ResourceOwnerEnlargeCatCacheRefs(CurrentResourceOwner);
ct->refcount++;
ResourceOwnerRememberCatCacheRef(CurrentResourceOwner, &ct->tuple);
break; /* assume only one match */
}
systable_endscan(scandesc); systable_endscan(scandesc);
} while (stale); } while (stale);
table_close(relation, AccessShareLock); table_close(relation, AccessShareLock);
@ -1654,95 +1654,95 @@ SearchCatCacheList(CatCache *cache,
cur_skey[2].sk_argument = v3; cur_skey[2].sk_argument = v3;
cur_skey[3].sk_argument = v4; cur_skey[3].sk_argument = v4;
scandesc = systable_beginscan(relation, scandesc = systable_beginscan(relation,
cache->cc_indexoid, cache->cc_indexoid,
IndexScanOK(cache, cur_skey), IndexScanOK(cache, cur_skey),
NULL, NULL,
nkeys, nkeys,
cur_skey); cur_skey);
/* The list will be ordered iff we are doing an index scan */ /* The list will be ordered iff we are doing an index scan */
ordered = (scandesc->irel != NULL); ordered = (scandesc->irel != NULL);
stale = false; stale = false;
while (HeapTupleIsValid(ntp = systable_getnext(scandesc))) while (HeapTupleIsValid(ntp = systable_getnext(scandesc)))
{
uint32 hashValue;
Index hashIndex;
bool found = false;
dlist_head *bucket;
/*
* See if there's an entry for this tuple already.
*/
ct = NULL;
hashValue = CatalogCacheComputeTupleHashValue(cache, cache->cc_nkeys, ntp);
hashIndex = HASH_INDEX(hashValue, cache->cc_nbuckets);
bucket = &cache->cc_bucket[hashIndex];
dlist_foreach(iter, bucket)
{ {
ct = dlist_container(CatCTup, cache_elem, iter.cur); uint32 hashValue;
Index hashIndex;
if (ct->dead || ct->negative) bool found = false;
continue; /* ignore dead and negative entries */ dlist_head *bucket;
if (ct->hash_value != hashValue)
continue; /* quickly skip entry if wrong hash val */
if (!ItemPointerEquals(&(ct->tuple.t_self), &(ntp->t_self)))
continue; /* not same tuple */
/* /*
* Found a match, but can't use it if it belongs to another * See if there's an entry for this tuple already.
* list already
*/ */
if (ct->c_list) ct = NULL;
continue; hashValue = CatalogCacheComputeTupleHashValue(cache, cache->cc_nkeys, ntp);
hashIndex = HASH_INDEX(hashValue, cache->cc_nbuckets);
found = true; bucket = &cache->cc_bucket[hashIndex];
break; /* A-OK */ dlist_foreach(iter, bucket)
}
if (!found)
{
/* We didn't find a usable entry, so make a new one */
ct = CatalogCacheCreateEntry(cache, ntp, scandesc, NULL,
hashValue, hashIndex);
/* upon failure, we must start the scan over */
if (ct == NULL)
{ {
ct = dlist_container(CatCTup, cache_elem, iter.cur);
if (ct->dead || ct->negative)
continue; /* ignore dead and negative entries */
if (ct->hash_value != hashValue)
continue; /* quickly skip entry if wrong hash val */
if (!ItemPointerEquals(&(ct->tuple.t_self), &(ntp->t_self)))
continue; /* not same tuple */
/* /*
* Release refcounts on any items we already had. We dare * Found a match, but can't use it if it belongs to
* not try to free them if they're now unreferenced, since * another list already
* an error while doing that would result in the PG_CATCH
* below doing extra refcount decrements. Besides, we'll
* likely re-adopt those items in the next iteration, so
* it's not worth complicating matters to try to get rid
* of them.
*/ */
foreach(ctlist_item, ctlist) if (ct->c_list)
{ continue;
ct = (CatCTup *) lfirst(ctlist_item);
Assert(ct->c_list == NULL); found = true;
Assert(ct->refcount > 0); break; /* A-OK */
ct->refcount--;
}
/* Reset ctlist in preparation for new try */
ctlist = NIL;
stale = true;
break;
} }
if (!found)
{
/* We didn't find a usable entry, so make a new one */
ct = CatalogCacheCreateEntry(cache, ntp, scandesc, NULL,
hashValue, hashIndex);
/* upon failure, we must start the scan over */
if (ct == NULL)
{
/*
* Release refcounts on any items we already had. We
* dare not try to free them if they're now
* unreferenced, since an error while doing that would
* result in the PG_CATCH below doing extra refcount
* decrements. Besides, we'll likely re-adopt those
* items in the next iteration, so it's not worth
* complicating matters to try to get rid of them.
*/
foreach(ctlist_item, ctlist)
{
ct = (CatCTup *) lfirst(ctlist_item);
Assert(ct->c_list == NULL);
Assert(ct->refcount > 0);
ct->refcount--;
}
/* Reset ctlist in preparation for new try */
ctlist = NIL;
stale = true;
break;
}
}
/* Careful here: add entry to ctlist, then bump its refcount */
/* This way leaves state correct if lappend runs out of memory */
ctlist = lappend(ctlist, ct);
ct->refcount++;
} }
/* Careful here: add entry to ctlist, then bump its refcount */ systable_endscan(scandesc);
/* This way leaves state correct if lappend runs out of memory */
ctlist = lappend(ctlist, ct);
ct->refcount++;
}
systable_endscan(scandesc);
} while (stale); } while (stale);
table_close(relation, AccessShareLock); table_close(relation, AccessShareLock);