Consider the following query:
select FEE_NUMBER
from CARRIER_FEE CF
left outer join CONTYPE_FEE_LIST cfl on CF.CAR_FEE_ID=cfl.CAR_FEE_ID and cfl.CONT_TYPE_ID=3
where CF.SEQ_NO = (
select max(CF2.SEQ_NO) from CARRIER_FEE CF2
where CF2.FEE_NUMBER=CF.FEE_NUMBER
and CF2.COMPANY_ID=CF.COMPANY_ID
group by CF2.FEE_NUMBER)
group by CF.CAR_FEE_ID
On my laptop this returns no results. Using exactly the same (dumped) database on my servers it does return results.
If I run an EXPLAIN on my laptop I get this
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+-------+-------+---------------------------------------------+-----------------------+---------+------------------------+------+----------------------------------------------+
| 1 | PRIMARY | CF | index | NULL | PRIMARY | 8 | NULL | 132 | Using where |
| 1 | PRIMARY | cfl | ref | FK_CONTYPE_FEE_LIST_1,FK_CONTYPE_FEE_LIST_2 | FK_CONTYPE_FEE_LIST_1 | 8 | odysseyB.CF.CAR_FEE_ID | 6 | |
| 2 | DEPENDENT SUBQUERY | CF2 | ref | FK_SURCHARGE_1 | FK_SURCHARGE_1 | 8 | func | 66 | Using where; Using temporary; Using filesort |
Whereas on all of my other servers it gives this (note the difference in the ref column)
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+-------+-------+---------------------------------------------+-----------------------+---------+------------------------+------+----------------------------------------------+
| 1 | PRIMARY | CF | index | NULL | PRIMARY | 8 | NULL | 132 | Using where |
| 1 | PRIMARY | cfl | ref | FK_CONTYPE_FEE_LIST_1,FK_CONTYPE_FEE_LIST_2 | FK_CONTYPE_FEE_LIST_1 | 8 | odysseyB.CF.CAR_FEE_ID | 6 | |
| 2 | DEPENDENT SUBQUERY | CF2 | ref | FK_SURCHARGE_1 | FK_SURCHARGE_1 | 8 | odysseyB.CF.COMPANY_ID | 66 | Using where; Using temporary; Using filesort |
If I remove either the join, the subquery or the last group-by then I get the expected results.
I'm assuming that this is a configuration issue, however it's not one that I've seen before. Does anybody know what might cause this?
My laptop is running OSX 10.6 with MySQL 5.0.41. Another laptop running OSX 10.5.7 and MySQL 5.0.37 works fine, as do the Linux servers running MySQL 5.0.27.
Can anyone explain the difference between one explain plan using ref=func and the other using ref=odysseyB.CF.COMPANY_ID?
Thanks.