@@ -729,9 +729,11 @@ WHERE t1.unique1 < 10 AND t1.unique2 = t2.unique2;
729729 Buffers: shared hit=3 read=5 written=4
730730 -> Bitmap Index Scan on tenk1_unique1 (cost=0.00..4.36 rows=10 width=0) (actual time=0.004..0.004 rows=10.00 loops=1)
731731 Index Cond: (unique1 < 10)
732+ Index Searches: 1
732733 Buffers: shared hit=2
733734 -> Index Scan using tenk2_unique2 on tenk2 t2 (cost=0.29..7.90 rows=1 width=244) (actual time=0.003..0.003 rows=1 loops=10)
734735 Index Cond: (unique2 = t1.unique2)
736+ Index Searches: 10
735737 Buffers: shared hit=24 read=6
736738 Planning:
737739 Buffers: shared hit=15 dirtied=9
@@ -790,6 +792,7 @@ WHERE t1.unique1 < 100 AND t1.unique2 = t2.unique2 ORDER BY t1.fivethous;
790792 Buffers: shared hit=92
791793 -> Bitmap Index Scan on tenk1_unique1 (cost=0.00..5.04 rows=100 width=0) (actual time=0.013..0.013 rows=100.00 loops=1)
792794 Index Cond: (unique1 < 100)
795+ Index Searches: 1
793796 Buffers: shared hit=2
794797 Planning:
795798 Buffers: shared hit=12
@@ -805,6 +808,58 @@ WHERE t1.unique1 < 100 AND t1.unique2 = t2.unique2 ORDER BY t1.fivethous;
805808 shown.)
806809 </para>
807810
811+ <para>
812+ Index Scan nodes (as well as Bitmap Index Scan and Index-Only Scan nodes)
813+ show an <quote>Index Searches</quote> line that reports the total number
814+ of searches across <emphasis>all</emphasis> node
815+ executions/<literal>loops</literal>:
816+
817+ <screen>
818+ EXPLAIN ANALYZE SELECT * FROM tenk1 WHERE thousand IN (1, 500, 700, 999);
819+ QUERY PLAN
820+ -------------------------------------------------------------------&zwsp;---------------------------------------------------------
821+ Bitmap Heap Scan on tenk1 (cost=9.45..73.44 rows=40 width=244) (actual time=0.012..0.028 rows=40.00 loops=1)
822+ Recheck Cond: (thousand = ANY ('{1,500,700,999}'::integer[]))
823+ Heap Blocks: exact=39
824+ Buffers: shared hit=47
825+ -> Bitmap Index Scan on tenk1_thous_tenthous (cost=0.00..9.44 rows=40 width=0) (actual time=0.009..0.009 rows=40.00 loops=1)
826+ Index Cond: (thousand = ANY ('{1,500,700,999}'::integer[]))
827+ Index Searches: 4
828+ Buffers: shared hit=8
829+ Planning Time: 0.037 ms
830+ Execution Time: 0.034 ms
831+ </screen>
832+
833+ Here we see a Bitmap Index Scan node that needed 4 separate index
834+ searches. The scan had to search the index from the
835+ <structname>tenk1_thous_tenthous</structname> index root page once per
836+ <type>integer</type> value from the predicate's <literal>IN</literal>
837+ construct. However, the number of index searches often won't have such a
838+ simple correspondance to the query predicate:
839+
840+ <screen>
841+ EXPLAIN ANALYZE SELECT * FROM tenk1 WHERE thousand IN (1, 2, 3, 4);
842+ QUERY PLAN
843+ ----------------------------------------------------------------------------------------------------------------------------------
844+ Bitmap Heap Scan on tenk1 (cost=9.45..73.44 rows=40 width=244) (actual time=0.009..0.019 rows=40.00 loops=1)
845+ Recheck Cond: (thousand = ANY ('{1,2,3,4}'::integer[]))
846+ Heap Blocks: exact=38
847+ Buffers: shared hit=40
848+ -> Bitmap Index Scan on tenk1_thous_tenthous (cost=0.00..9.44 rows=40 width=0) (actual time=0.005..0.005 rows=40.00 loops=1)
849+ Index Cond: (thousand = ANY ('{1,2,3,4}'::integer[]))
850+ Index Searches: 1
851+ Buffers: shared hit=2
852+ Planning Time: 0.029 ms
853+ Execution Time: 0.026 ms
854+ </screen>
855+
856+ This variant of our <literal>IN</literal> query performed only 1 index
857+ search. It spent less time traversing the index (compared to the original
858+ query) because its <literal>IN</literal> construct uses values matching
859+ index tuples stored next to each other, on the same
860+ <structname>tenk1_thous_tenthous</structname> index leaf page.
861+ </para>
862+
808863 <para>
809864 Another type of extra information is the number of rows removed by a
810865 filter condition:
@@ -861,6 +916,7 @@ EXPLAIN ANALYZE SELECT * FROM polygon_tbl WHERE f1 @> polygon '(0.5,2.0)';
861916 Index Scan using gpolygonind on polygon_tbl (cost=0.13..8.15 rows=1 width=85) (actual time=0.074..0.074 rows=0.00 loops=1)
862917 Index Cond: (f1 @> '((0.5,2))'::polygon)
863918 Rows Removed by Index Recheck: 1
919+ Index Searches: 1
864920 Buffers: shared hit=1
865921 Planning Time: 0.039 ms
866922 Execution Time: 0.098 ms
@@ -894,8 +950,10 @@ EXPLAIN (ANALYZE, BUFFERS OFF) SELECT * FROM tenk1 WHERE unique1 < 100 AND un
894950 -> BitmapAnd (cost=25.07..25.07 rows=10 width=0) (actual time=0.100..0.101 rows=0.00 loops=1)
895951 -> Bitmap Index Scan on tenk1_unique1 (cost=0.00..5.04 rows=100 width=0) (actual time=0.027..0.027 rows=100.00 loops=1)
896952 Index Cond: (unique1 < 100)
953+ Index Searches: 1
897954 -> Bitmap Index Scan on tenk1_unique2 (cost=0.00..19.78 rows=999 width=0) (actual time=0.070..0.070 rows=999.00 loops=1)
898955 Index Cond: (unique2 > 9000)
956+ Index Searches: 1
899957 Planning Time: 0.162 ms
900958 Execution Time: 0.143 ms
901959</screen>
@@ -923,6 +981,7 @@ EXPLAIN ANALYZE UPDATE tenk1 SET hundred = hundred + 1 WHERE unique1 < 100;
923981 Buffers: shared hit=4 read=2
924982 -> Bitmap Index Scan on tenk1_unique1 (cost=0.00..5.04 rows=100 width=0) (actual time=0.031..0.031 rows=100.00 loops=1)
925983 Index Cond: (unique1 < 100)
984+ Index Searches: 1
926985 Buffers: shared read=2
927986 Planning Time: 0.151 ms
928987 Execution Time: 1.856 ms
@@ -1061,6 +1120,7 @@ EXPLAIN ANALYZE SELECT * FROM tenk1 WHERE unique1 < 100 AND unique2 > 9000
10611120 Index Cond: (unique2 > 9000)
10621121 Filter: (unique1 < 100)
10631122 Rows Removed by Filter: 287
1123+ Index Searches: 1
10641124 Buffers: shared hit=16
10651125 Planning Time: 0.077 ms
10661126 Execution Time: 0.086 ms
0 commit comments