私は8,566件の結果を出すクエリを持っています。しかし、EXPLAINは233,190行を検索する1つのテーブルを表示していますが、なぜ表示されません。 それは、ステータス 'キーを使用して、問題テーブル(ppi_sar_status)を示しているが、クエリは「loanID」MySQL JOINが多すぎる行を検索しています
SELECT DISTINCT
ppi_loan.loanID,
ppi_loan.lender,
ppi_loan.customerID,
ppi_loan.agreementNo,
loan_number,
ppi_lenders.name,
ppi_status.status,
ppi_statuses.description,
ppi_loan.broker,
(SELECT sarSent
FROM ppi_sar
WHERE ppi_sar.customerID = ppi_loan.customerID
AND ppi_sar.lender = ppi_loan.lender
ORDER BY sarSent DESC
LIMIT 1) as sarSent,
(SELECT COUNT(DISTINCT(groupID))
FROM ppi_mdrs
WHERE ppi_mdrs.customerIDfk = ppi_loan.customerID
AND ppi_mdrs.lender = ppi_loan.lender
AND sent_to_lender = '0000-00-00 00:00:00') AS mdrs_sent,
(SELECT sent
FROM ppi_mdrs
WHERE ppi_mdrs.customerIDfk = ppi_loan.customerID
AND ppi_mdrs.lender = ppi_loan.lender
ORDER BY sent DESC
LIMIT 1) AS mdr_last_sent,
mobilePhone,
homePhone,
title,
firstName,
lastName,
loaSent
FROM
ppi_loan
JOIN ppi_sar_status
ON ppi_loan.loanID = ppi_sar_status.loanID
JOIN ppi_customer
ON ppi_loan.customerID = ppi_customer.customerID
JOIN ppi_lenders
ON ppi_loan.lender = ppi_lenders.id
JOIN ppi_status
ON ppi_loan.customerID = ppi_status.customerID
JOIN ppi_statuses
ON ppi_status.status = ppi_statuses.status
LEFT JOIN ppi_mdrs
ON ppi_loan.customerID = customerIDfk
AND ppi_loan.lender = ppi_mdrs.lender
WHERE
ppi_loan.customerID != 10
AND ppi_status.status != 9
AND ppi_status.status != 32
AND ppi_status.status != 54
AND ppi_status.status != 58
AND ppi_status.status != 59
AND ppi_status.status != 61
AND ppi_status.status != 69
AND ppi_status.status != 60
AND ppi_status.history = 0
AND ppi_loan.customerID
IN (SELECT customerID
FROM ppi_status
WHERE (status = 5 || status = 6 || status = 79)
AND timestamp > '2015-04-01'
AND ppi_status.customerID = ppi_loan.customerID)
AND ppi_sar_status.status = 16
AND ppi_sar_status.history = 0
AND (cc_type = '' || (cc_type != '' AND cc_accepted = 'no'))
AND ppi_loan.deleted = 'no'
テーブルにインデックスを設定していますか? –
はい、EXPLAINの結果には可能なキーが表示されます – swdee