Disabling optimizer features

Sometimes the optimizer doesn't do what you want, and you may want some tools to either force it to change its mind or to see what alternatives it's considering but rejecting. Consider this simple query that searches for one order and joins with its matching customer record:

EXPLAIN ANALYZE SELECT C.customerid,O.orderid FROM customers C,orders O WHERE c.customerid=o.customerid AND o.orderid=10000;
    Nested Loop  (cost=0.00..16.55 rows=1 width=8) (actual time=0.038..0.049 rows=1 loops=1)
       ->  Index Scan using orders_pkey on orders o  (cost=0.00..8.27 rows=1 width=8) (actual time=0.018..0.020 rows=1 loops=1)
             Index Cond: (orderid = 10000)
     -> Index Scan using customers_pkey on customers c (cost=0.00..8.27 ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.