다음 두 쿼리에 대해 mysql의 EXPLAIN 출력을 이해하지 못합니다. 제 질의 MySQL은GROUP BY를 추가하면 어떻게이 쿼리를보다 효율적으로 만들 수 있습니까?
이 1,238,264 제 레코드를 선택한다 : 더
explain select
count(distinct utc.id)
from
user_to_company utc
inner join
users u
on utc.user_id=u.id
where
u.is_removed=false
group by
utc.user_id
order by
utc.user_id asc limit 20;
+----+-------------+--------+--------+----------------------------+--------------------+---------+-------------------------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+--------+----------------------------+--------------------+---------+-------------------------+------+-------------+
| 1 | SIMPLE | utc | index | user_id,FKF513E0271C2D1677 | FKF513E0271C2D1677 | 8 | NULL | 20 | Using index |
| 1 | SIMPLE | u | eq_ref | PRIMARY | PRIMARY | 8 | utc.user_id | 1 | Using where |
+----+-------------+--------+--------+----------------------------+--------------------+---------+-------------------------+------+-------------+
: 제 쿼리
explain select
count(distinct utc.id)
from
user_to_company utc
inner join
users u
on utc.user_id=u.id
where
u.is_removed=false
order by
utc.user_id asc limit 20;
+----+-------------+--------+------+----------------------------+---------+---------+---------------------------------+---------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+------+----------------------------+---------+---------+---------------------------------+---------+-------------+
| 1 | SIMPLE | u | ALL | PRIMARY | NULL | NULL | NULL | 1238264 | Using where |
| 1 | SIMPLE | utc | ref | user_id,FKF513E0271C2D1677 | user_id | 8 | u.id | 1 | Using index
하는 GROUP BY
은 20 레코드를 선택 MySQL이 만드는 첨가 info에는 사용자 테이블에 1333194 개의 레코드가 있고 user_to_company 테이블에 1327768 개의 레코드가 있습니다.
GROUP BY
을 추가하면 mysql이 첫 번째 패스에서 20 레코드 만 선택하는 방법은 무엇입니까?
*해야 할 첫 번째 검색어 *는 무엇입니까? 'where' 조건을 만족하는'utc.id'의 총 고유 카운트 인 하나의 행만 반환합니다. –