So far, the most important optimizations performed by the planner have been discussed in more or less detail. PostgreSQL has become very smart over the years. Still it can happen that something goes south and users have to convince the planner to do the right thing.
To modify plans, PostgreSQL offers a couple of runtime variables, which will have a significant impact on planning. The idea is to give the end user the chance to make certain types of nodes in the plan more expensive than others. What does that mean in practice? Here is a simple plan:
test=# explain SELECT *
FROM generate_series(1, 100) AS a,
generate_series(1, 100) AS b
WHERE a = b;
QUERY PLAN
-----------------------------------------------------------------
Merge Join (cost=119.66..199.66 rows=5000 width...