Skip to content

Commit 20fbd32

Browse files
committed
add 'entries' to 'pathman_cache_stats' view
1 parent 0c3233c commit 20fbd32

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

init.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ CREATE OR REPLACE FUNCTION @extschema@.show_cache_stats()
274274
RETURNS TABLE (
275275
context TEXT,
276276
size INT8,
277-
used INT8)
277+
used INT8,
278+
entries INT8)
278279
AS 'pg_pathman', 'show_cache_stats_internal'
279280
LANGUAGE C STRICT;
280281

src/include/pathman.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@
7979
* Definitions for the "pathman_cache_stats" view.
8080
*/
8181
#define PATHMAN_CACHE_STATS "pathman_cache_stats"
82-
#define Natts_pathman_cache_stats 3
82+
#define Natts_pathman_cache_stats 4
8383
#define Anum_pathman_cs_context 1 /* name of memory context */
8484
#define Anum_pathman_cs_size 2 /* size of memory context */
8585
#define Anum_pathman_cs_used 3 /* used space */
86+
#define Anum_pathman_cs_entries 4 /* number of cache entries */
8687

8788

8889
/*

src/pl_funcs.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ typedef struct
8989
typedef struct
9090
{
9191
MemoryContext pathman_contexts[PATHMAN_MCXT_COUNT];
92-
int current_context;
92+
HTAB *pathman_htables[PATHMAN_MCXT_COUNT];
93+
int current_item;
9394
} show_cache_stats_cxt;
9495

9596

@@ -299,7 +300,12 @@ show_cache_stats_internal(PG_FUNCTION_ARGS)
299300
usercxt->pathman_contexts[2] = PathmanParentCacheContext;
300301
usercxt->pathman_contexts[3] = PathmanCostraintCacheContext;
301302

302-
usercxt->current_context = 0;
303+
usercxt->pathman_htables[0] = NULL; /* no HTAB for this entry */
304+
usercxt->pathman_htables[1] = partitioned_rels;
305+
usercxt->pathman_htables[2] = parent_cache;
306+
usercxt->pathman_htables[3] = constraint_cache;
307+
308+
usercxt->current_item = 0;
303309

304310
/* Create tuple descriptor */
305311
tupdesc = CreateTemplateTupleDesc(Natts_pathman_cache_stats, false);
@@ -310,6 +316,8 @@ show_cache_stats_internal(PG_FUNCTION_ARGS)
310316
"size", INT8OID, -1, 0);
311317
TupleDescInitEntry(tupdesc, Anum_pathman_cs_used,
312318
"used", INT8OID, -1, 0);
319+
TupleDescInitEntry(tupdesc, Anum_pathman_cs_entries,
320+
"entries", INT8OID, -1, 0);
313321

314322
funccxt->tuple_desc = BlessTupleDesc(tupdesc);
315323
funccxt->user_fctx = (void *) usercxt;
@@ -320,8 +328,9 @@ show_cache_stats_internal(PG_FUNCTION_ARGS)
320328
funccxt = SRF_PERCALL_SETUP();
321329
usercxt = (show_cache_stats_cxt *) funccxt->user_fctx;
322330

323-
if (usercxt->current_context < lengthof(usercxt->pathman_contexts))
331+
if (usercxt->current_item < lengthof(usercxt->pathman_contexts))
324332
{
333+
HTAB *current_htab;
325334
MemoryContext current_mcxt;
326335
MemoryContextCounters mcxt_stats;
327336
HeapTuple htup;
@@ -331,8 +340,9 @@ show_cache_stats_internal(PG_FUNCTION_ARGS)
331340
/* Prepare context counters */
332341
memset(&mcxt_stats, 0, sizeof(mcxt_stats));
333342

334-
/* Select current memory context */
335-
current_mcxt = usercxt->pathman_contexts[usercxt->current_context];
343+
/* Select current memory context and hash table (cache) */
344+
current_mcxt = usercxt->pathman_contexts[usercxt->current_item];
345+
current_htab = usercxt->pathman_htables[usercxt->current_item];
336346

337347
/* NOTE: we do not consider child contexts if it's TopPathmanContext */
338348
McxtStatsInternal(current_mcxt, 0,
@@ -348,8 +358,11 @@ show_cache_stats_internal(PG_FUNCTION_ARGS)
348358
values[Anum_pathman_cs_used - 1] =
349359
Int64GetDatum(mcxt_stats.totalspace - mcxt_stats.freespace);
350360

351-
/* Switch to next context */
352-
usercxt->current_context++;
361+
values[Anum_pathman_cs_entries - 1] =
362+
Int64GetDatum(current_htab ? hash_get_num_entries(current_htab) : 0);
363+
364+
/* Switch to next item */
365+
usercxt->current_item++;
353366

354367
/* Form output tuple */
355368
htup = heap_form_tuple(funccxt->tuple_desc, values, isnull);

0 commit comments

Comments
 (0)