• retagged by
27,070 views
58 58 votes
Consider the following relations $P(X,Y,Z), Q(X,Y,T)$ and $R(Y,V)$.
$$\overset{\textbf{Table: P}}{\begin{array}{|l|l|l|} \hline \textbf{X} & \textbf{Y} & \textbf{Z} \\\hline \text{X1} & \text{Y1} & \text{Z1} \\\hline \text{X1} & \text{Y1} & \text{Z2} \\\hline \text{X2} & \text{Y2} & \text{Z2} \\\hline \text{X2} & \text{Y4} & \text{Z4} \\\hline  \end{array}} \qquad \overset{\textbf{Table: Q}}{\begin{array}{|l|l|l|} \hline  \textbf{X} & \textbf{Y} & \textbf{T} \\\hline \text{X2} & \text{Y1} & 2 \\\hline \text{X1} & \text{Y2} & 5 \\\hline \text{X1} & \text{Y1} & 6 \\\hline \text{X3} & \text{Y3} & 1 \\\hline  \end{array}} \qquad \overset{\textbf{Table: R}}{\begin{array}{|l|l|} \hline \textbf{Y} & \textbf{V}  \\\hline \text{Y1} & \text{V1} \\\hline \text{Y3} & \text{V2} \\\hline \text{Y2} & \text{V3} \\\hline \text{Y2} & \text{V2} \\\hline  \end{array}}$$
How many tuples will be returned by the following relational algebra query?

$\Pi_x (\sigma_{(P.Y=R.Y \wedge R.V=V2))} (P \times R)) – \Pi_x (\sigma_{(Q.Y = R.Y \wedge Q.T>2))} (Q \times R))$

Answer: ________

4 Answers

Best answer
83 83 votes
$R \cdot V = V2$, there are two tuples which have $Y$ parameter as $Y3$ and $Y2$.

$P \cdot  Y = R \cdot Y$, there are no coincide with $Y3$, and there is one tuple coincide with $Y2$ which have $X$ parameter as $X2$.

$\Pi_X (\sigma _{(P.Y=R.Y\; \Lambda \;R.V = V2)}(P \times R)) = \{X_2\}$

$Q \cdot T > 2$, there are two tuples which have $Y$ parameter as $Y1$ and $Y2$ which have $X$ parameter as $X1$.

check atleast one tuple is matched $Q.Y=R.Y$ in this query, that's enough to result $X1$.

$\Pi_X (\sigma _{(Q.Y=R.Y\; \Lambda \;Q.T >2)}(Q \times R)) =  \{X_1\}$

$\Pi_X (\sigma _{(P.Y=R.Y\; \Lambda \;R.V = V2)}(P \times R)) - \Pi_X (\sigma _{(Q.Y=R.Y\; \Lambda \;Q.T >2)}(Q \times R)) = \{X_2\} - \{X_1\} = \{X_2\}$

Number of Tuples $= 1$
• edited by
0 0 votes

At last, (X1 X1 X2 X2) - (X1 X1 X1) will be executed leading to result of only 1 tuple i.e X2.

1 flag:
✌ Edit necessary (js__)
0 0 votes

🔹 Step 1: π_X(σ(P.Y = R.Y ∧ R.V = V2)(P × R))

  • R.V = V2 → (Y3, V2) and (Y2, V2)

  • Match P.Y = R.Y:

    • P has Y2 → (X2, Y2, Z2)

    • P has no Y3

  • So selected X: X2

✅ Result of Part 1: {X2}

🔹 Step 2: π_X(σ(Q.Y = R.Y ∧ Q.T > 2)(Q × R))

  • Q.T > 2 → (X1, Y2, 5), (X1, Y1, 6)

  • Match R.Y:

    • R has Y2 and Y1 → both match

  • So selected X: X1

✅ Result of Part 2: {X1}

🔹 Final Set Difference:

{X2} − {X1} = {X2}

✅ Final Answer:

1 tuple selected: X2

• reshown by
Answer:
Position:
Show:

Related questions

73 73 votes
8 answers 8 answers
50.7k
50.7k views
Arjun asked Feb 7, 2019
50,681 views
A relational database contains two tables Student and Performance as shown below:$$\overset{\text{Table: student}}{\begin{array}{|l|l|} \hline \text{Roll_no} & \text{Stud...
54 54 votes
3 answers 3 answers
26.0k
26.0k views
Arjun asked Feb 7, 2019
25,953 views
Let the set of functional dependencies $F=\{QR \rightarrow S, \: R \rightarrow P, \: S \rightarrow Q \}$ hold on a relation schema $X=(PQRS)$. $X$ is not in BCNF. Suppose...
53 53 votes
6 answers 6 answers
29.0k
29.0k views
Arjun asked Feb 7, 2019
29,020 views
Consider the following two statements about database transaction schedules:Strict two-phase locking protocol generates conflict serializable schedules that are also recov...
38 38 votes
3 answers 3 answers
17.7k
17.7k views
Arjun asked Feb 7, 2019
17,693 views
Which one of the following statements is NOT correct about the $B^+$ tree data structure used for creating an index of a relational database table?$B^+$ Tree is a height-...