PostgreSQL Source Code git master
Loading...
Searching...
No Matches
instrument_node.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * instrument_node.h
4 * Definitions for node-specific support for parallel query instrumentation
5 *
6 * These structs purposely contain no pointers because they are copied
7 * across processes during parallel query execution. Each worker copies its
8 * individual information into the container struct at executor shutdown time,
9 * to allow the leader to display the information in EXPLAIN ANALYZE.
10 *
11 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
12 * Portions Copyright (c) 1994, Regents of the University of California
13 *
14 * src/include/executor/instrument_node.h
15 *
16 *-------------------------------------------------------------------------
17 */
18#ifndef INSTRUMENT_NODE_H
19#define INSTRUMENT_NODE_H
20
21/*
22 * Offset added to plan_node_id to create a second TOC key for per-worker scan
23 * instrumentation. Instrumentation and parallel-awareness are independent, so
24 * separate DSM chunks let each be allocated and initialized only when needed.
25 * In the future, if nodes need more DSM allocations, we would need a more
26 * robust system.
27 */
28#define PARALLEL_KEY_SCAN_INSTRUMENT_OFFSET UINT64CONST(0xD000000000000000)
29
30/* ---------------------
31 * Instrumentation information for aggregate function execution
32 * ---------------------
33 */
35{
36 Size hash_mem_peak; /* peak hash table memory usage */
37 uint64 hash_disk_used; /* kB of disk space used */
38 int hash_batches_used; /* batches used during entire execution */
40
41/*
42 * Shared memory container for per-worker aggregate information
43 */
49
50
51/* ---------------------
52 * Instrumentation information about read streams and I/O
53 * ---------------------
54 */
55typedef struct IOStats
56{
57 /* number of buffers returned to consumer (for averaging distance) */
59
60 /* sum of pinned_buffers sampled at each buffer return */
62
63 /* maximum actual pinned_buffers observed during the scan */
65
66 /* maximum possible look-ahead distance (max_pinned_buffers) */
68
69 /* number of waits for a read (for the I/O) */
71
72 /* I/O stats */
73 uint64 io_count; /* number of I/Os */
74 uint64 io_nblocks; /* sum of blocks for all I/Os */
75 uint64 io_in_progress; /* sum of in-progress I/Os */
77
82
83/* merge IO statistics from 'src' into 'dst' */
84static inline void
86{
87 dst->prefetch_count += src->prefetch_count;
88 dst->distance_sum += src->distance_sum;
89 if (src->distance_max > dst->distance_max)
90 dst->distance_max = src->distance_max;
91 if (src->distance_capacity > dst->distance_capacity)
92 dst->distance_capacity = src->distance_capacity;
93 dst->wait_count += src->wait_count;
94 dst->io_count += src->io_count;
95 dst->io_nblocks += src->io_nblocks;
96 dst->io_in_progress += src->io_in_progress;
97}
98
99
100/* ---------------------
101 * Instrumentation information for indexscans (amgettuple and amgetbitmap)
102 * ---------------------
103 */
105{
106 /* Index search count (incremented with pgstat_count_index_scan call) */
109
110/*
111 * Shared memory container for per-worker information
112 */
118
119
120/* ---------------------
121 * Instrumentation information for bitmap heap scans
122 *
123 * exact_pages total number of exact pages retrieved
124 * lossy_pages total number of lossy pages retrieved
125 * ---------------------
126 */
133
134/*
135 * Shared memory container for per-worker information
136 */
142
143
144/* ---------------------
145 * Instrumentation information for Memoize
146 * ---------------------
147 */
149{
150 uint64 cache_hits; /* number of rescans where we've found the
151 * scan parameters values to be cached */
152 uint64 cache_misses; /* number of rescans where we've not found the
153 * scan parameters values to be cached */
154 uint64 cache_evictions; /* number of cache entries removed due to
155 * the need to free memory */
156 uint64 cache_overflows; /* number of times we've had to bypass the
157 * cache when filling it due to not being
158 * able to free enough space to store the
159 * current scan's tuples */
160 uint64 mem_peak; /* peak memory usage in bytes */
162
163/*
164 * Shared memory container for per-worker memoize information
165 */
171
172
173/* ---------------------
174 * Instrumentation information for Sorts.
175 * ---------------------
176 */
177
183
184/*
185 * The parallel-sort infrastructure relies on having a zero TuplesortMethod
186 * to indicate that a worker never did anything, so we assign zero to
187 * SORT_TYPE_STILL_IN_PROGRESS. The other values of this enum can be
188 * OR'ed together to represent a situation where different workers used
189 * different methods, so we need a separate bit for each one. Keep the
190 * NUM_TUPLESORTMETHODS constant in sync with the number of bits!
191 */
200#define NUM_TUPLESORTMETHODS 4
201
203{
204 TuplesortMethod sortMethod; /* sort algorithm used */
205 TuplesortSpaceType spaceType; /* type of space spaceUsed represents */
206 int64 spaceUsed; /* space consumption, in kB */
208
209/*
210 * Shared memory container for per-worker sort information
211 */
217
218
219/* ---------------------
220 * Instrumentation information for nodeHash.c
221 * ---------------------
222 */
224{
225 int nbuckets; /* number of buckets at end of execution */
226 int nbuckets_original; /* planned number of buckets */
227 int nbatch; /* number of batches at end of execution */
228 int nbatch_original; /* planned number of batches */
229 Size space_peak; /* peak memory usage in bytes */
231
232/*
233 * Shared memory container for per-worker information
234 */
240
241
242/* ---------------------
243 * Instrumentation information for IncrementalSort
244 * ---------------------
245 */
255
261
262/* Shared memory container for per-worker incremental sort information */
268
269
270/* ---------------------
271 * Instrumentation information for sequential scans
272 * ---------------------
273 */
278
279/*
280 * Shared memory container for per-worker information
281 */
287
288
289/*
290 * Instrumentation information for TID range scans
291 */
296
297/*
298 * Shared memory container for per-worker information
299 */
305
306#endif /* INSTRUMENT_NODE_H */
int64_t int64
Definition c.h:621
#define FLEXIBLE_ARRAY_MEMBER
Definition c.h:558
int16_t int16
Definition c.h:619
uint64_t uint64
Definition c.h:625
uint32_t uint32
Definition c.h:624
size_t Size
Definition c.h:689
static void AccumulateIOStats(IOStats *dst, IOStats *src)
TuplesortSpaceType
@ SORT_SPACE_TYPE_DISK
@ SORT_SPACE_TYPE_MEMORY
TuplesortMethod
@ SORT_TYPE_EXTERNAL_SORT
@ SORT_TYPE_TOP_N_HEAPSORT
@ SORT_TYPE_QUICKSORT
@ SORT_TYPE_STILL_IN_PROGRESS
@ SORT_TYPE_EXTERNAL_MERGE
static int fb(int x)
TableScanInstrumentation stats
int16 distance_capacity
uint64 io_count
uint64 wait_count
int16 distance_max
uint64 io_in_progress
uint64 distance_sum
uint64 prefetch_count
uint64 io_nblocks
IncrementalSortGroupInfo prefixsortGroupInfo
IncrementalSortGroupInfo fullsortGroupInfo
TableScanInstrumentation stats
AggregateInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER]
BitmapHeapScanInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER]
HashInstrumentation hinstrument[FLEXIBLE_ARRAY_MEMBER]
IncrementalSortInfo sinfo[FLEXIBLE_ARRAY_MEMBER]
IndexScanInstrumentation winstrument[FLEXIBLE_ARRAY_MEMBER]
MemoizeInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER]
SeqScanInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER]
TuplesortInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER]
TidRangeScanInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER]
TableScanInstrumentation stats
TuplesortSpaceType spaceType