Query Processing:
Measuring Query
Cost
Query Processing
Query processing is the process of translating a
high-level query, such as SQL, into a low-level
query that can be executed by the database
system.
The steps involved are:
1. Parsing and translation.
2. Optimization.
3. Evaluation.
Steps in Query Processing
Query Cost
Query cost is the time taken by the query to hit
the database and return the result.
It involves query processing time i.e. time taken
to parse and translate the query, optimize it,
evaluate, execute and return the result to the
user
Factors in Measuring Query Cost
1
Disk access
The cost to access data from disk is
most important for large database
since the disk access are slow
compare to main memory access
2
CPU time
Time to execute the query code by
CPU
3
Communication time in Network
Time taken to the amount of data
transferred over the network during
a query execution
Measuring Query Cost
Why we prefer disk access for measure of query cost?
●
CPU speed > disk speed for executing a query. So it is difficult to
calculate with CPU time
Primarily considered with Distributed/ parallel system, it is difficult
to calculate transmit time in network
●
Query Cost: Disk access
No. of Seeks(N);
No. of blocks read;
No. of blocks write;
Cost = N x Avg Seek time
Cost = N x Avg block read cost
Cost = N x Avg block write cost
=> Disk Access cost is no of blocks transfer from disk and no of seeks
tT = time to transfer one block
tS = time for one to seek
Cost for b block transfers plus S seeks
= b * tT + S * tS
Best case: When all records resides in main memory
Worst case: When record resides in secondary memory or one part of record
resides in main memory and other in secondary memory
Thank you

DOC-20240720-WA0005.. query processing pptx

  • 1.
  • 2.
    Query Processing Query processingis the process of translating a high-level query, such as SQL, into a low-level query that can be executed by the database system. The steps involved are: 1. Parsing and translation. 2. Optimization. 3. Evaluation.
  • 3.
    Steps in QueryProcessing
  • 4.
    Query Cost Query costis the time taken by the query to hit the database and return the result. It involves query processing time i.e. time taken to parse and translate the query, optimize it, evaluate, execute and return the result to the user
  • 5.
    Factors in MeasuringQuery Cost 1 Disk access The cost to access data from disk is most important for large database since the disk access are slow compare to main memory access 2 CPU time Time to execute the query code by CPU 3 Communication time in Network Time taken to the amount of data transferred over the network during a query execution
  • 6.
    Measuring Query Cost Whywe prefer disk access for measure of query cost? ● CPU speed > disk speed for executing a query. So it is difficult to calculate with CPU time Primarily considered with Distributed/ parallel system, it is difficult to calculate transmit time in network ●
  • 7.
    Query Cost: Diskaccess No. of Seeks(N); No. of blocks read; No. of blocks write; Cost = N x Avg Seek time Cost = N x Avg block read cost Cost = N x Avg block write cost => Disk Access cost is no of blocks transfer from disk and no of seeks tT = time to transfer one block tS = time for one to seek Cost for b block transfers plus S seeks = b * tT + S * tS Best case: When all records resides in main memory Worst case: When record resides in secondary memory or one part of record resides in main memory and other in secondary memory
  • 8.