Hey all,

I've read the pages in the MySQL manual that explain the types of JOINs many 
times, but still think I'm missing something.

I usually was always using INNER JOIN in all my join queries, and in a few 
cases LEFT JOIN (in cases I wanted the rows in one table that were not in the 
other one).

I've started to discover, with the help of EXPLAIN, that the join type can 
seriously affect performance. For example, I had a query such as this:

SELECT a.field
FROM table1 a
INNER JOIN table2 b
USING (field2)
ORDER BY b.field3 DESC

It was using both filesort and a temporary table (in EXPLAIN) and took about 
4.50 seconds to run. I switched the order of the tables in the join, putting 
table2 first, and nothing changed in my EXPLAIN.

I then changed the join to LEFT JOIN, and suddenly I had no more filesort or 
temporary table, and the query took 0.05 seconds !

I compared that I got the same rows in my result both ways, and indeed I did.

I'm positive I can improve many of my queries this way, but feel I need to 
understand the JOINs better. If someone can point me to a guide on this 
someplace, other than the mysql manual (as Ive already read it few times but 
it didnt explain their differences and uses very well), I'd greatly appreciate 
it =)

Or, if you simply want to give the explanation yourself, that's fine too.

Thanks,


-- 
Keith Bussey

Mana Internet Solutions, Inc.
Chief Technology Manager
+50 6 280 2284 ext.108 




-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to