Unit Iii & Iv
Unit Iii & Iv
A user has submitted a complex SQL query to your database, but it appears to be taking a long time to
execute. Implement analyzing the query to identify potential performance issues?
Compare query parsing and query analysis in the evaluation of relational algebra expressions and write
down the contribute to overall efficiency of query processing?
You are designing a new database system that needs to handle a variety of complex queries, but you are
not sure which optimization algorithm to use. How would you go about selecting the appropriate
algorithm for each query?
A user has submitted a query that involves a join between three tables: "Orders," "Customers," and
"Products." The query needs to find all orders placed by customers in a specific city, with details about
the products included in each order. Which join strategy would you use and why?
Suppose you have a complex relational algebra expression involving multiple operations, including
selection, projection, and join. How would you optimize the query to ensure the most efficient execution
plan is selected?
What is query equivalence and why is it important in database management? Provide examples of
queries that are equivalent.
Given a relation R( A, B, C, D, E) and Functional Dependency set FD = { A → B, B → E, C → D},
determine whether the given R is in 2NF? If not convert it into 2 NF.
Consider the following relational schema:Suppliers(sid:integer, sname:string, city:string, street:string)
Parts(pid:integer, pname:string, color:string)
Catalog(sid:integer, pid:integer, cost:real)
Assume that, in the suppliers relation above, each supplier and each street within a city has a unique
name, and (sname, city) forms a candidate key. No other functional dependencies are implied other than
those implied by primary and candidate keys. Identify the normalization and justify.
Derive the proof for the following Inference rules
X YZ, then X Y and X Z
X Y and X Z then X YZ
X Y and WY Z then WX Z
Suppose we have a relation R(A, B, C, D) and the functional dependencies A -> BC, B -> D, and C -> D
hold. Using Armstrong's axioms, can you determine whether the functional dependency AD -> B holds?
If so, provide a proof. If not, explain why not.
Consider the following relation:
Shipping(Shipname,Shiptype,VoyageID,Cargo,Port,Date)
Hint:Date refers arrival of ships at the given port.
With the functional dependencies
Shipname Shiptype
VoyageID Shipname,Cargo
Shipname,Date VoyageID, Port
(i) Identify the candidate keys (ii)Normalize to 2NF
(iii)Normalize to 3NF (iv) Normalize to BCNF
Examine the limitations of traditional concurrency control techniques in modern database systems, and
describe some emerging techniques that address these limitations.
Consider the following two transactions: T31: read(A); read(B); If A = 0 then B:=B+1; write(B). T32:
read(B); read(A); if B = 0 then A:=A+1; write(A). Add lock and unlock instructions to transactions T31
and T32, so that they observe the two-phase locking protocol. Can the execution of these transactions
result in a deadlock?
Examine the importance of continuous monitoring and optimization of queries in database management.
What tools and techniques are used for this purpose?
Consider the following schedules. The actions are listed in the order they are schedule, and prefixed
with transaction name. S1: T1: R(X), T2: R(x), T1: W(Y), T2: W(Y), T1: R(Y), T2: R(Y) S2:T3: R(X),
T1: R(X), T1: W(Y), T2: R (Z), T2: W (Z), T3: R (Z) For each of the schedules, answer the following
questions: i. What is the precedence graph for the schedule?
ii. Is the schedule view-serializable? If so, what are all the view equivalent serial schedules?
Check whether the above given schedule S is conflict serializable or not. If yes, then determine all the
possible serialized schedules.
Check whether the given schedule S is view serializable or not- Justify your answer.
(i) Given the following input (4322, 1334, 1471, 9679, 1989, 6171, 6173, 4199) and the hash function x
mod 10. Justify the following statements
i. 9679, 1989, 4199 hash to the same value
ii. 1471, 6171 hash to the same value
iii. All elements hash to the same value
iv. Each element hashes to a different value.
(ii)Consider a hash table with 100 slots. Collisions are resolved using chaining. Assuming simple
uniform hashing, what is the probability that the first 3 slots are unfilled after the first 3 insertions?
Construct a B-Tree with an order of 3 for the values 34,25,65,21,56,39,87 and show the tree structure
after the deletion of the values 56 & 21.
Consider the following relational schema: Suppliers(sid: integer,sname: char(20), city: char(20))
Supply(sid: integer, pid: integer) Parts(pid:integer,pname:char(20), price: real)
SELECT S.sname FROM Suppliers S WHERE S.sid NOT IN (SELECT C.sid FROM Catalog C
WHERE C.pid NOT IN (SELECT P.pid FROM Parts P WHERE
P.color=<>
Convert the given SQL into Relational Algebra Expression.
(i)Consider the following table
Dogs(did,dname,dob,weight)
Mushers(mid,mname)
Races(mid,did,raceNumber)
Write the SQL query and draw the query tree for the following
Find the names of dogs that have never participated in any races and age of the dogs is more than 5
years.
(ii) Consider the following SQL query for our bank database:
select T.branch-name from branch T, branch S where T.assets > S.assets and S.branch-city =
“Brooklyn” Write an efficient relational-algebra expression that is equivalent to this query.
(i)Suppose you have a large database with multiple tables and want to retrieve data from two of the
tables using a relational algebra expression. How would you optimize the query to ensure the most
efficient execution plan is selected?
(ii) Suppose a database has the following schema:
Trip(fromAddrId: INTEGER, toAddrId: INTEGER, date: DATE) Address(id: INTEGER, street:
STRING, townState: STRING)
(a) Write an SQL query that returns the street of all addresses in ’Stony Brook NY’ that are destination
of a trip on ’5/14/02’.
(b) Translate the SQL query in (a) into the corresponding “naive” relational algebra expression.
(c) Translate the relational algebra expression in (b) into an equivalent expression using pushing of
selections and projections.
(d) Translate the relational algebra expression in (c) into a most directly corresponding SQL query.
(i)Suppliers(sid: integer,sname: char(20), city: char(20)) Supply(sid: integer, pid: integer)
Parts(pid:integer,pname:char(20), price: real) and write an algorithm of SELECT operation in relational
algebra for cost-based query optimization.
(ii)Describe the materialization algorithm used in query optimization. How can it be used to reduce the
number of disk I/O operations required for query execution?
(i) A simple airline flight booking scenario implemented using micro service architecture. There would
be one micro service to block a seat, another to accept payments, and finally, another micro service to
allocate the blocked seat, each implementing a local transaction to realize their functionalities. To
successfully complete the flight booking process for a traveler, all three steps must be completed. If any
of the steps fails, all of the completed preceding steps must roll back. Sketch the challenges involved in
implementing concurrency control in for the above distributed databases.
(ii)Examine the techniques can be used to address these challenges?
Assume that you are using hashing for storage strategies.
(i) Insert the following data using extendible dynamic hashing:11,20,7,15,36,45,52 with a bucket size is
3
(ii)Illustrate the delete operation.
Consider the following log sequence of two transactions on a bank account, with initial balance 12000,
that transfer 2000 to a mortgage payment and then apply a 5% interest.
1. T1 start
2. T1 B old=12000 new=10000
3. T1 M old=0 new=2000
4. T1 commit
5. T2 start
6. T2 B old=10000 new=10500
7. T2 commit
Suppose the database system crashes just before log record 7 is written. When the system is restarted,
Discuss the recovery procedure in detail.
Suppose that we are using extendable hashing on a file that contains records with the following search-
key values: 2, 3, 5, 7, 11, 17, 19, 23, 29, 31 i)Show the extendable hash structure for this file if the hash
function is h(x) = x mod 8 and buckets can hold three records.
ii)Show how the extendable hash structure changes as the result of each of the following steps: a. Delete
11. b. Delete 31. c. Insert 1. d. Insert 15