Thread: Understanding Rule System

Understanding Rule System

From
Juan Pablo Espino
Date:
Hello all

I have been studying the rule system in Postgres.  I understand that
the original query tree is the input at the rewrite, and then this
query tree is modified by the rewrite in case that there is a rule.

SQL query ----> Parser ----> Rewrite ----> Planner ----> Executor                                 ^^^^            ^^^^
                             Query         New Query                               tree            tree 

I would like to know how the rewrite detects that a rule in a table
exists, and if it possible you indicate me where in the source code
it's implemented.  Any comments are welcome, thanks in advance.

Juan P. Espino


Re: Understanding Rule System

From
Jaime Casanova
Date:
On 5/11/05, Juan Pablo Espino <jp.espino@gmail.com> wrote:
> Hello all
>
> I have been studying the rule system in Postgres.  I understand that
> the original query tree is the input at the rewrite, and then this
> query tree is modified by the rewrite in case that there is a rule.
>
> SQL query ----> Parser ----> Rewrite ----> Planner ----> Executor
>                                   ^^^^            ^^^^
>                                  Query         New Query
>                                 tree            tree
>
> I would like to know how the rewrite detects that a rule in a table
> exists, and if it possible you indicate me where in the source code
> it's implemented.  Any comments are welcome, thanks in advance.
>
src/backend/rewrite/*.c       The entry point i think is rewriteHandler.c

IIRC, there is a catalog that is used to know if there are any rules
for a table i think it is pg_rewrite, but i can be wrong.

--
Atentamente,
Jaime Casanova
(DBA: DataBase Aniquilator ;)