Using index with left join (11 replies)
Submitted by sudeepg on Fri, 08/15/2008 - 17:59.
I am trying to perform a left join on two tables ('hymnText' and 'subjectToEntry') using indexes, but the results are not what I'm expecting. I have added indexes to the 'number' field of both tables, yet according to the explain query below, all of the rows of 'subjectToEntry' are being scanned for each row in 'hymnText'. What I think I'm looking for is a type of 'ref' and a ref of 'hymnText.number' in the 'subjectToEntry' row in the explain query. Any suggestions on what to do would be appreciated. Thanks!
- Jon
mysql> explain select hymnText.textID from hymnText left join subjectToEntry on subjectToEntry.number = hymnText.number; +----+-------------+----------------+-------+---------------+--------+---------+------+-------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+----------------+-------+---------------+--------+---------+------+-------+-------------+ | 1 | SIMPLE | hymnText | ALL | NULL | NULL | NULL | NULL | 27663 | | | 1 | SIMPLE | subjectToEntry | index | NULL | number | 52 | NULL | 45473 | Using index | +----+-------------+----------------+-------+---------------+--------+---------+------+-------+-------------+ 2 rows in set (0.00 sec)

Recent comments
22 weeks 4 days ago
23 weeks 1 day ago
23 weeks 1 day ago
23 weeks 3 days ago
24 weeks 1 day ago
26 weeks 2 days ago
29 weeks 2 days ago
32 weeks 1 day ago
32 weeks 6 days ago
33 weeks 4 days ago