-4
이 쿼리를 레일로 끝내지는 않습니다. 왜? 검색어 :mysql 쿼리에 많은 시간이 걸린다
SELECT CONCAT(f.name, ' ', f.parent_names) AS FullName,
stts.name AS 'Status',
u.name AS Unit,
city.name AS City,
hus.mobile1 AS HusbandPhone,
wife.mobile1 AS WifePhone,
f.phone AS HomePhone,
f.contact_initiation_date AS InitDate,
fh.created_at AS StatusChangeDate,
cmt.created_at AS CommentDate,
cmt.comment AS LastComment,
f.reconnection_date AS ReconnectionDate,
(SELECT GROUP_CONCAT(t.name, ' ')
FROM taggings tgs
JOIN tags t ON tgs.tag_id = t.id
WHERE tgs.taggable_type = 'family'
AND tgs.taggable_id = f.id) AS HandlingStatus
FROM families f
JOIN categories stts ON f.family_status_cat_id = stts.id
JOIN units u ON f.unit_id = u.id
JOIN categories city ON f.main_city_cat_id = city.id
LEFT JOIN contacts hus ON f.husband_id = hus.id
LEFT JOIN contacts wife ON f.wife_id = wife.id
LEFT JOIN comments cmt ON f.id = cmt.commentable_id
AND cmt.created_at =
(SELECT MAX(created_at)
FROM comments
WHERE commentable_id = f.id)
LEFT JOIN family_histories fh ON f.id = fh.family_id
AND fh.created_at =
(SELECT MAX(created_at)
FROM family_histories
WHERE family_id = f.id
AND family_history_cat_id = 1422)
AND fh.family_history_cat_id = 1422
WHERE 1=0
OR (f.family_status_cat_id = 1422
AND ( (SELECT MAX(_fh.created_at)
FROM family_histories _fh
WHERE _fh.family_history_cat_id = 1422
AND _fh.family_id = f.id
AND _fh.new_val LIKE '%1422%') BETWEEN '2010-03-10' AND '2011-03-02'))
누락 된 항목이 있습니까? Synatx가 정확하므로 문제가 있습니까?
당신의'EXPLAIN '은 뭐라고 말합니까? –
테이블이 인덱싱됩니까? 얼마나 많은 레코드가 각 테이블? 우리는 붙여 넣기 된 쿼리 (형식화되지 않은 쿼리)를 기반으로하여 왜 성능이 기대만큼 좋지 않은지에 대해 대답 할 수 없습니다. –
개별 쿼리가 성공적으로 실행됩니까? 나는 이것을 최소한으로 자르고 거기에서 일할 것이다. –