Advanced Course On Databases 2015 Exercises (10) : TH TH TH
Advanced Course On Databases 2015 Exercises (10) : TH TH TH
Exercises (10)
Submit your solutions on paper or by email before the examination that you plan to
participate. The examination dates are: 23.11.2015, Jan 2016 and Feb 2016 (to be
announced). At least 50% of the tasks should be solved acceptably.
Some of the tasks may require access to the textbook (Elmasri & Navathe: Fundamentals
of Database Systems, Pearson/Addison-Wesley, 4th, 5th or 6th ed.)
Exercise 1
Explain the meanings of the following multi-level SQL-queries and transform
them into single-level queries.
(a)
SELECT Pname, Plocation
FROM
PROJECT AS P
WHERE EXISTS
(SELECT *
FROM
DEPARTMENT AS D
WHERE Dname = 'Administration'
AND
P.Dnum = D.Dnumber)
(b)
SELECT Fname, Lname
FROM
EMPLOYEE AS E
WHERE Dno IN
(SELECT Dnumber
FROM
DEPARTMENT
WHERE Mgr_ssn IN
(SELECT Ssn
FROM
EMPLOYEE AS M
WHERE E.Lname = M.Lname))
The queries are related to the COMPANY database, described in the course textbook
(Figures 5.5-5.7 in the 4th and 5th ed., Figures 3.5-3.7 in the 6th edition). The relational
schema is as follows:
EMPLOYEE (Fname, Minit, Lname, Ssn, Bdate, Address, Sex, Salary, Super_ssn, Dno)
DEPARTMENT (Dname, Dnumber, Mgr_ssn, Mgr_start_date)
DEPT_LOCATIONS (Dnumber, Dlocation)
PROJECT(Pname, Pnumber, Plocation, Dnum)
WORKS_ON (Essn, Pno, Hours)
DEPENDENT (Essn, Dependent_name, Sex, Bdate, Relationship)
Exercise 2
Assume that a relational database contains a relation of persons:
Person (Pid, Name, FatherPid, MotherPid)
where FatherPid and MotherPid are the identifiers of the father and mother of the
current person. They are thus foreign keys, referring to the Person relation itself.
Write a query to determine all the descendants (children, grandchildren, etc.)
of a person named "John Adams".
You may use either extended SQL or some free-form pseudo language for the task.
Exercise 3
Assume that we have two relations, R (A, B, C) and S (C, D), where R.A and S.C are
primary keys, and R.C is a foreign key, referring to S.C.
The result of natural join of R and S is denoted by RS (A, B, C, D).
Assume that S has a primary B+-tree index on C, with depth = 3.
We also know the following quantities:
Number of tuples
Tuple size (bytes)
R
1 000 000
100
S
100 000
100
RS
1 000 000
150
The disk block size is 4096 bytes, and the buffer size is 10 blocks.
Estimate the number of disk accesses for the following join algorithms.
(a) Sort-merge join
(b) Index-based join
(As for buffering, you can assume a worst-case situation, i.e. no probabilistic calculations
are required.)
Exercise 4
Assume that we have the following relations in a university database:
Student(Sno, Sname, Address, MajorSubject)
Course (Cno, Cname, Credits)
Passed (Sno, Cno, Grade, Date)
with the obvious semantics. Assume further that the following SQL-query
should be processed:
SELECT
FROM
WHERE
AND
AND
AND
Credits, Grade
Student, Course, Passed
Sname = 'Smith'
Cname = 'Java'
Student.Sno = Passed.Sno
Course.Cno = Passed.Cno
Draw first the canonical query tree for this query and then convert
the tree stepwise, by applying the heuristic optimization algorithm.
(For refinement of query trees, see the textbook chapter on Query Optimization)
Exercise 5
Below the numbers 1 to 4 refer to concurrent transactions, while x and y are some data
units to be read (r) or written (w). Determine whether the following schedules are conflict
serializable or not. For those which are, derive the corresponding serial schedule.
(a) r1(x); r2(y); r1(y); w1(x); r3(x); r3(y); w2(y); w3(x); c2; c 1; c3;
(b) r1(x); r1(y); r2(y); r3(x); r3(y); w3(x); w1(y); r2(x); w2(y); c1; c2; c3;
(c) r1(x); w2(x); r4(x); r3(y); r1(y); w 4(x); r2(y); r4(y); w3(y); w3(x); c 4; c3; c2; c1;
Exercise 6
Let us study the following schedule:
r3(Y); r3(Z); r1(X); w1(X); w3(Y); w3(Z); r2(Z); r1(Y); w 1(Y); r2(Y); w2(Y); r2(X); w2(X);
Determine, whether the schedule is acceptable when using
(a) 2-phase locking protocol (2PL),
assuming that locks are reserved as late as possible, and released as early as possible.
Assume further that upgrading and downgrading of locks is allowed.
(b) Timestamp ordering protocol (TO),
assuming that the starting timestamps of transactions T 1, T2, and T3 are determined by
their first operation in the schedule, and each operation takes one time unit. Thus, T 3
starts at time 0, T 1 at time 2, and so on.
Exercise 7
Describe the recovery process for the following log contents (schedule), assuming that
the immediate update protocol (with checkpoints) is used. Specify, related to the system
crash, which of the transactions (T 1, T2, T3, T4) are rolled back, which operations are
undone, and which are redone, and whether any cascading rollback takes place. The
write_item entries in the log contain the before- and after-images (the numeric values) of
the written data item (one of A to D).
[start_transaction, T1]
[read_item, T 1, A]
[read_item, T 1, D]
[write_item, T1, D, 10, 20]
[commit, T1]
[checkpoint]
[start_transaction, T2]
[read_item, T 2, B]
[write_item, T2, B, 5, 12]
[start_transaction, T4]
[read_item, T 4, D]
[write_item, T4, D, 20, 15]
[start_transaction, T3]
[write_item, T3, C, 40, 30]
[read_item, T 4, A]
[write_item, T4, A, 30, 20]
[commit, T4]
[read_item, T 2, D]
[write_item, T2, D, 15, 25]
--- System crash! ---
Exercise 8
[Textbook exercise] Suppose that we have the following multilevel relation in a database
supporting mandatory multilevel access control. TC denotes the clearance level of the
whole tuple.
EMPLOYEE
Name
Smith
U
Smith
U
Jones
C
Salary
40000
C
40000
C
80000
S
JobPerformance
Fair
S
Excellent C
Good
C
TC
S
C
S
Exercise 9
Slide 200 of the lecture notes gives an example of a nested relation. On the basis of slides
in Section 8, do the following:
(a) Present the same content using XML.
(b) Convert the XML representation into a normal relation using non-typed nodes.
Exercise 10
One of the recent NoSQL approaches to data modeling is a column-oriented database.
Perform a web search and find answers to the following questions (no copy-paste,
please):
(a) What is the basic idea and purpose of the column-oriented model.
(b) How does it differ from the normal relational model?
(c) In what kind of applications is it currently used?
(d) Mention some existing column-oriented database management systems.