SQL Query Processing

Introduction to Query Processing

  • Query Processing is a translation of high-level queries into low-level expression.
  • It is a step wise process that can be used at the physical level of the file system, query optimization and actual execution of the query to get the result.
  • It requires the basic concepts of relational algebra and file structure.
  • It refers to the range of activities that are involved in extracting data from the database.
  • It includes translation of queries in high-level database languages into expressions that can be implemented at the physical level of the file system.
  • In query processing, we will actually understand how these queries are processed and how they are optimized.
query processing

In the above diagram,
  • The first step is to transform the query into a standard form.
  • A query is translated into SQL and into a relational algebraic expression. During this process, Parser checks the syntax and verifies the relations and the attributes which are used in the query.
  • The second step is Query Optimizer. In this, it transforms the query into equivalent expressions that are more efficient to execute.
  • The third step is Query evaluation. It executes the above query execution plan and returns the result.

Translating SQL Queries into Relational Algebra

Example

SELECT Ename FROM Employee
  WHERE Salary > 5000;


Translated into Relational Algebra Expression

σ Salary > 5000 (π Ename (Employee))
                                        OR
π Ename (σ Salary > 5000 (Employee))

query execution plan

  • A sequence of primitive operations that can be used to evaluate a query is a Query Execution Plan or Query Evaluation Plan.
  • The above diagram indicates that the query execution engine takes a query execution plan and returns the answers to the query.
  • Query Execution Plan minimizes the cost of query evaluation.