1. Query Processing • Query Processing is a
procedure of transforming a high-level query (such
as SQL) into a correct and efficient execution plan
expressed in low-level language. • When a
database system receives a query for update or
retrieval of information, it goes through a series of
compilation steps, called execution plan.
2. • Query processing goes through
various phases:
• first phase is called syntax checking phase, the
system parses the query and checks that it follows
the syntax rules or not. • It then matches the
objects in the query syntax with the view tables
and columns listed in the system table.
3. translated in to an algebraic
expression using various rules.
So that the process of
transforming a high-level
SQL query into a
relational algebraic form
is called Query
Decomposition
4. 1. Parsing and translation – Check
syntax and verify relations. – Translate the
query into an equivalent relational algebra
expression.
2. Optimization – Generate an optimal
evaluation plan (with lowest cost) for the
query plan.
3. Evaluation – The query-execution
engine takes an (optimal) evaluation plan,
executes that plan, and returns the
answers to the query.
5.
6. Query Processing Example
Example: Transformation of an SQL-query into an RA-query. Relations:
EMP(ENO, ENAME, TITLE), ASG(ENO,PNO,RESP,DUR)
– High level query:: SELECT ENAME FROM EMP,ASG WHERE EMP.ENO =
ASG.ENO AND DUR > 37
∗ Expression 1: ΠENAME ( σDUR>37 ∧EMP.ENO =ASG.ENO (EMP × ASG)) ∗
Expression 2: ΠENAME (EMP ⋊⋉ENO ( σDUR>37 (ASG)))
7. Join:::
is a combination of a Cartesian product followed by a selection process. A
Join operation pairs two tuples from different relations, if and only if a given
join condition is satisfied.
Theta (θ) Join
Theta join combines tuples from different relations provided they satisfy the
theta condition. The join condition is denoted by the symbol θ.
9. Student_Detail −
STUDENT ⋈Student.Std = Subject.Class SUBJECT
Student_detail
SID Name Std Class Subject
101 Alex 10 10 Math
101 Alex 10 10 English
102 Maria 11 11 Music
102 Maria 11 11 Sports
10. Natural join does not use any comparison operator. It does not
concatenate the way a Cartesian product does. We can perform a Natural
Join only if there is at least one common attribute that exists between two
relations. In addition, the attributes must have the same name and domain.
Natural join : (⋈)
11. Courses
CID Course Dept
CS01 Databas
e
CS
ME01 Mechani
cs
ME
EE01 Electroni
cs
EE
HoD
Dept Head
CS Alex
ME Maya
EE Mira
Courses ⋈ HoD
Dept CID Course Head
CS CS01 Database Alex
ME ME01 Mechanics Maya
EE EE01 Electronics Mira