我有complex1(field2,field3)
用于搜索table1
和index order1(field10)
排序结果的索引。这table1
是 MySQL IndoDB 表。通过子查询,我尝试使用complex1
索引获取值,通过主查询,我想使用order1
索引对它们进行排序,只保留前 50 个。
EXPLAIN(
SELECT `t1`.`field1`,`t1`.`field10` from `database`.`table1` `t1` INNER JOIN
(SELECT `field1` FROM `database`.`table1` WHERE
`field2` >= 'val1' and `field2`<='val2' `and `field3` >= 'val3' and `field3`<='val4'
) as e1
ON e1.`field1`=t1.`field1` ORDER BY t1.`field10` LIMIT 50)
结果如下:
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 13 "Using temporary; Using filesort"
1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 e1.field1 1
2 DERIVED table1 range complex1 complex1 8 NULL 13 "Using where; Using index"
如我所见complex1
,已使用order1
且未使用。为什么?