I have a doubt. Assume R and S are 2 relations with attributes A and B respectively . If I have a query
Select *
From R, S
Where R.A = S.B
Does this work like a double For Loop in say c or c++
For( i=0; i<n; i++)
For( j=0; j<n; j++)
if (i == j)
//DO some work
First of all: there is no knowing how mysql will internally optimize the query (without knowing the internals of mysql).
In pure relational databases words, this is what you are doing:
SELECT * FROM R, S-> perform cross join, that generates all (r,s) tuples.WHERE R.A = S.B-> now select those tuples that have this behaviourSo it will go over all tuples (more or less like your code). However, it is perfectly possible mysql will internally reduce this to a more efficient inner join that never creates all tuples but only the tuples where
R.A=S.Bis valid.