by anarazel · 10y ago · 0 comments
Analyze & rewrite doesn't really use any complex algorithms.
Analyzing basically means that we resolve tables/objects/operators/databases/... in the parse-tree into what they mean in the current database with the current settings. The process of parsing itself (via a bison parser) doesn't do any object lookups and such. So errors about non-existant tables, operators and such will mostly happen during the analyze phase.
The rewrite phase, which often will do nothing, will resolve both explicitly (CREATE VIEW) and implicitly (row-level security) referenced views by their definition. It also processes rules in an equivalent manner, but you should never use those...
The actual optimization you're referring to will happen as part of planning.
EDIT: typos
Source: I'm a PostgreSQL Developer.