select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

CONFIGURATION / QUERY TUNING

geqo_threshold

Read PG 18 manual ↗

Use genetic query optimization to plan queries with at least this many FROM items involved.

Type
integer
Context
user
Measured default
12
Unit
Metadata snapshot
18

Definition PG 18 manual

Use genetic query optimization to plan queries with at least this many FROM items involved. (Note that a FULL OUTER JOIN construct counts as only one FROM item.) The default is 12. For simpler queries it is usually best to use the regular, exhaustive-search planner, but for queries with many tables the exhaustive search takes too long, often longer than the penalty of executing a suboptimal plan. Thus, a threshold on the size of the query is a convenient way to manage use of GEQO.

Measured default history
Version intervalDefault
9.0 – 1912
Analysis & operational context

Authored guidance from the GUC source snapshot; the version-specific manual above is the definition reference. View source ↗

How it works

It counts FROM items and switches eligible join problems to GEQO at or above the threshold; a FULL OUTER JOIN construct counts as one item.

GEQO trades bounded planning time for a heuristic search that can miss the best join order. It still costs scan and join paths with the ordinary planner cost model after constructing candidates.

The setting is read during planning, and GEQO's randomized search means plan quality can vary with seed and search budget. Collapse limits can change the number of relations exposed to the join search and therefore whether the threshold is crossed. Its user context permits session- or transaction-local changes; newly performed or newly planned work sees the value.

Operational considerations

Judging plan quality from one randomized GEQO run.

Changing a GEQO knob without accounting for geqo_threshold and collapse limits.

Spending much more planning CPU for a marginal or unstable execution-time gain.

Assuming GEQO guarantees the globally best join order.

Workload guidance

OLAP: For recurring many-table reports, test geqo_threshold with multiple geqo_seed values and compare planning plus execution time. A single lucky seed is not a stable production policy.

OLTP: Keep geqo_threshold at its upstream default unless planning time for many-way joins is measured as a problem. Prefer simplifying generated SQL or fixing join estimates before expanding a randomized search budget globally.

SMALL: Avoid increasing geqo_threshold in ways that consume disproportionate planning CPU on a small host. The default adaptive values are safer than copying a large-system GEQO budget.

Related entries

Further reading

Definition snapshot: english-manuals:55ef23c7bc8759428e8b8c23093… · English manual source