52.4. Система правил PostgreSQL

PostgreSQL поддерживает мощную систему правил для создания представлений и возможности изменения представлений. Система правил PostgreSQL претерпела две реализации:

  • Первый вариант производил обработку на уровне строк и был внедрён глубоко в исполнителе. Этот обработчик правил вызывался при обращении к каждой отдельной строке. Эта реализация была ликвидирована в 1995 г., когда последний официальный выпуск Berkeley Postgres превратился в Postgres95.

  • Во втором воплощении системы правил применили так называемое переписывание запроса. Система переписывания реализована в механизме, внедрённом между анализатором и планировщиком/оптимизатором. Этот механизм работает и сегодня.

Механизм переписывания запросов подробно обсуждается в Главе 41, так что здесь мы его не рассматриваем. Мы только отметим, что и на входе, и на выходе у него деревья запросов, то есть представление или уровень семантической детализации он не меняет. Переписывание запроса можно считать формой расширения макросов.

52.4. The PostgreSQL Rule System

PostgreSQL supports a powerful rule system for the specification of views and ambiguous view updates. Originally the PostgreSQL rule system consisted of two implementations:

  • The first one worked using row level processing and was implemented deep in the executor. The rule system was called whenever an individual row had been accessed. This implementation was removed in 1995 when the last official release of the Berkeley Postgres project was transformed into Postgres95.

  • The second implementation of the rule system is a technique called query rewriting. The rewrite system is a module that exists between the parser stage and the planner/optimizer. This technique is still implemented.

The query rewriter is discussed in some detail in Chapter 41, 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.

FAQ