Skip to content

Commit 9f9135d

Browse files
committed
Instrument index-only scans to count heap fetches performed.
Patch by me; review by Tom Lane, Jeff Davis, and Peter Geoghegan.
1 parent 0814677 commit 9f9135d

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

src/backend/commands/explain.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,9 @@ ExplainNode(PlanState *planstate, List *ancestors,
10121012
if (plan->qual)
10131013
show_instrumentation_count("Rows Removed by Filter", 1,
10141014
planstate, es);
1015+
if (es->analyze)
1016+
ExplainPropertyLong("Heap Fetches",
1017+
((IndexOnlyScanState *) planstate)->ioss_HeapFetches, es);
10151018
break;
10161019
case T_BitmapIndexScan:
10171020
show_scan_qual(((BitmapIndexScan *) plan)->indexqualorig,

src/backend/executor/nodeIndexonlyscan.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ IndexOnlyNext(IndexOnlyScanState *node)
9090
/*
9191
* Rats, we have to visit the heap to check visibility.
9292
*/
93+
node->ioss_HeapFetches++;
9394
tuple = index_fetch_heap(scandesc);
9495
if (tuple == NULL)
9596
continue; /* no visible tuple, try next index entry */
@@ -346,6 +347,7 @@ ExecInitIndexOnlyScan(IndexOnlyScan *node, EState *estate, int eflags)
346347
indexstate = makeNode(IndexOnlyScanState);
347348
indexstate->ss.ps.plan = (Plan *) node;
348349
indexstate->ss.ps.state = estate;
350+
indexstate->ioss_HeapFetches = 0;
349351

350352
/*
351353
* Miscellaneous initialization

src/include/nodes/execnodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,7 @@ typedef struct IndexScanState
12601260
* RelationDesc index relation descriptor
12611261
* ScanDesc index scan descriptor
12621262
* VMBuffer buffer in use for visibility map testing, if any
1263+
* HeapFetches number of tuples we were forced to fetch from heap
12631264
* ----------------
12641265
*/
12651266
typedef struct IndexOnlyScanState
@@ -1277,6 +1278,7 @@ typedef struct IndexOnlyScanState
12771278
Relation ioss_RelationDesc;
12781279
IndexScanDesc ioss_ScanDesc;
12791280
Buffer ioss_VMBuffer;
1281+
long ioss_HeapFetches;
12801282
} IndexOnlyScanState;
12811283

12821284
/* ----------------

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy