From 9f9135d129e915e72c8a2f770689fd72619ead49 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Wed, 25 Jan 2012 20:40:34 -0500 Subject: [PATCH] Instrument index-only scans to count heap fetches performed. Patch by me; review by Tom Lane, Jeff Davis, and Peter Geoghegan. --- src/backend/commands/explain.c | 3 +++ src/backend/executor/nodeIndexonlyscan.c | 2 ++ src/include/nodes/execnodes.h | 2 ++ 3 files changed, 7 insertions(+) diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index 8b48105974..e297e9cfb9 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -1012,6 +1012,9 @@ ExplainNode(PlanState *planstate, List *ancestors, if (plan->qual) show_instrumentation_count("Rows Removed by Filter", 1, planstate, es); + if (es->analyze) + ExplainPropertyLong("Heap Fetches", + ((IndexOnlyScanState *) planstate)->ioss_HeapFetches, es); break; case T_BitmapIndexScan: show_scan_qual(((BitmapIndexScan *) plan)->indexqualorig, diff --git a/src/backend/executor/nodeIndexonlyscan.c b/src/backend/executor/nodeIndexonlyscan.c index 7f1100e15e..4abd805aa3 100644 --- a/src/backend/executor/nodeIndexonlyscan.c +++ b/src/backend/executor/nodeIndexonlyscan.c @@ -90,6 +90,7 @@ IndexOnlyNext(IndexOnlyScanState *node) /* * Rats, we have to visit the heap to check visibility. */ + node->ioss_HeapFetches++; tuple = index_fetch_heap(scandesc); if (tuple == NULL) continue; /* no visible tuple, try next index entry */ @@ -346,6 +347,7 @@ ExecInitIndexOnlyScan(IndexOnlyScan *node, EState *estate, int eflags) indexstate = makeNode(IndexOnlyScanState); indexstate->ss.ps.plan = (Plan *) node; indexstate->ss.ps.state = estate; + indexstate->ioss_HeapFetches = 0; /* * Miscellaneous initialization diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index da4b695cd6..5207102f6c 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -1260,6 +1260,7 @@ typedef struct IndexScanState * RelationDesc index relation descriptor * ScanDesc index scan descriptor * VMBuffer buffer in use for visibility map testing, if any + * HeapFetches number of tuples we were forced to fetch from heap * ---------------- */ typedef struct IndexOnlyScanState @@ -1277,6 +1278,7 @@ typedef struct IndexOnlyScanState Relation ioss_RelationDesc; IndexScanDesc ioss_ScanDesc; Buffer ioss_VMBuffer; + long ioss_HeapFetches; } IndexOnlyScanState; /* ---------------- -- 2.40.0