• edited by
789 views
6 6 votes

Consider the given relations $X, Y$ and $Z$. The relation $X$ has three columns $P, Q$ and $R$. The relation $Y$ has three columns $P, Q$ and $S$. The relation $Z$ has two columns $P$ and $T$.

 
X
PQR
P1Q1R1
P2Q2R2
P3Q3R2
 
Y
PQS
P1Q12
P1Q25
P2Q16
P3Q31
 
Z
PT
P1T1
P3T2
P4T3
P4NULL

Consider the relational algebra expression

\[ \pi_{P,R,S} \Big[ (\sigma_{(Q=Q3 \vee R=R2)}(X \bowtie Y)) \ \bowtie\ (\sigma_{(S>1)}(Y \bowtie Z)) \Big] \]

where $\bowtie$ denotes natural join operation.

Which of the following options is the correct output for the given expression?

  1. Two rows $\text{(P1, R1, 2)}$ and $\text{(P1, R1, 5)}$
  2. Three rows $\text{(P1, R1, 2), (P1, R1, 5)}$ and $\text{(P2, R2, 6)}$
  3. One row $\text{(P1, R1, 2)}$
  4. Zero rows

2 Answers

6 6 votes
\[
\Pi_{PRS}
\Big(
(\sigma_{Q=Q3 \vee R=R2}(X \bowtie Y))
\bowtie
(\sigma_{S>1}(Y \bowtie Z))
\Big)
\]

Step 1:  Compute $X \bowtie $ Y

Natural join is performed on common attributes $P$ and $Q$.

The resulting relation is:

\[
\begin{array}{|c|c|c|c|}
\hline
P & Q & R & S \\ \hline
P1 & Q1 & R1 & 2 \\
P3 & Q3 & R2 & 1 \\ \hline
\end{array}
\]

Now apply the selection condition $Q=Q3 \vee R=R2$.

Only the second row satisfies the condition.

\[
\begin{array}{|c|c|c|c|}
\hline
P & Q & R & S \\ \hline
P3 & Q3 & R2 & 1 \\ \hline
\end{array}
\]

Step 2:  Compute $Y \bowtie $ Z

Natural join is performed on attribute $P$.

\[
\begin{array}{|c|c|c|c|}
\hline
P & Q & S & T \\ \hline
P1 & Q1 & 2 & T1 \\
P1 & Q2 & 5 & T1 \\
P3 & Q3 & 1 & T2 \\ \hline
\end{array}
\]

Now apply the selection condition $S > 1$.

\[
\begin{array}{|c|c|c|c|}
\hline
P & Q & S & T \\ \hline
P1 & Q1 & 2 & T1 \\
P1 & Q2 & 5 & T1 \\ \hline
\end{array}
\]

Step 3: Final Natural Join

The first intermediate relation contains only $P3$.

The second intermediate relation contains only $P1$.

Since there is no matching value of $P$, the natural join results in an empty relation.

 

Step 4: Projection

Applying $\Pi_{PRS}$ on an empty relation still gives an empty relation.

\[
\boxed{\text{Final Output: Zero rows}}
\]

Correct Option: (D)
• moved by
0 0 votes

we can also do by option matching
First need to be compute (σ(Q=Q3∨R=R2)​(X⋈Y))
and then we get only 

so option D will satisfied.

Answer:
Position:
Show:

Related questions

3 3 votes
2 2 answers
679
679 views
gatecse asked Feb 23
679 views
Consider a B+ Tree where the maximum number of key values in each leaf node is $2$ and the maximum number of pointers in each non-leaf node is $3$. Let the content of the...
2 2 votes
2 2 answers
650
650 views
gatecse asked Feb 23
650 views
Consider a table Employee(EmpID, TeamID), where the column EmpID (ID of an employee) is the primary key. The column TeamID denotes the team ID of the team of which the em...
2 2 votes
2 2 answers
851
851 views
gatecse asked Feb 23
851 views
Let there be two relations $X$ and $Y$ as shown. $X$ has three columns $P, Q$ and $R . Y$ has two columns $P$ and $S$.\[\textbf{X}\]\[\begin{array}{|c|c|c|}\hlineP & Q & ...
2 2 votes
1 1 answer
730
730 views
gatecse asked Feb 23
730 views
Let Account be a relation as shown.\[\textbf{Account}\]\[\renewcommand{\arraystretch}{1.3}\begin{array}{|c|c|}\hline\text{AccNo} & \text{Balance} \\\hline\text{A1} & 5000...