What is query processing and optimization in DBMS?

The activities involved in parsing, validating, execution and optimizing a query is called Query Processing.


The steps involved in query processing and optimization are as follows −

  • A sequence of primitive operations that can be used to evaluate a query is called query execution plan or query evaluation plan.

  • The query execution engine takes a query evaluation plan, executes that plan and produces the desired output. The different execution plans for a given query can have different costs based on the number of disks. It is the responsibility of the system to construct a query evaluation plan which minimizes the cost of query evaluation. This task is called query optimization.

  • A query optimization is expressed in high level query language and is scanned, parsed and validated. The scanner identifies the SQL keywords, attributes and relation names in the text of the query.

  • The parser checks the syntax which is used to determine if the query is formulated according to syntax rules of the query language.

  • Finally, the query is evaluated by checking that all attributes and relation names are valid and semantically meaningful in the schema of a particular database.

  • An internal representation of the query is then created which is either a tree or a graph known as query tree or query graph.

  • If the query written SQL is translated into relational algebra, then its internal representation is a query tree. Otherwise, if TRC or DRC its internal representation is a query graph. A graph has many possible execution strategies and the process of choosing a strategy with minimum cost is called query optimization.

The query processing and optimization in the DBMS are explained in the form of a diagram below −

Updated on: 06-Jul-2021

13K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started