Index Scan

An Index Scan is what you want if your query needs to return a value fast. If an index that is useful to satisfy a selective WHERE condition exists, you'll get one in a query plan that looks like the following:

EXPLAIN ANALYZE SELECT * FROM customers WHERE customerid=1000;
QUERY PLAN
----------
Index Scan using customers_pkey on customers  (cost=0.00..8.27 rows=1 width=268) (actual time=0.029..0.033 rows=1 loops=1)
       Index Cond: (customerid = 1000)
     Total runtime: 0.102 ms  

The main component to the cost here are the two random page reads (4.0 each, making a total of 8.0), both the index block and the one the database row is in. If you remember, that the data blocks must always be read in PostgreSQL, even if the Index Scan is just ...

Get PostgreSQL 10 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.