Timing overhead
Assume you're executing a simple query to count all the customers in the database, and want to time how long this takes:
dellstore2=# \timing Timing is on. dellstore2=# SELECT count(*) FROM customers; count ------- 20000 Time: 7.994 ms
You might then be curious what query plan was used to get this result. The amount of time taken to determine that, may shock you:
dellstore2=# EXPLAIN ANALYZE SELECT count(*) FROM customers; QUERY PLAN ---------- Aggregate (cost=726.00..726.01 rows=1 width=0) (actual time=68.836..68.838 rows=1 loops=1) -> Seq Scan on customers (cost=0.00..676.00 rows=20000 width=0) (actual time=0.012..33.609 rows=20000 loops=1) Total runtime: 68.934 ms Time: 69.837 ms
This fairly trivial query was picked because it demonstrates something close to a worst-case here, where instrumenting the query causes the result to slow dramatically, to almost 10X as long. Using EXPLAIN ANALYZE...