Restriction, projection, renaming and extension all bind closely to the relation on their left. This means when combining relations, e.g. using a join, we need to add parentheses if we want to bind to the results of the combined relations instead.
For example, this fails:
$S & $SP{*, extra:=STATUS*2}
ERROR: ::1:21: identifier not found: STATUS
because the { } extension binds to $SP and not to the result of the join between $S and $SP where the STATUS attribute can be found.
So instead:
($S & $SP){*, extra:=STATUS*2}
| extra | SNO | SNAME | STATUS | CITY | PNO | QTY |
|---|---|---|---|---|---|---|
| 20 | S2 | Jones | 10 | Paris | P1 | 300 |
| 20 | S2 | Jones | 10 | Paris | P2 | 400 |
| 40 | S1 | Smith | 20 | London | P1 | 300 |
| 40 | S1 | Smith | 20 | London | P2 | 200 |
| 40 | S1 | Smith | 20 | London | P3 | 400 |
| 40 | S1 | Smith | 20 | London | P4 | 200 |
| 40 | S1 | Smith | 20 | London | P5 | 100 |
| 40 | S1 | Smith | 20 | London | P6 | 100 |
| 40 | S4 | Clark | 20 | London | P2 | 200 |
| 40 | S4 | Clark | 20 | London | P4 | 300 |
| 40 | S4 | Clark | 20 | London | P5 | 400 |
| 60 | S3 | Blake | 30 | Paris | P2 | 200 |
works by adding the ( ) to ensure the extension binds to the result of the join between $S and $SP.
As with other programming languages there are also precedences for binary operators, e.g. * binds tighter than +, and again, adding parentheses around things can prioritise alternative evaluations.