@@ -89,7 +89,8 @@ typedef struct
89
89
typedef struct
90
90
{
91
91
MemoryContext pathman_contexts [PATHMAN_MCXT_COUNT ];
92
- int current_context ;
92
+ HTAB * pathman_htables [PATHMAN_MCXT_COUNT ];
93
+ int current_item ;
93
94
} show_cache_stats_cxt ;
94
95
95
96
@@ -299,7 +300,12 @@ show_cache_stats_internal(PG_FUNCTION_ARGS)
299
300
usercxt -> pathman_contexts [2 ] = PathmanParentCacheContext ;
300
301
usercxt -> pathman_contexts [3 ] = PathmanCostraintCacheContext ;
301
302
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 ;
303
309
304
310
/* Create tuple descriptor */
305
311
tupdesc = CreateTemplateTupleDesc (Natts_pathman_cache_stats , false);
@@ -310,6 +316,8 @@ show_cache_stats_internal(PG_FUNCTION_ARGS)
310
316
"size" , INT8OID , -1 , 0 );
311
317
TupleDescInitEntry (tupdesc , Anum_pathman_cs_used ,
312
318
"used" , INT8OID , -1 , 0 );
319
+ TupleDescInitEntry (tupdesc , Anum_pathman_cs_entries ,
320
+ "entries" , INT8OID , -1 , 0 );
313
321
314
322
funccxt -> tuple_desc = BlessTupleDesc (tupdesc );
315
323
funccxt -> user_fctx = (void * ) usercxt ;
@@ -320,8 +328,9 @@ show_cache_stats_internal(PG_FUNCTION_ARGS)
320
328
funccxt = SRF_PERCALL_SETUP ();
321
329
usercxt = (show_cache_stats_cxt * ) funccxt -> user_fctx ;
322
330
323
- if (usercxt -> current_context < lengthof (usercxt -> pathman_contexts ))
331
+ if (usercxt -> current_item < lengthof (usercxt -> pathman_contexts ))
324
332
{
333
+ HTAB * current_htab ;
325
334
MemoryContext current_mcxt ;
326
335
MemoryContextCounters mcxt_stats ;
327
336
HeapTuple htup ;
@@ -331,8 +340,9 @@ show_cache_stats_internal(PG_FUNCTION_ARGS)
331
340
/* Prepare context counters */
332
341
memset (& mcxt_stats , 0 , sizeof (mcxt_stats ));
333
342
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 ];
336
346
337
347
/* NOTE: we do not consider child contexts if it's TopPathmanContext */
338
348
McxtStatsInternal (current_mcxt , 0 ,
@@ -348,8 +358,11 @@ show_cache_stats_internal(PG_FUNCTION_ARGS)
348
358
values [Anum_pathman_cs_used - 1 ] =
349
359
Int64GetDatum (mcxt_stats .totalspace - mcxt_stats .freespace );
350
360
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 ++ ;
353
366
354
367
/* Form output tuple */
355
368
htup = heap_form_tuple (funccxt -> tuple_desc , values , isnull );
0 commit comments