UT 1 QB Solution
UT 1 QB Solution
Module - 1
Q. What do you mean by Query Processing in dbms.
Ans: - The database is used to store the data at one place.
- This data is accessed and manipulated by the users.
- The process of accessing and manipulating the data should be done efficiently i.e., it
should be accessed easily and quickly.
- To access the data user has to communicate with database.
- User request for the data in language like SQL. SQL is a high level language but the
underlying systems in the DBMS do not understand SQL.
- There has to be some low level language to which these systems can understand. Hence,
request query is accepted in SQL and converted into low level language, this process is
known as query processing.
- Query processing is defined as the set of activities performed to convert SQL high level
queries into low level languages and then retrieve data from database by using this low
level language.
Q. What are the steps of query processing.
Ans: Steps of query processing:
- The set of activities are known as the steps involved in query processing which are
explained below:
- 1] Parsing and translation
- 2] Optimization
- 3] Evaluation
Page 1
○ In high level language, the query is represented as a string.
○ This sentences of characters may present various types of tokens like
keywords, operators, operands, literal strings, etc.
○ The parser extracts the tokens from the sequence of characters and translates
them into the related internal data elements and structures .
2] Optimizing the Query:
○ This is the second stage of query processing in which the query processor
applies rules to the internal data structures of the query to transform them
into equivalent representation which are more efficient.
○ These rules are based on mathematical models of the relational algebra
expression.
○ The main function of the query optimization engine is to select correct rules
to apply, situation to apply these rules and format to apply them.
3] Evaluating the Query:
○ This is the last step in query processing in which best evaluation plan created
by the optimization engine is selected and then performed.
○ There are various methods to execute the query.
○ A whole query can be executed or small parts of query can be executed
simultaneously.
○ The important thing is that the results of all the methods should be same.
Q. What do you mean by query optimization
Ans: - Query optimization is an essential for many DBMS in which best query execution plan,
out of multiple alternative query execution plans is to be identified for solving efficiently.
- Query optimization is nothing but selecting the efficient query execution plan among the
available query plans for solving a given query.
- The query plan is constructed based on multiple cost factors.
- Query optimization tries to select query plan which is lower processing cost.
- Query optimization come into picture when we want to develop a good system to
minimize the cost of query evaluation.
Q. How will you measure query cost.
Ans: Measuring cost of query:
- To evaluate a query, there are many plans available bit it is very important to
select the best plan in terms of its estimated cost.
- A query is consist of multiple operations.
- Estimated the cost of each operations will give us the total cost of a query.
- The sum of costs of all these operations will give us the total cost of a query.
1. The factors affecting the cost of query are as follows:
a. Number of different resources including disk accesses
b. CPU time to execute a query
c. In a distributed or parallel database system, the cost of communication.
2. In case of large database, the most important cost is the cost to access data from
disk because the disc access is slow as compare to in-memory operations.
3. To measure the query cost, it use the number of block transfers from disk and the
count of disks seeks to estimate the cost of a query - evaluation plan. Consider the
Page 2
count of disks seeks to estimate the cost of a query - evaluation plan. Consider the
disk subsystem takes an average of tT seconds to transfer a block of data and the
average block access time od tS seconds, then operations b blocks and performs S
seeks would take:
Time = b*tT+S*tS seconds.
Where, tT- Time to transfer one block.
tS - Time for one seek
Cost for b blocks transfers plus S seeks. Here ignore CPU costs for simplicity. Real
systems do take CPU cost into account. We do not include cost to writing output
to disk in our cost formulae.
4. In our cost estimation, the cost of writing the final result of an operation back to
disk is not included. As per requirements it can be added separately. In our case
cost of all the algorithms is depending upon the size of the buffer in main memory.
5. In best case the whole data is read into buffer and there is no need of access of the
disc again. In worst case it is assumed that the disc can store only few blocks of
data approximately one block per relation. The worst case is generally assumes
while calculating the cost estimates.
Q. Assume an operation transfers 100 blocks and perform 20 seeks. The average block tT is
0.1ms and the average seek time tS is 4ms. Calculate the total time required for the
operation. (tT = transfer time per block, tS = seek time per seek, S = for number of disk
seeks)
Ans: b = 100 blocks,
tT = 0.1ms,
S = 20 seeks,
tS = 4ms,
Page 4