0
私は本当に遅く、理由がわからないクエリを、すべての結合フィールドにインデックスがあります。利用可能な場合、インデックスを使用していないのはなぜですか?
これは私のクエリです:
SELECT
CASE
WHEN
arrears_action.executed IS NULL
OR arrears_action.executed != '0000-00-00 00:00:00'
THEN
'No action'
ELSE DATE_FORMAT(arrears_action.planned, '%d %M %Y')
END,
CASE
WHEN
arrears_action.executed IS NULL
OR arrears_action.executed != '0000-00-00 00:00:00'
THEN
NULL
ELSE IF(DATEDIFF(NOW(), arrears_action.planned) >= 0,
DATEDIFF(NOW(), arrears_action.planned),
NULL)
END,
customer.id AS customer_id,
customer.customer_number AS cif_number,
arrears_application.id AS arrears_application_id,
person.id AS person_id,
person.fullname,
account.account_number,
CONCAT(branch.branch_id,
product.code,
SUBSTRING(contract.loan_number, - 9, 9)) AS loan_account,
payment.principal_amount_outstanding,
arrears.amount_in_arrears,
arrears.days_in_arrears,
balance.account_balance_available,
product.code AS product_code,
division.name AS division_name,
coll_customer_status.name AS customer_status,
loan_status.name AS loan_status
FROM
cregora_cregora.base_cregora_loancontract_inarrears_data AS arrears
INNER JOIN
cregora_cregora.base_cregora_loancontract_data AS contract ON contract.id = arrears.loancontract_id
INNER JOIN
cregora_cregora.base_cregora_loancontract_payment_data AS payment ON payment.loancontract_id = contract.id
INNER JOIN
cregora_cregora.base_cregora_nmb_product_class_data AS product ON product.id = contract.product_class
INNER JOIN
cregora_cregora.base_cregora_account_data AS account ON account.id = contract.account_id
INNER JOIN
cregora_cregora.base_cregora_customer_data AS customer ON customer.id = account.customer_id
INNER JOIN
cregora_cregora.base_cregora_person_data AS person ON person.id = customer.type_of_customer_id
INNER JOIN
cregora_base.system_organization_division AS division ON division.id = contract.loan_branch
INNER JOIN
cregora_cregora.base_cregora_nmb_branch_data AS branch ON branch.id = division.entity_instance_id
INNER JOIN
cregora_cregora.base_cregora_account_balanceinfo_daily_data AS balance ON balance.account_id = account.id
LEFT JOIN
cregora_cregora.base_cregora_arrears_applications_data AS arrears_application ON arrears_application.loan_contract_number = contract.loan_number
LEFT JOIN
cregora_cregora.base_cregora_arrears_action_data AS arrears_action ON arrears_action.arrears_application_id = arrears_application.id
LEFT JOIN
cregora_cregora.base_cregora_collection_applications_data AS coll_application ON coll_application.arrears_application_id = arrears_application.id
LEFT JOIN
cregora_cregora.base_cregora_collection_customer_statuses_data AS coll_customer_status ON coll_customer_status.id = coll_application.collection_customer_status_id
LEFT JOIN
cregora_cregora.base_cregora_arrears_loan_contract_statuses_data AS loan_status ON loan_status.id = arrears_application.loan_contract_status_id
LEFT JOIN
cregora_cregora.base_cregora_arrears_application_statuses_data AS arrears_status ON arrears_status.id = arrears_application.arrears_application_status_id
WHERE
contract.loan_branch IN (46)
AND (coll_customer_status.id IN ('1' , '2',
'3',
'5',
'6',
'7',
'8',
'9',
'10',
'11',
'12',
'13',
'15',
'16',
'17',
'18',
'19',
'20',
'21',
'22',
'23')
OR coll_customer_status.id IS NULL)
AND (loan_status.id IS NULL
OR loan_status.id IN ('1' , '2', '3', '4', '5'))
AND arrears.amount_in_arrears > '1'
GROUP BY arrears_application.id
ORDER BY arrears.days_in_arrears DESC , person.fullname
これはEXPLAINの出力です:mysqlは契約テーブル(説明の3行目、タイプ - のインデックスのいずれかを使用していないのはなぜ > ALL 、可能なキー? - > PRIMARY、ACCOUNT_ID、loan_branch、product_classキー - >空
のthnx事前
説明を少し読みやすくしてください。単純な理由でインデックスを使用していない可能性があります。なぜあなたはそれが遅いクエリを心配していますか?そのようにタイミングを与え、各テーブルの行数を指定すると、 – e4c5
はテキスト出力の代わりにピクチャを使用しました。コントラクトテーブルはインデックスを使用していません。フルテーブルスキャンを実行しています。レコードのnrはまだ実際のテストデータをインポートしていますが、たくさんあるのでまだわかりません。プロダクションでは、このクエリは5分ほど実行されます。追加の注意:group byおよびorder by句を削除すると、クエリーは2番目の数値以下に落ちます – user2988167
大量のインポート操作が既に実行されている間は何の分析もしません – e4c5