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. Recall that the data blocks must always be read in PostgreSQL, even if the index scan is just being used to determine if a row exists, because visibility must be checked in the row data. This will however, turn into random disk seeks against the actual table, the true overhead of which depends on how much of it is already cached.
Regular index...