Professional Documents
Culture Documents
Database Management
Systems
Unit-5
Query Processing
and Optimization
Topics to be covered
• Overview (Query Processing)
• Measures of query cost
• Evaluation of expressions
• Query optimization
• Transformation of relational expressions
• Sorting and join
Database Catalog
Data Statistics about Data
1. Materialization
2. Pipelining
2
Bottom to top
Execution
1
Balance<2500 customer
account
Unit – 5: Query Processing & Optimization 14
Pipelining
In pipelining, operations form a queue, and results are passed from
one operation to another as they are calculated.
To reduce number of intermediate temporary relations, we pass
results of one operation to the next operation in the pipelines.
Combining operations into a pipeline eliminates the cost of reading
and writing temporary relations.
Pipelines can be executed in two ways:
1. Demand driven : In this method, the result of lower level queries are not
passed to the higher level automatically. It will be passed to higher level only
when it is requested by the higher level.
2. Producer driven : In this method, the lower level queries eagerly pass the
results to higher level queries. It does not wait for the higher level queries to
request for the results.
It uses temporary relations for storing the It does not use any temporary relations for
results of the evaluated operations. So, it storing the results of the evaluated
needs more temporary files and I/O. operations.
It is less efficient as it takes time to generate It is a more efficient way of query evaluation
the query results. as it quickly generates the results.
It does not have any higher requirements for It requires a high rate for generating
query evaluation. outputs.
The overall cost includes the cost of It optimizes the cost of query evaluation. As
operations plus the cost of reading and it does not include the cost of reading and
writing results on the temporary storage. writing the temporary storages.
Customer Output
Cid Ano Cust_name Balance Cid Ano Cust_name Balance
C01 1 Raj 3000 C02 2 Meet 1000
C02 2 Meet 1000
C03 3 Harsh 2000
C04 4 Punit 4000
σ θ (E1 E2) = E1 θ E2
E1 θ E2 = E2 θ E1
E1 U E2 = E2 U E1
E1 ∩ E2 = E2 ∩ E1
Unit – 5: Query Processing & Optimization 29
Transformation of relational expressions
9. Set operations union and intersection are associative.
Union Intersect
Customer Employee Student Output Output
Cust_name Emp_name Emp_name Name Name
Raj Meet Raj Raj Meet
Meet Suresh Meet Meet
Suresh
Table A
[Inner Table] Table B Output
[Outer Table]
2 1
4
4
4
6 7
7 5
9 1
7
1
R
S