diff options
author | Peter Geoghegan | 2025-03-05 14:36:48 +0000 |
---|---|---|
committer | Peter Geoghegan | 2025-03-05 14:36:48 +0000 |
commit | 5ead85fbc81162ab1594f656b036a22e814f96b3 (patch) | |
tree | 2ad8afc5c2709eb41eca0e1b8176e729adabdcc2 /src/include/access | |
parent | 635f580120b99f6df71d7c12749b22acde61c5ad (diff) |
Show index search count in EXPLAIN ANALYZE.
Expose the count of index searches/index descents in EXPLAIN ANALYZE's
output for index scan nodes. This information is particularly useful
with scans that use ScalarArrayOp quals, where the number of index scans
isn't predictable in advance (at least not with optimizations like the
one added to nbtree by Postgres 17 commit 5bf748b8). It will also be
useful when EXPLAIN ANALYZE shows details of an nbtree index scan that
uses skip scan optimizations set to be introduced by an upcoming patch.
The instrumentation works by teaching index AMs to increment a new
nsearches counter whenever a new index search begins. The counter is
incremented at exactly the same point that index AMs must already
increment the index's pg_stat_*_indexes.idx_scan counter (we're counting
the same event, but at the scan level rather than the relation level).
The new counter is stored in the scan descriptor (IndexScanDescData),
which explain.c reaches by going through the scan node's PlanState.
This approach doesn't match the approach used when tracking other index
scan specific costs (e.g., "Rows Removed by Filter:"). It is similar to
the approach used in other cases where we must track costs that are only
readily accessible inside an access method, and not from the executor
(e.g., "Heap Blocks:" output for a Bitmap Heap Scan). It is inherently
necessary to maintain a counter that can be incremented multiple times
during a single amgettuple call (or amgetbitmap call), and directly
exposing PlanState.instrument to index access methods seems unappealing.
Author: Peter Geoghegan <[email protected]>
Reviewed-By: Tomas Vondra <[email protected]>
Reviewed-By: Robert Haas <[email protected]>
Reviewed-By: Masahiro Ikeda <[email protected]>
Reviewed-By: Matthias van de Meent <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wz=PKR6rB7qbx+Vnd7eqeB5VTcrW=iJvAsTsKbdG+kW_UA@mail.gmail.com
Discussion: https://postgr.es/m/CAH2-WzkRqvaqR2CTNqTZP0z6FuL4-3ED6eQB0yx38XBNj1v-4Q@mail.gmail.com
Diffstat (limited to 'src/include/access')
-rw-r--r-- | src/include/access/relscan.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/include/access/relscan.h b/src/include/access/relscan.h index dc6e0184284..8e0b08b0d94 100644 --- a/src/include/access/relscan.h +++ b/src/include/access/relscan.h @@ -151,6 +151,13 @@ typedef struct IndexScanDescData void *opaque; /* access-method-specific info */ /* + * Instrumentation counters that are maintained by every index access + * method, for all scan types. These go here because there is no standard + * way to access PlanState.instrument during amgettuple calls. + */ + uint64 nsearches; /* total # of index searches */ + + /* * In an index-only scan, a successful amgettuple call must fill either * xs_itup (and xs_itupdesc) or xs_hitup (and xs_hitupdesc) to provide the * data returned by the scan. It can fill both, in which case the heap |