The idea · Lab 3.1.4Every GUC seen so far in this block — enable_hashjoin, enable_mergejoin — is a blunt instrument: a session-wide toggle meant for diagnosis, not a permanent fix. Flip one off, see what the planner does with the alternative forced on it, then flip it back with RESET. That same diagnostic technique applies to enable_seqscan, and PostgreSQL 19 makes the result easier to read than ever: a disabled strategy that was still the only option left now prints "Disabled: true" directly in the plan, instead of leaving you to infer it from an unusually high cost.
Two other levers matter just as much and are permanent, not diagnostic: work_mem, which decides whether a large sort or hash happens in memory or spills to disk, and how a query is written, which decides whether the planner can see through a Common Table Expression or is forced to treat it as an opaque, materialized block. None of this needs an extension — pg_hint_plan is not installed on this server and cannot be, since there is no network access to fetch it and no compiler to build it. Every technique in this lab ships in PostgreSQL by default.
enable_seqscan as a Diagnostic, Not a Fix
SET enable_seqscan = off;
EXPLAIN SELECT * FROM big_a WHERE val = 5000;
Seq Scan on big_a (cost=0.00..847.00 rows=1 width=8)
Disabled: true
Filter: (val = 5000)
With no index on val, Seq Scan is the only access path that exists — disabling it does not remove it, it just marks it. PostgreSQL 19's "Disabled: true" line makes that unambiguous: this plan was forced to use a strategy the session explicitly turned off, because nothing else was available. That is a diagnostic signal pointing at a missing index, not evidence that enable_seqscan fixed anything.
Add the Missing Index
CREATE INDEX idx_biga_val ON big_a(val);
SET enable_seqscan = off;
EXPLAIN SELECT * FROM big_a WHERE val = 5000;
Index Scan using idx_biga_val on big_a (cost=0.29..8.31 rows=1 width=8)
Index Cond: (val = 5000)
Cost drops from 847.00 to 8.31. The real fix was never the GUC — it was the missing index the GUC helped surface.
work_mem: The Same Sort, Two Memory Budgets
| work_mem | Sort Method | Execution Time |
|---|
| 64kB | external merge, Disk: 1128kB | 569.232 ms |
| 32MB | quicksort, Memory: 2196kB | 193.833 ms |
Same query, same 50,000 rows, same result — nearly three times slower when the sort has to spill to disk because the memory budget for it was too small.
The MATERIALIZED CTE Fence
-- default (and explicit NOT MATERIALIZED): planner inlines the CTE
EXPLAIN WITH sub AS (SELECT * FROM big_a) SELECT * FROM sub WHERE id = 5;
-- Index Scan using big_a_pkey on big_a (cost=0.29..8.31 rows=1 width=8)
-- MATERIALIZED: planner treats the CTE as an opaque, computed-once block
EXPLAIN WITH sub AS MATERIALIZED (SELECT * FROM big_a) SELECT * FROM sub WHERE id = 5;
-- CTE Scan on sub (cost=722.00..1847.00 rows=1 width=8)
-- Filter: (id = 5)
-- CTE sub
-- -> Seq Scan on big_a (cost=0.00..722.00 rows=50000 width=8)
Cost 8.31 versus 1847.00, for the exact same logical query. Since PostgreSQL 12, a CTE is inlined by default whenever it is referenced only once and has no side effects — MATERIALIZED opts back into the old, pre-12 opaque behavior, and is occasionally still useful (forcing a CTE to compute once rather than being duplicated into every reference point), but it is a real fence, not a free hint.
Key concepts
Disabled: true
A PostgreSQL 19 EXPLAIN annotation shown on a plan node whose strategy was turned off with an enable_* GUC but had to be used anyway because no other access path existed. It turns a previously implicit signal (an unusually high cost with no obvious explanation) into an explicit one, making it immediately clear that the plan is not really "the seq scan strategy losing to the planner" — it is the only strategy left standing.
MATERIALIZED / NOT MATERIALIZED (CTE)
Since PostgreSQL 12, a CTE referenced exactly once with no side effects is inlined into the surrounding query by default, letting outer WHERE clauses and joins push down into it exactly as if it had been written as a subquery. Writing MATERIALIZED forces the old pre-12 behavior instead: the CTE is computed once, in isolation, as an opaque block the rest of the query cannot see into or push conditions down through — a deliberate planning fence, occasionally still useful for forcing one-time computation of something expensive that is referenced more than once.
What to remember
- enable_* GUCs are diagnostic tools for testing "what would the planner do without this option" — not permanent settings
- PostgreSQL 19's "Disabled: true" annotation makes it explicit when a disabled strategy still had to run because no alternative existed
- work_mem genuinely changes execution, not just planning — a sort or hash that fits in memory is measurably faster than one that spills to temporary files on disk
- Since PostgreSQL 12, a singly-referenced CTE with no side effects is inlined by default; MATERIALIZED opts back into the pre-12 opaque, fenced behavior deliberately
- Checking whether an extension is actually available (pg_available_extensions) beats assuming — and every technique here ships in PostgreSQL core regardless