0% found this document useful (0 votes)
16 views

IT3020 - DS 2022 June

The document discusses a database schema for an airline with tables for customers, schedules, flights and bookings. It includes Oracle SQL statements for queries on flight schedules and bookings. Methods are added to calculate passenger counts on flights. The number of available seats on flights is displayed. Comparison of heap and sequential file organization is provided along with examples of B+ tree and hash indexes.

Uploaded by

jathurshanm3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

IT3020 - DS 2022 June

The document discusses a database schema for an airline with tables for customers, schedules, flights and bookings. It includes Oracle SQL statements for queries on flight schedules and bookings. Methods are added to calculate passenger counts on flights. The number of available seats on flights is displayed. Comparison of heap and sequential file organization is provided along with examples of B+ tree and hash indexes.

Uploaded by

jathurshanm3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

00750

Sri Lanka Institute of Information Technology

B. Sc. Honours Degree in


Information Technology
Final Examination
Year 3, Semester I

IT3020 — Database Systems

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

Question 1 (25 marks)


Consider the following object relational schema for a database of ABC Airline.

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.

SELECT f.flight.flightno, SUM(f.flight.fare) AS total_fare


FROM Flights f
WHERE f.flight.source = 'London' AND f.flight.destination = 'Colombo'
AND f.depdate = TO_DATE('25-12-2021', 'DD-MM-YYYY')
GROUP BY f.flight.flightno;
(4 marks)

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.

INSERT INTO Flights


VALUES (
Flight_t(
(SELECT REF(s) FROM Schedules s WHERE s.flightno = 'QR09'),
TO_DATE('25-05-2022', 'DD-MM-YYYY'),
passenger_list_ntab(
Booking_t(
(SELECT REF(c) FROM Customers c WHERE c.cid = 'AW35462'),
'LASTI',
85000.00
)
)
)
);
(5 marks)

(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.

ALTER TYPE Flight_t ADD MEMBER FUNCTION passcount RETURN INTEGER;


(7 marks)

(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.

SELECT f.flight.flightno, f.flight.deptime,


f.flight.capacity - f.flight.passengers.COUNT() AS available_seats
FROM Flights f
WHERE f.flight.source = 'Colombo' AND f.flight.destination = 'Singapore'
AND f.depdate = TO_DATE('01-06-2022', 'DD-MM-YYYY');
(4 marks)

Question 2 (25 marks)

(a) Compare and contrast the heap and sequential file organization approaches.

Heap File Organization Sequential File Organization


Data is stored in a heap without any Data is stored in a sequential order based

Page 3 of 9
00750

particular order. on a specified key field.


Insertion and deletion operations are Insertion and deletion operations are less
relatively efficient. efficient.
Random access to individual records is not Random access to individual records is
efficient efficient

(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.

i. Illustrate the tree after inserting 31 and 33.


(3 marks) 11.
illustrate the tree after deleting 2 and 3 from the original tree.
(3 marks)
(f) Consider the Hash index below. Illustrate the hash index after inserting 50.

Page 4 of 9
00750

01
10
11

46

Bucket A
Bucket D

(5 marks)
Question 3 (25 marks)

(a) What is the goal of query optimization? Why is it important?

The goal of query optimization is to find the most efficient execution plan for a given database
query.

Importance of query optimization:

 Improving performance: Query optimization helps to minimize the execution time of


queries, making database operations more efficient and responsive.
 Resource utilization: It aims to optimize the utilization of system resources such as
CPU, memory, and disk I/O, reducing the overall system load.
 Cost reduction: By finding optimal execution plans, query optimization reduces the
need for unnecessary disk accesses or expensive operations, resulting in cost savings.

(3 marks)

(b) Consider the following relational schema and SQL query.


Suppliers (Sid: integer, sname: char(20), city: char(20))
Supply (Sid: integer, pid: integer)
Part (pid: integer, pname: char(20), price: real)

SELECT s.sname, p.pname


FROM Suppliers s, Parts p, Supply y
WHERE s.sid = y.sid AND y.pid = p.pid AND p.price 1000

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)

Question 4 (25 marks)

(a) Why do DBMSs interleave actions of multiple transactions? Briefly explain your answer.

DBMSs interleave the actions of multiple transactions to improve performance. By


interleaving transactions, the DBMS can use the CPU more efficiently and reduce the
amount of time that users have to wait for their transactions to complete.

Here are some of the benefits of interleaving transactions:

 Increased throughput: Interleaving transactions can increase the throughput of a


database system by allowing multiple transactions to execute concurrently.
 Reduced latency: Interleaving transactions can reduce the latency of a database
system by allowing users to begin using the data that has been modified by other
transactions sooner.

(l marks)

(b) Show a schedule that is unrecoverable? Briefly explain the schedule.


A schedule is considered unrecoverable if it leads to a situation where a transaction
reads a value that is later overwritten by another transaction that aborts. This means
that the first transaction cannot be rolled back to its initial state, resulting in an
unrecoverable state.

T1: Read(A) T2: Read(A) T2: Write(A) T1: Write(A) T2: Abort

Explanation:

 Transaction T1 reads the initial value of data item A.

Page 6 of 9
00750

 Transaction T2 also reads the same initial value of data item A.


 Transaction T2 writes a new value to data item A.
 Transaction T1 writes a different value to data item A, overwriting the value written
by T2.
 Transaction T2 aborts, meaning its changes are rolled back.

(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.

i. Draw a Wait-For-Graph for the given schedule above.


(2 marks)

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)

(e) Briefly explain Simple Tree Locking algorithm.


(4 marks)
(f) Consider the following B+ tree. Follow Simple Tree Locking Algorithm and specify when and what
lock get and release to do the followings.

Page 8 of 9
00750

i. Search 1 1. (l marks) Delete 99.


(l .5 marks) iii.
Insert 30.
(l .5 marks)

(g) Consider the following scenario:

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)

- End of the Question Paper -

Page 9 of 9

You might also like