Professional Documents
Culture Documents
End-Sem Solutions
1. TODO: ER Schema & Relational Schema
2. Relational algebra
(a)
fname,
minit,
lname,
address
smith ssn=superssn
smith ssn
ssn
fname=John
lname=Smith
employee
sex=female
employee
(i)
pname,
plocation
dnumber=dnum
dnumber
ssn=mgrssn
fname=George
lname=Mathew
employee
department
project
(ii)
(b) The expression
_
empid
(emp)
empid
_
emp
salary>sal
_
eid,sal
(emp)
_
__
returns employees with
lowest salary, when emp(empid, salary) is a non-empty relation.
3. Tuple relational calculus expressions
(a)
_
e.ssn, e.fname, e.minit, e.lname
employee(e)
p w
_
project(p) works on(w)
e.ssn = w.essn w.pno = p.pnumber p.pname = superJet
x
_
_
works on(x) x.pno = p.pnumber
_
_
x.hours w.hours
_
_
__
(b)
_
e.ssn, e.fname, e.minit, e.lname
employee(e)
d
_
_
dependent(d) (d.essn = e.ssn)
_
d.sex = female
__
4. SQL queries
(a) select x.pno
from (select w.pno
from works_on as w, employee as e
where e.fname = John and e.lname = Smith
and w.essn = e.ssn
) as x,
(select w.pno
from works_on as w, employee as e
where e.fname = Susan and e.lname = Smith
and w.essn = e.ssn
) as y
where x.pno = y.pno
;
1
(b) select w.pno, count(*) as fcount
from works_on as w, employee as e
where e.ssn = w.essn
and e.sex = female
group by w.pno
having count(*) >= 4
;
(c) select e.dno, count(*) as ecount, sum(dcount) as dcount
from employee as e,
(select d.essn, count(*) as dcount
from dependent as d
group by d.essn
) as x
where e.ssn = x.essn
group by e.dno
;
5. TODO: Disk access for nested-loop join & B
+
-tree index structure.
(a) TODO:
(b) TODO:
6. Functional dependency: State True or False.
(a) (True) A relation in which every key is a singleton is always in 2NF.
(b) (False) A relation scheme in 3NF cannot have any transitive dependencies.
(c) (False) Given a relation R and a set of FDs on it, a lossless, dependency-preserving decompo-
sition of R into BCNF relations can always be determined.
(d) (True) Any relation that has exactly two attributes is in BCNF.
(e) (True) Every functional dependency is also a multi-valued dependency.
(f) (True) Given the set of all FDs on a relation scheme, one can algorithmically determine the
keys of R.
7. Transaction processing
Some basics: Two operations in a schedule are said to be in conict if they belong to dierent
transactions and access same data and at least one of them is a write operation. So, by denition, 2
read operations can never be in conict. Three types of conict are recognized in schedules (a) Read
After Write (RAW); (b) Write After Read (WAR); and (c) Write After Write (WAW). A RAW
conict means a transaction writes some data that is subsequently read by another transaction i.e.
Read happens after Write. The WAR & WAW conicts have similar interpretation.
A Precedence Graph or Serialization Graph, of a schedule, is a directed graph where vertices represent
transactions and edges represent precedence relation between transactions. An edge is drawn from
T
1
to T
2
if an operation in T
1
precedes and conicts with some operation in T
2
. Self loops are absent
because conicts do not arise between operations in the same transaction.
A schedule is serializable if and only if the corresponding precedence graph is acyclic. A schedule S
is conict-serializable if it has a serial schedule S