내 SQL 내가 쿼리의 모든 필드에 인덱스가이 MySQL 쿼리를 최적화 할 수 있습니까?
SELECT authors.*, COUNT(*) FROM authors
INNER JOIN resources_authors ON authors.author_id=resources_authors.author_id
WHERE
resource_id IN
(SELECT resource_id FROM resources_authors WHERE author_id = '1313')
AND authors.author_id != '1313'
GROUP BY authors.author_id`
,하지만 난 여전히 Using temporary; Using Filesort
를 얻을.
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY authors ALL PRIMARY NULL NULL NULL 16025 Using where; Using temporary; Using filesort
1 PRIMARY resources_authors ref author_id author_id 4 authors.author_id 3 Using where
2 DEPENDENT SUBQUERY resources_authors unique_subquery resource_id,author_id,resource_id_2 resource_id 156 func,const 1 Using index; Using where
이 쿼리의 속도를 높이려면 쿼리 또는 테이블 구조를 어떻게 향상시킬 수 있습니까? http://sqlfiddle.com/#!2/96d57/2/0
'author_id! = 1313'은 색인을 효과적으로 사용할 수 있다고 생각하지 않습니다. – Barmar
@MKhalidJunaid - 결코 결과를 반환하지 않으므로 작동하지 않습니다. –
왜 이드는 1313이어야하고 1313이 아니라고 말할까요? ... 기본적으로 당신은 자존심이있는 자원이 1313이고 저자가 1313이 아닌 곳을 찾아 내고 있습니다. –