How to tell which of these two relational-algebra expression is more effective?

45 Views Asked by At

I have this table :

enter image description here

And these two expressions :

enter image description here

I have to tell which one of these two expression is more effictive to find "nom".

I have choice between A or B or both are equally effective.

My teacher said in class that a join is a really demanding operation but it is the most used. Other than that he didn't address this topic so i am kinda lost to answer this question.

They have the same amount of join operations so i am not sure what else i am supposed to look at..

Thank you for your help.

1

There are 1 best solutions below

0
On BEST ANSWER

As a general principle, filtering should happen as early as practical: joins tend to multiply the number of rows in each table, which means more work for the filters and for later joins.

In this case:

  • $S1 ⋈ C1$ creates 14 rows; $E1 ⋈ (S1 ⋈ C1)$ creates another 14 rows; $\sigma_{sujet=BD}(E1 ⋈ (S1 ⋈ C1))$ filters those 14 rows down to 5. The filter is run 14 times, and 28 rows are calculated.
  • $\sigma_{sujet=BD} (C1)$ filters 6 rows down to 2; $S1 ⋈ \sigma_{sujet=BD} (C1)$ creates 5 rows; $E1 ⋈ (S1 ⋈ \sigma_{sujet=BD} (C1))$ creates another 5 rows. The filter is run 6 times, and 10 rows are calculated.

Both of these calculations give the same result, but the second - filtering as early as possible - has reduced the number of filter attempts and row calculations, because it doesn't need to come up with all the rows for course data that it doesn't care about.