← Friday, October 9, 2026DatabasesDeep dive

PostgreSQL separates static query rewrites from data-driven plan optimization

theconsensus.dev by theconsensus.dev via fanf 14 min read Editor score 7/10

The piece distinguishes statically knowable rewrites, such as folding `i+0`, from optimization decisions that depend on statistics and data. Understanding that boundary helps engineers reason about query plans and database performance.

What
- PostgreSQL query-plan rewriting covers statically knowable changes, distinct from optimization that depends on statistics or other data-specific knowledge.
How
- PostgreSQL parses SQL into an abstract syntax tree, then resolves identifiers; its planner can fold constants and choose indexes, scans, and joins.
Why it matters
- Distinguishing rewriting from optimization helps engineers reason about which query-plan changes follow from SQL alone and which depend on data.
parse resolve rewrite and o… SQL query Abstract SyntaxTree (AST) query planner query plan
PostgreSQL turns SQL into an AST, then the planner produces a query plan. Sketched from the article's own text.

Discussion

Discussion is not switched on yet. Use Note above to keep your own thoughts on this story.

Headline, summary, brief and diagram are written by a model from the source's own text; the link, byline and numbers come from the source. Read the original before relying on a claim.

Your note

Private to you. Stored in this browser, and synced to your account when you are signed in.