IT3020 - DS 2022 June
IT3020 - DS 2022 June
Duration: 2 Hours
June 2022
Instructions to Candidates:
This paper is preceded by a 10-minute reading period. The supervisor will indicate
when answering may commence.
This paper contains 4 questions. Answer All Questions.
Use the booklets given to provide answers.
Total marks för the paper will be 100.
A mark for each question is mentioned in the paper.
This paper contains 6 pages with the Cover Pager.
Electronic devices capable of storing and retrieving text, including calculators and
mobile phones are not allowed.
00750
Object types:
Customer_t (cid: char(7), name: varchar(1 5), phone: varchar(10))
Schedule_t (flightno:char(6), dep[ime:char(6), source: varchar(12), destination: varchar(12), capacüy:
integer)
Booking_t (passenger: ref customer_t, ticketno: char(10), fare: float)
Passenger.list table of booking_t
Flight_t (flight: ref schedule t, depdate: date, passengers: passenger_list)
Table:
Customers of customer_t (cid primary key)
Schedules of schedule_t (flightno primary key)
Flights offlight_t (flight not null references schedule, depdate not null)
Nested table passengers store as passengerlist_ntab
The customers table of customer_t has attributes of customer id (cid), name, and phone. It contains tuples
for all customers. Schedules table of schedule_t contains tuples for all scheduled flights, and has the
attributes flight number (flightno), departure time at source (deptime), source and destination of the flight,
and seating capacity. The flights table of flight t records the information of an actual flight on a particular
date and consists of attributes for flight reference, date of departure (depdate), and a nested table of
passenger details. The nested table contains passenger reference, ticket number (ticketno), and the fare
charged for the given flight. The attrib-oz types are specified in the type descriptions above. The primary
keys and referential constraints are shown in the table schema. Note that date literals can be specified in
SQL statements as 'DD-MM-YY'
(a) Write Oracle OR-SQL statements for the following queries (use columns of REF type instead of
joins to link tables).
(i) Find the cheapest flight from Colombo to London in 15th of October 2021.
SELECT MIN(f.flight.fare) AS cheapest_fare
FROM Flights f
WHERE f.flight.source = 'Colombo' AND f.flight.destination = 'London'
AND f.depdate = TO_DATE('15-10-2021', 'DD-MM-YYYY');
(4 marks)
(ii) Find the total fare collected from passengers booked on each flight departing London for
Colombo on 25 December 2021. Display the flight number, and the total fare.
Page 2 of 9
00750
(b) Add a new passenger to flight number 'QR09' departing on 25 th of May, 2022. This passenger exists
in the customers table with cid of 'AW35462'. The ticket number for this passenger is 'LASTI and the
fare LKR85000.
(c) It is required to add a member method called passcounl to calculate the number of passengers on a
flight. Write Oracle SQL statements to modify the object type flight t by adding this method
specification.
(d) Using the method defined above, write an Oracle SQL statement to display the number of available
seats on flights from Colombo to Singapore on of June 2022. The number of available seats is the
difference between the capacity of a flight and the current number of passengers booked to travel.
Display the flight number, departure time, and the number of available seats.
(a) Compare and contrast the heap and sequential file organization approaches.
Page 3 of 9
00750
(3 marks)
(b) Consider a employees relation containing records with employee id, name, age, salary and
department number. Assume that the records are stored in a sequential file where records are ordered based
on the employee's id.
"The aforementioned file makes it inefficient to get records with salaries ranging from Rs.20,000 to IQs.
30,000."State whether the statement above is true or false with reasons.
(5 marks)
(c) Briefly explain two disadvantages that exist in static hashing.
Insertion can create long overflow chains – use Extendible to fix the problem.
Deletion may waste space – use Linear Hashing to fix the problem.
(3 marks)
(e) Explain the terms dense and sparse index.
Dense
In a dense index, an index entry exists for every record in the data file.
The index contains a key value and a pointer to the corresponding record.
Sparse Index
In a sparse index, not every record in the data file has an index entry.
The index contains a subset of key values from the data file, along with pointers to
the corresponding records.
Allows for faster access to specific records compared to a full scan of the data file.
(3 marks)
Consider the B+ tree index below.
Page 4 of 9
00750
01
10
11
46
Bucket A
Bucket D
(5 marks)
Question 3 (25 marks)
The goal of query optimization is to find the most efficient execution plan for a given database
query.
(3 marks)
i. How many different join orders, assuming that cross products are disallowed, will a System R
style query optimizer consider when deciding how to process the given query? List each of these
join orders.
(3 marks)
Page 5 of 9
00750
ii. What indexes might be of help in processing this query? Explain briefly.
(4 marks)
iii. How does adding DISTINCT to SELECT clause affect the plans produced?
(3 marks)
iv. Estimate the I/O cost of retrieving records from Parts table that contains price less than or equal
1000 rupees. Assume that 15% of tuples satisfy the selection criteria. There are 3300 pages in the
Parts table, with 50 records each page. The clustered B+ tree index on price attribute is the only
index available in the Parts table. This index takes up 1/3 of the table's space.
(8 marks)
v. Estimate the I/O cost of sorting 200 pages of Suppliers table using 10 buffer frames.
(4 marks)
(a) Why do DBMSs interleave actions of multiple transactions? Briefly explain your answer.
(l marks)
T1: Read(A) T2: Read(A) T2: Write(A) T1: Write(A) T2: Abort
Explanation:
Page 6 of 9
00750
(3 marks)
(c) Briefly explain the terms deadlock prevention and deadlock detection. Explain approaches for each
methodology.
Deadlock Prevention: Deadlock prevention aims to avoid the occurrence of deadlocks by
structuring the system in a way that makes it impossible for the necessary conditions for a
deadlock to arise. Two common approaches for deadlock prevention are,
1. Resource Ordering
2. Resource Allocation Policies
Deadlock Detection: Deadlock detection involves periodically checking the system for the
presence of deadlocks after they occur. Two primary approaches for deadlock detection are,
1. Resource Allocation Graph (RAG)
2. Wait-for Graph
(3 marks)
(d) Consider the following part of the schedule.
Page 7 of 9
00750
Assume that Transaction Ti is higher priority than transaction Ti+l(i.e. transaction Tl has higher
priority than T2', T2 has higher priority than T3•, and T3 has higher priority than TO.
ii. What should do next for deadlocks detection approach to break the deadlock after identify
it?
(l mark)
111 . Draw the schedule again considering deadlock prevention algorithm: Wait-Die
approach
(4 marks)
Page 8 of 9
00750
Database D
P-1
"+1
Relation R
p Tuple tr
Database D contains a relation R. Relation R contains a page P. Page P contains a tuple tr.
Assume that multiple granularity locking scheme is used. Describe the locks acquired when reading
all tuples of page P.
(3 marks)
Page 9 of 9