Instrument index-only scans to count heap fetches performed.
authorRobert Haas <rhaas@postgresql.org>
Thu, 26 Jan 2012 01:40:34 +0000 (20:40 -0500)
committerRobert Haas <rhaas@postgresql.org>
Thu, 26 Jan 2012 01:41:52 +0000 (20:41 -0500)
Patch by me; review by Tom Lane, Jeff Davis, and Peter Geoghegan.

src/backend/commands/explain.c
src/backend/executor/nodeIndexonlyscan.c
src/include/nodes/execnodes.h

index 8b48105974f8a288988e9170864c9595023aeda0..e297e9cfb9079be18500d8e425ee6cdfa0f731be 100644 (file)
@@ -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,
index 7f1100e15e4352d988f2ea2dd904e67332197d92..4abd805aa31733fafc0b18e80a65c4f91695fae5 100644 (file)
@@ -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
index da4b695cd642b5f3ba0a14695e2db9e29487bb6d..5207102f6c9e79c969c0c5f2b46df4a9800ca452 100644 (file)
@@ -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;
 
 /* ----------------