I have a basic HFSQL database, with 3 tables: Company, Person and Worker. Each table has ~5 columns, and 5000 entries. Worker has a foreign key to person called IDPerson, and a foreign key to entity called IDCompany.
I tested the 2 following queries (I only change the order of the INNER JOIN):
QUERY 1 (~5ms execution time)
SELECT *
FROM Person
INNER JOIN Worker ON Worker .IDPerson = Person.IDPerson
WHERE Worker.Company = 1;
QUERY 2 (~50ms execution time)
SELECT *
FROM Worker
INNER JOIN Person ON Worker .IDPerson = Person.IDPerson
WHERE Worker.Company = 1;
Number of entries found is the same, but execution time is 10x slower. Why? Isn't INNER JOIN supposed to be symmetric? Why the order changes the performance up to 10x when a WHERE clause is used?
Please help me understand this strange behaviour!
PS: performance issue is the same if I only select some columns instead of ""*