Query Optimization
Query Optimization
b.) Then it is parsed to look for syntactical errors and correctness of data types. If
the query passes this step, the query is decomposed into smaller query blocks.
Query Processing
Query processing is a set of all activities starting from query placement to displaying
the results of the query. The steps are as shown in the following diagram −
Relational Algebra :
Relational algebra defines the basic set of operations of
relational database model.
2. Selection
3. Join
Join operation combines related tuples of two different tables (results of
queries) into a single table.
Notation : R ⋈θ S
Where R is the first relation
S is the second relation
EMPLOYEE ⋈ θ
MIN_EXPERIENCE from DEPARTMENT.
Syntax
EMPLOYEE.EXPERIENCE>=DEPARTMENT.MIN_EXPERIENCE DEPARTMENT
πp (R ⋈ R.P = S.P S)
Example 1: Consider a relational algebra expression:
Step 1: Write the relations you want to execute as the tree’s Leaf nodes. Here R and S are the relations.
Step 2: Add the condition (here R.P = S.P) with the relational algebra operator as an internal node (or
parent node of these two leaf nodes).
JOIN R and S where R.P = S.P
Step 3: Now add the root node that on execution gives the output of the query.
Code generation is the final step in query optimization. It is the executable form of
the query, whose form depends upon the type of the underlying operating system.
Once the query code is generated, the Execution Manager runs it and produces the
results.