MySQL Forums
Forum List  »  Optimizer & Parser

Re: inner join on key does full table scan anyway
Posted by: Chris Schneider
Date: October 26, 2007 01:21PM

You could use LEFT or RIGHT join on this, that is, if don't wast to join ALL of the rows in each table regardless of NULL...

test> EXPLAIN SELECT * FROM a left JOIN b ON b.z = a.x OR b.z = a.y;
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref |rows | Extra |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
| 1 | SIMPLE | a | index | NULL | y | 5 | NULL | 2 | Using index |
| 1 | SIMPLE | b | index | PRIMARY | PRIMARY | 4 | NULL | 2 | Using index |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
2 rows in set (0.00 sec)

otherwise two queries would be better.

Careful with UNION because it will truncate duplicates.

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: inner join on key does full table scan anyway
3275
October 26, 2007 01:21PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.