Relational Algebra · Databases
31 questions · asked in 19 of 27 years (2000–2026)
MCQ 27 · MSQ 1 · NAT 31-mark 17 · 2-mark 14
2000Questions per year2026
Questions 6–10 of 31
Consider the relations r(A, B) and s(B, C), where s.B is a primary key and r.B is a foreign key referencing s.B. Consider the query
Let LOJ denote the natural left outer-join operation. Assume that r and s contain no null values.
Which one of the following queries is NOT equivalent to Q?
Let LOJ denote the natural left outer-join operation. Assume that r and s contain no null values.
Which one of the following queries is NOT equivalent to Q?
Answer: (C)
Q keeps only the r-tuples whose B value is 5, joined with s.
- (A) filters after the join, which gives the same rows as Q.
- (B) Every r.B value is present in s because of the foreign key, and r has no nulls. So every r-tuple finds a match, the outer join adds no padded rows, and . Then the filter gives Q.
- (D) keeps r-tuples with B 5, and each one finds its match in s. This is Q.
- (C) keeps every r-tuple. Those with B 5 find no match in the filtered s, so they stay in the result padded with NULLs. These extra rows are not in Q.
Answer: (C)
- (A) filters after the join, which gives the same rows as Q.
- (B) Every r.B value is present in s because of the foreign key, and r has no nulls. So every r-tuple finds a match, the outer join adds no padded rows, and . Then the filter gives Q.
- (D) keeps r-tuples with B 5, and each one finds its match in s. This is Q.
- (C) keeps every r-tuple. Those with B 5 find no match in the filtered s, so they stay in the result padded with NULLs. These extra rows are not in Q.
Answer: (C)
Consider a database that has the relation schema CR (StudentName, CourseName). An instance of the schema CR is as given below.
The following query is made on the database
The number of rows in T2 is ____________.
The following query is made on the database
The number of rows in T2 is ____________.
Answer: 4
T1 is the set of courses taken by SA, which is {CA, CB, CC}. T2 is the set of students who take all of these courses:
- SA: yes. SB: no, because there is no CA. SC: yes. SD: yes. SE: no, because there is no CC. SF: yes.
Answer: 4
- SA: yes. SB: no, because there is no CA. SC: yes. SD: yes. SE: no, because there is no CC. SF: yes.
Answer: 4
Consider two relations R1(A,B) with the tuples (1,5), (3,7) and R2(A,C) = (1,7), (4,9). Assume that R(A,B,C) is the full natural outer join of R1 and R2. Consider the following tuples of the form (A,B,C): a = (1,5,null), b = (1,null,7), c = (3, null, 9), d = (4,7,null), e = (1,5,7), f = (3,7,null), g = (4,null,9). Which one of the following statements is correct?
Answer: (C)
Join on A:
- A = 1 is in both tables: (1, 5, 7) e
- (3, 7) from R1 finds no partner: (3, 7, null) f
- (4, 9) from R2 finds no partner: (4, null, 9) g
A = 1 matched, so (1, 5, null) and (1, null, 7) are not in R.
Answer: R contains e, f, g but not a, b
- A = 1 is in both tables: (1, 5, 7) e
- (3, 7) from R1 finds no partner: (3, 7, null) f
- (4, 9) from R2 finds no partner: (4, null, 9) g
A = 1 matched, so (1, 5, null) and (1, null, 7) are not in R.
Answer: R contains e, f, g but not a, b
Consider a join (relation algebra) between relations r(R)and s(S) using the nested loop method. There are 3 buffers each of size equal to disk block size, out of which one buffer is reserved for intermediate results. Assuming size(r(R))size(s(S)), the join will have fewer number of disk block accesses if
Answer: (A)
One buffer holds the outer relation and one holds the inner relation. The number of block accesses is .
The product term does not change when the relations swap places. So the cost is lower when the outer relation has fewer blocks. Relation r is the smaller one, so r goes in the outer loop.
Answer: relation r(R) is in the outer loop
The product term does not change when the relations swap places. So the cost is lower when the outer relation has fewer blocks. Relation r is the smaller one, so r goes in the outer loop.
Answer: relation r(R) is in the outer loop
What is the optimized version of the relation algebra expression , where A1, A2 are sets of attributes in r with and F1, F2 are Boolean expressions based on the attributes in r?
Answer: (A)
Let us look at each step:
- Two selections can be merged into one:
- As , the two projections reduce to one:
Answer:
- Two selections can be merged into one:
- As , the two projections reduce to one:
Answer:
Keep practising
Topics in Databases
ER ModelRelational Schema
Relational AlgebraYou are here
Tuple CalculusSQLIntegrity ConstraintsNormal FormFile SystemTransaction