Skip to content

Commit 087abe7

Browse files
committed
resolve fixme regarding flushing all caches
1 parent ee8ef93 commit 087abe7

File tree

3 files changed

+64
-17
lines changed

3 files changed

+64
-17
lines changed

src/hooks.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -834,9 +834,9 @@ pathman_relcache_hook(Datum arg, Oid relid)
834834
/* Invalidation event for whole cache */
835835
if (relid == InvalidOid)
836836
{
837-
invalidate_pathman_status_info_cache();
838-
839-
/* FIXME: reset other caches as well */
837+
invalidate_bounds_cache();
838+
invalidate_parents_cache();
839+
invalidate_status_cache();
840840
}
841841

842842
/* Invalidation event for PATHMAN_CONFIG table (probably DROP) */
@@ -855,7 +855,7 @@ pathman_relcache_hook(Datum arg, Oid relid)
855855
forget_parent_of_partition(relid);
856856

857857
/* Invalidate PartStatusInfo entry if needed */
858-
invalidate_pathman_status_info(relid);
858+
forget_status_of_relation(relid);
859859
}
860860
}
861861

src/include/relation_info.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ typedef struct PartBoundInfo
184184
uint32 part_idx;
185185
} PartBoundInfo;
186186

187+
static inline void
188+
FreePartBoundInfo(PartBoundInfo *pbin)
189+
{
190+
if (pbin->parttype == PT_RANGE)
191+
{
192+
FreeBound(&pbin->range_min, pbin->byval);
193+
FreeBound(&pbin->range_max, pbin->byval);
194+
}
195+
}
196+
187197
/*
188198
* PartRelationInfo
189199
* Per-relation partitioning information.
@@ -341,8 +351,8 @@ PartTypeToCString(PartType parttype)
341351

342352

343353
/* Status chache */
344-
void invalidate_pathman_status_info(Oid relid);
345-
void invalidate_pathman_status_info_cache(void);
354+
void forget_status_of_relation(Oid relid);
355+
void invalidate_status_cache(void);
346356

347357
/* Dispatch cache */
348358
bool has_pathman_relation_info(Oid relid);
@@ -359,11 +369,13 @@ void shout_if_prel_is_invalid(const Oid parent_oid,
359369
/* Bounds cache */
360370
void forget_bounds_of_partition(Oid partition);
361371
PartBoundInfo *get_bounds_of_partition(Oid partition, const PartRelationInfo *prel);
372+
void invalidate_bounds_cache(void);
362373

363374
/* Parents cache */
364375
void cache_parent_of_partition(Oid partition, Oid parent);
365376
void forget_parent_of_partition(Oid partition);
366377
Oid get_parent_of_partition(Oid partition);
378+
void invalidate_parents_cache(void);
367379

368380
/* Partitioning expression routines */
369381
Node *parse_partitioning_expression(const Oid relid,

src/relation_info.c

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ init_relation_info_static_data(void)
187187

188188
/* Invalidate PartStatusInfo for 'relid' */
189189
void
190-
invalidate_pathman_status_info(Oid relid)
190+
forget_status_of_relation(Oid relid)
191191
{
192192
PartStatusInfo *psin;
193193
PartParentInfo *ppar;
@@ -225,7 +225,7 @@ invalidate_pathman_status_info(Oid relid)
225225

226226
/* Invalidate all PartStatusInfo entries */
227227
void
228-
invalidate_pathman_status_info_cache(void)
228+
invalidate_status_cache(void)
229229
{
230230
invalidate_psin_entries_using_relid(InvalidOid);
231231
}
@@ -241,14 +241,14 @@ invalidate_psin_entries_using_relid(Oid relid)
241241

242242
while ((psin = (PartStatusInfo *) hash_seq_search(&status)) != NULL)
243243
{
244-
if (relid == InvalidOid ||
244+
if (!OidIsValid(relid) ||
245245
psin->relid == relid ||
246246
(psin->prel && PrelHasPartition(psin->prel, relid)))
247247
{
248248
/* Perform invalidation */
249249
invalidate_psin_entry(psin);
250250

251-
/* Exit if found */
251+
/* Exit if exact match */
252252
if (OidIsValid(relid))
253253
{
254254
hash_seq_term(&status);
@@ -952,15 +952,10 @@ forget_bounds_of_partition(Oid partition)
952952
NULL) :
953953
NULL; /* don't even bother */
954954

955-
/* Free this entry */
956955
if (pbin)
957956
{
958-
/* Call pfree() if it's RANGE bounds */
959-
if (pbin->parttype == PT_RANGE)
960-
{
961-
FreeBound(&pbin->range_min, pbin->byval);
962-
FreeBound(&pbin->range_max, pbin->byval);
963-
}
957+
/* Free this entry */
958+
FreePartBoundInfo(pbin);
964959

965960
/* Finally remove this entry from cache */
966961
pathman_cache_search_relid(bounds_cache,
@@ -1027,6 +1022,26 @@ get_bounds_of_partition(Oid partition, const PartRelationInfo *prel)
10271022
return pbin;
10281023
}
10291024

1025+
void
1026+
invalidate_bounds_cache(void)
1027+
{
1028+
HASH_SEQ_STATUS status;
1029+
PartBoundInfo *pbin;
1030+
1031+
Assert(offsetof(PartBoundInfo, child_relid) == 0);
1032+
1033+
hash_seq_init(&status, bounds_cache);
1034+
1035+
while ((pbin = hash_seq_search(&status)) != NULL)
1036+
{
1037+
FreePartBoundInfo(pbin);
1038+
1039+
pathman_cache_search_relid(bounds_cache,
1040+
pbin->child_relid,
1041+
HASH_REMOVE, NULL);
1042+
}
1043+
}
1044+
10301045
/*
10311046
* Get constraint expression tree of a partition.
10321047
*
@@ -1258,6 +1273,26 @@ get_parent_of_partition(Oid partition)
12581273
}
12591274
}
12601275

1276+
void
1277+
invalidate_parents_cache(void)
1278+
{
1279+
HASH_SEQ_STATUS status;
1280+
PartParentInfo *ppar;
1281+
1282+
Assert(offsetof(PartParentInfo, child_relid) == 0);
1283+
1284+
hash_seq_init(&status, parents_cache);
1285+
1286+
while ((ppar = hash_seq_search(&status)) != NULL)
1287+
{
1288+
/* This is a plain structure, no need to pfree() */
1289+
1290+
pathman_cache_search_relid(parents_cache,
1291+
ppar->child_relid,
1292+
HASH_REMOVE, NULL);
1293+
}
1294+
}
1295+
12611296

12621297
/*
12631298
* Partitioning expression routines.

0 commit comments

Comments
 (0)