Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b85a9d0

Browse files
committed
Avoid looping over all type cache entries in TypeCacheRelCallback()
Currently, when a single relcache entry gets invalidated, TypeCacheRelCallback() has to loop over all type cache entries to find appropriate typentry to invalidate. Unfortunately, using the syscache here is impossible, because this callback could be called outside a transaction and this makes impossible catalog lookups. This is why present commit introduces RelIdToTypeIdCacheHash to map relation OID to its composite type OID. We are keeping RelIdToTypeIdCacheHash entry while corresponding type cache entry have something to clean. Therefore, RelIdToTypeIdCacheHash shouldn't get bloat in the case of temporary tables flood. There are many places in lookup_type_cache() where syscache invalidation, user interruption, or even error could occur. In order to handle this, we keep an array of in-progress type cache entries. In the case of lookup_type_cache() interruption this array is processed to keep RelIdToTypeIdCacheHash in a consistent state. Discussion: https://postgr.es/m/5812a6e5-68ae-4d84-9d85-b443176966a1%40sigaev.ru Author: Teodor Sigaev Reviewed-by: Aleksander Alekseev, Tom Lane, Michael Paquier, Roman Zharkov Reviewed-by: Andrei Lepikhov, Pavel Borisov, Jian He, Alexander Lakhin Reviewed-by: Artur Zakirov
1 parent c1500a1 commit b85a9d0

File tree

11 files changed

+433
-46
lines changed

11 files changed

+433
-46
lines changed

src/backend/access/transam/xact.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include "utils/snapmgr.h"
7171
#include "utils/timeout.h"
7272
#include "utils/timestamp.h"
73+
#include "utils/typcache.h"
7374

7475
/*
7576
* User-tweakable parameters
@@ -2407,6 +2408,9 @@ CommitTransaction(void)
24072408
/* Clean up the relation cache */
24082409
AtEOXact_RelationCache(true);
24092410

2411+
/* Clean up the type cache */
2412+
AtEOXact_TypeCache();
2413+
24102414
/*
24112415
* Make catalog changes visible to all backends. This has to happen after
24122416
* relcache references are dropped (see comments for
@@ -2709,6 +2713,9 @@ PrepareTransaction(void)
27092713
/* Clean up the relation cache */
27102714
AtEOXact_RelationCache(true);
27112715

2716+
/* Clean up the type cache */
2717+
AtEOXact_TypeCache();
2718+
27122719
/* notify doesn't need a postprepare call */
27132720

27142721
PostPrepare_PgStat();
@@ -2951,6 +2958,7 @@ AbortTransaction(void)
29512958
false, true);
29522959
AtEOXact_Buffers(false);
29532960
AtEOXact_RelationCache(false);
2961+
AtEOXact_TypeCache();
29542962
AtEOXact_Inval(false);
29552963
AtEOXact_MultiXact();
29562964
ResourceOwnerRelease(TopTransactionResourceOwner,
@@ -5153,6 +5161,7 @@ CommitSubTransaction(void)
51535161
true, false);
51545162
AtEOSubXact_RelationCache(true, s->subTransactionId,
51555163
s->parent->subTransactionId);
5164+
AtEOSubXact_TypeCache();
51565165
AtEOSubXact_Inval(true);
51575166
AtSubCommit_smgr();
51585167

@@ -5328,6 +5337,7 @@ AbortSubTransaction(void)
53285337

53295338
AtEOSubXact_RelationCache(false, s->subTransactionId,
53305339
s->parent->subTransactionId);
5340+
AtEOSubXact_TypeCache();
53315341
AtEOSubXact_Inval(false);
53325342
ResourceOwnerRelease(s->curTransactionOwner,
53335343
RESOURCE_RELEASE_LOCKS,

0 commit comments

Comments
 (0)