50.4. ThePostgreSQL Rule System#
PostgreSQL supports a powerfulrule system for the specification ofviews and ambiguousview updates. Originally thePostgreSQL rule system consisted of two implementations:
The first one worked usingrow level processing and was implemented deep in theexecutor. The rule system was called whenever an individual row had been accessed. This implementation was removed in 1995 when the last official release of theBerkeley Postgres project was transformed intoPostgres95.
The second implementation of the rule system is a technique calledquery rewriting. Therewrite system is a module that exists between theparser stage and theplanner/optimizer. This technique is still implemented.
The query rewriter is discussed in some detail inChapter 39, so there is no need to cover it here. We will only point out that both the input and the output of the rewriter are query trees, that is, there is no change in the representation or level of semantic detail in the trees. Rewriting can be thought of as a form of macro expansion.