DEV Community

moaz178
moaz178

Posted on

Query Processing Subsystems in Postgres

In postgres, backend processes perform some operations to carry out a query provided by the client. This includes :

Parser
Analyzer
Rewriter
Planner
Executor

Parser:
This portion prepares the query to be processed by other operations that are subsequent in fashion. It creates a parse tree that is possible to be read by other operations.

Analyzer:
The semantic analysis of the query is performed by the analyzer and this generates a query tree from the parse tree. Attached below is the image of the query tree generated.

Image description

Rewriter:
The rewriter is the system that checks the rules stored and transforms the query tree according to the rules

Planner:
The planner receives the query tree from the rewriter and generates a plan tree. It is based on cost-based optimization.
Cost is just a number with no units to check the complexity of a process. It is a metric to analyse subsequent processes. In Postgres, it comprises of:

Startup Cost required to start a query. It is allocated before accessing the first tuple

Run Cost It is the cost to process all the tuples

Total Cost It is the sum of both startup cost and run cost.

Plan tree comprises of plan nodes that stores the information necessary for the subsequent operation to carry the actual implementation of the query.

Executor:

Executor takes up the plan nodes and carryout functions stored on each node. This is the step where the query is actually processed and functions are performed. It first carries out the sequential scan and then sorts the results

These are the brief descriptions about subsystems of postgres query. For a detailed explanation, you can visit this article: https://www.interdb.jp/pg/pgsql03.html

Top comments (0)