0% found this document useful (0 votes)
4 views30 pages

Understanding Query Processing Steps

Uploaded by

premkannanmscds
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views30 pages

Understanding Query Processing Steps

Uploaded by

premkannanmscds
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Query Processing

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.
Query Processing
Parsing
Parsing
Example :
SELECT name FROM Students WHERE age > 18;
Correct → goes to next step

SELECT name Students WHERE age > 18;


Missing "FROM" → parser throws error
Translation
Translation
Example :
SELECT name FROM Students WHERE age > 18;
gets translated to: Relational Algebra form
π(name)(σ(age > 18)(Students))
Optimization
Optimization
Example :

SELECT * FROM Students WHERE age = 18;

Do a full table scan (slow)


Use an index on age column (fast)
DBMS chooses the index if available → faster
result
Evaluation (Execution)
Evaluation (Execution)
Example:
After planning
Example: Food Ordering System
Question
Find the names and prices of all items ordered
by customers in 'Coimbatore'.
Translation (Relational Algebra)
Optimization (Heuristic or Cost-Based)
The database optimizes the execution plan:
Push selection early:
• Apply location = 'Coimbatore' before joins.
• Choose join order based on table size and
indexes.
Optimized Relational Algebra

π(item_name, price)((Orders ⨝ (σ(location =


'Coimbatore')(Customers))) ⨝ Menu )
Translation (Relational Algebra)

Optimized Relational Algebra


π(item_name, price)((Orders ⨝ (σ(location =
'Coimbatore')(Customers))) ⨝ Menu )
Evaluation (Execution)
Sample Results
Sample Question: solve using Query
Optimization

QNS : Find the names of students


enrolled in the 'DBMS' course
Question: 2
Find the names of vendors who supply items with
quantity more than 40

Table 1: ITEM
Question: 2
Find the names of vendors who supply items with
quantity more than 40

Table 2: Vendors Table 3 :


supplies

You might also like