According to wiki
There are two types of optimization. These consist of logical optimization—which generates a sequence of relational algebra to solve the query—and physical optimization—which is used to determine the means of carrying out each operation.
I think @Arjun sir did here physical optimization.
We can do the same by logical optimization. By writing sequence of relation algebra operation then convert them to equivalent sql queries.
so here we can rewrite the query in order to optimally excute is like below:-
select D.dname
from Drivers D
where D.did in (
select distinct R.did
from Cars C, Reserves R
where R.cid = C.cid and ( C.colour = 'red' or C.Colour='green' )
)
I think above query has same effect as above query. Means I can call it as optimized version of above query.
So here total tuple comparison is 40 for inner query .
The reason is :-
cross product of Cars and Reserves table in from Clause results into 40 tuples(Cross product is just one operation which don't need any comparison)
now search the constraint ->>R.cid = C.cid and ( C.colour = 'red' or C.Colour='green' ) in 40 tuples so atmost 40 comparison required .
and its o/p is did <22,31,64> now search this in driver relation which requires another 6 comparison.(if u comparing from top in Driver relation . note that did is primary key in Driver relation.)
so total 40+6=46 comparison Hence Option B is Ans.
@Arjun sir, Plz Verify my approach.