Exercise 5.1.1
As a set:
speed
2.66
2.10
1.42
As a bag:
speed
2.66
2.10
1.42
2.80
3.20
3.20
2.20
2.20
2.00
2.80
1.86
2.80
3.06
Exercise 5.1.2
As a set:
2.80
3.20
2.00
1.86
3.06
hd
250
80
As a bag:
hd
250
250
80
250
250
320
200
250
250
300
160
160
80
Exercise 5.1.3a
As a set:
bore
15
16
14
18
320
200
300
160
As a bag:
bore
15
16
Exercise 5.1.3b
πbore(Ships Classes)
Exercise 5.1.4a
For bags:
On the left-hand side:
Given bags R and S where a tuple t appears n and m times respectively, the union of bags
Exercise 5.1.4b
For bags:
On the left-hand side:
14
16
15
15
18
Given bags R and S where a tuple t appears n and m times respectively, the intersection
of bags R and S will have tuple t appear min( n, m ) times. The further intersection of bag
T with the tuple t appearing o times will produce tuple t min( o, min( n, m ) ) times in the
final result.
Exercise 5.1.4c
For bags:
On the left-hand side:
Given that tuple r in R, which appears m times, can successfully join with tuple s in S,
which appears n times, we expect the result to contain mn copies. Also given that tuple t
The order in which we perform the natural join does not matter for bags.
For sets:
This is a similar case when dealing with bags except the joined tuples can only appear at most
Exercise 5.1.4d
For bags:
Suppose a tuple t occurs n and m times in bags R and S respectively. In the union of these two
bags R S, tuple t would appear n + m times. Likewise, in the union of these two bags S R,
Exercise 5.1.4e
For bags:
Suppose a tuple t occurs n and m times in bags R and S respectively. In the intersection of these
Exercise 5.1.4f
For bags:
Suppose a tuple t occurs n times in bag R and tuple u occurs m times in bag S. Suppose also that
the two tuples t,u can successfully join. Then in the natural join of these two bags R S, the
Exercise 5.1.4g
For bags:
Suppose tuple t appears m times in R and n times in S. If we take the union of R and S first, we
will get a relation where tuple t appears m + n times. Taking the projection of a list of attributes L
Exercise 5.1.4h
For bags:
Suppose tuple t appears u times in R, v times in S and w times in T. On the left hand side, the
intersection of S and T would produce a result where tuple t would appear min(v , w) times. With
Exercise 5.1.4i
Suppose that in relation R, u tuples satisfy condition C and v tuples satisfy condition D. Suppose
Exercise 5.1.5a
For sets, an arbitrary tuple t appears on the left hand side if it appears in both R,S and not in T.
Exercise 5.1.5b
For sets, an arbitrary tuple t appears on the left hand side if it appears in R and either S or T. This
Exercise 5.1.5c
For sets, an arbitrary tuple t appears on the left hand side if it satisfies condition C, condition D
or both condition C and D. On the right hand side, σC(R) selects those tuples that satisfy
Exercise 5.2.1a
A+B
A2
B2
1
0
1
5
4
9
Exercise 5.2.1b
B+1
C-1
1
0
3
3
3
4
4
3
1
1
4
3
Exercise 5.2.1c
A
B
0
1
0
1
2
3
2
4
3
4
Exercise 5.2.1d
B
C
0
1
0
2
2
4
2
5
3
4
1
0
1
6
4
7
9
Exercise 5.2.1e
A
B
0
1
Exercise 5.2.1f
B
C
0
1
2
4
2
5
3
4
0
2
Exercise 5.2.1g
A
SUM(B)
0
2
3
Exercise 5.2.1h
B
0
2
3
Exercise 5.2.1i
A
0
2
3
Exercise 5.2.1j
2
3
2
4
3
4
A
MAX(C)
Exercise 5.2.1k
A
B
C
2
3
4
2
3
4
0
1
2
4
3
4
Exercise 5.2.1l
A
B
C
2
3
4
2
3
4
0
1
2
5
0
2
Exercise 5.2.1m
A
B
C
2
3
4
2
3
4
0
1
2
4
3
4
0
1
2
4
2
5
2
Exercise 5.2.1n
A
R.B
S.B
C
0
1
2
4
0
1
2
5
0
1
3
4
Exercise 5.2.2a
Applying the δ operator on a relation with no duplicates will yield the same relation. Thus δ is
idempotent.
Exercise 5.2.2b
Exercise 5.2.2c
The result of σC is a relation where condition C is satisfied by every tuple. Performing the
Exercise 5.2.2d
The result of γL is a relation whose schema consists of the grouping attributes and the aggregated
attributes. If we perform the same grouping operation, there is no guarantee that the expression
0
1
3
4
0
1
2
4
0
1
2
5
0
1
3
4
0
1
3
4
2
3
2
4
3
4
0
1
0
2
Exercise 5.2.2e
The result of τ is a sorted list of tuples based on some attributes L. If L is not the entire schema
Exercise 5.2.3
If we only consider sets, then it is possible. We can take πA(R) and do a product with itself. From
this product, we take the tuples where the two columns are equal to each other.
Exercise 5.3.1
a) Answer(model) ← PC(model,speed,_,_,_) AND speed ≥ 3.00
b) Answer(maker) ← Laptop(model,_,_,hd,_,_) AND Product(maker,model,_) AND hd ≥
100
c) Answer(model,price) ← PC(model,_,_,_,price) AND Product(maker,model,_) AND
g) Answer(model1,model2) ← PC(model1,speed, ram,_,_) AND
PC(model2,_speed,ram,_,_) AND model1 < model2
h) FastComputer(model) ← PC(model,speed,_,_,_) AND speed ≥ 2.80
FastComputer(model) ← Laptop(model,speed,_,_,_,_) AND speed ≥ 2.80
PCs(maker,speed2) AND speed <> speed1 AND speed <> speed2 AND speed1 <>
speed2
k) PCs(maker,model) ← Product(maker,model,type) AND type=’pc’
Answer(maker) ← PCs(maker,model) AND PCs(maker,model1) AND
PCs(maker,model2) AND PCs(maker,model3) AND model <> model1 AND model <>
Exercise 5.3.2
a) Answer(class,country) ← Classes(class,_,country,_,bore,_) AND bore ≥ 16
b) Answer(name) ← Ships(name,_,launched) AND launched < 1921
f) Answer(name) ← Ships(name,_,_)
Answer(name) ← Outcomes(name,_,_) AND NOT Answer(name)
g) MoreThanOne(class) ← Ships(name,class,_) AND Ships(name1,class,_) AND name <>
name1
Answer(class) ← Classes(class,_,_,_,_,_) AND NOT MoreThanOne(class)
Exercise 5.3.3
Answer(x,y) ← R(x,y) AND z = z
Exercise 5.4.1a
Exercise 5.4.1b
Answer(a,b,c) ← R(a,b,c) AND S(a,b,c)
Exercise 5.4.1c
Exercise 5.4.1d
Exercise 5.4.1e
Exercise 5.4.1f
Answer(a,b) ← R(a,b,_)
Exercise 5.4.1g
Exercise 5.4.2a
Exercise 5.4.2b
Answer(x,y,z) ← R(x,y,z) AND x < y AND y < z
Exercise 5.4.2c
Exercise 5.4.2d
Change: NOT(x < y OR x > y)
Exercise 5.4.2e
Change: NOT((x < y OR x > y) AND y < z)
Exercise 5.4.2f
Change: NOT((x < y OR x < z) AND y < z)
Exercise 5.4.3a
Exercise 5.4.3b
Answer(b,c,d,e) ← S(b,c,d) AND T(d,e)
Exercise 5.4.3c
Exercise 5.4.4
a) Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx = sy
b) Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx < sy AND ry < sz
Exercise 5.4.5a
R1 := πx,y(Q R)
Exercise 5.4.5b
Exercise 5.4.5c