私は非常に遅い次のクエリを持っています (結果だけで 4 ~ 5 秒かかります)。このクエリを高速化するために、このクエリで別の方法で実行できることを誰かが見ることができるかどうか疑問に思っていましたか?
ありがとう!
SELECT
accounts.id AS account_id,
accounts. NAME AS account_name,
accounts.assigned_user_id account_id_owner,
users.user_name AS assigned_user_name,
opportunities_cstm.firstname_c, opportunities_cstm.lastname_c,
opportunities.`name`, TRIM(
Concat(
Ifnull(
opportunities_cstm.firstname_c,
''
),
' ',
Ifnull(
opportunities_cstm.lastname_c,
''
)
)
) AS 'cfull' FROM
opportunities
LEFT JOIN users ON opportunities.assigned_user_id = users.id
LEFT JOIN accounts_opportunities ON opportunities.id = accounts_opportunities.opportunity_id
LEFT JOIN accounts ON accounts_opportunities.account_id = accounts.id
LEFT JOIN opportunities_cstm ON opportunities.id = opportunities_cstm.id_c
WHERE
(
(
opportunities.sales_stage IN (
'Prospecting',
'Appointment Set',
'MeetAndGreet',
'Qualification',
'Needs Analysis',
'Locating Vehicle',
'Demo',
'Trade Evaluation',
'Negotiation',
'Manager T/O',
'Write Up',
'Credit App Submitted',
'Pending Finance',
'Loan Approval',
'Deposit',
'Delayed Decision',
'Sold-Vehicle Ordered',
'Sold-Pending Finance',
'Sold/Pending Delivery',
'Price Quoted',
'Service Pending'
)
)
)
AND (
accounts_opportunities.deleted IS NULL
OR accounts_opportunities.deleted = 0
)
AND (
accounts.deleted IS NULL
OR accounts.deleted = 0
)
AND opportunities.deleted = 0
ORDER BY
opportunities.date_entered DESC,
opportunities.id DESC
LIMIT 0,21
同じクエリからの説明は次のとおりです。
╔═════════════╦════════════════════════╦════════╦═ ═════════════════════════╦═════════════════════╦══ ═══════╦══════════════════════════════════════════ ══╦═══════╦═════════════════════════════╗ ║ select_type ║ table ║ type ║ possible_keys ║ key ║ key_len ║ ref ║ rows ║ extra ║ ╠═════════════╬════════════════════════╬════════╬═ ═════════════════════════╬═════════════════════╬══ ═══════╬══════════════════════════════════════════お問い合わせ ║ シンプル ║ 機会 ║ 範囲 ║ sales_stage, idx_deleted ║ sales_stage ║ 78 ║ null ║ 25161 ║ where を使用する; ファイルソートの使用 ║ ║ シンプル ║ ユーザー ║ eq_ref ║ PRIMARY、idx_id_deleted ║ PRIMARY ║ 108 ║ version4.opportunities.assigned_user_id ║ 1 ║ ║ ║ simple ║ accounts_opportunities ║ ref ║ idx_oppid_del_accid ║ idx_oppid_del_accid ║ 111 ║ version4.opportunities.id ║ 1 ║ where; を使用する。インデックス║の使用 ║ シンプル ║ アカウント ║ eq_ref ║ PRIMARY,idx_accnt_id_del ║ PRIMARY ║ 108 ║ version4.accounts_opportunities.account_id ║ 1 ║ where の使用 ║ ║ シンプル ║ Opportunities_cstm ║ eq_ref ║ PRIMARY ║ PRIMARY ║ 108 ║ version4.opportunities.id ║ 1 ║ ║ ╚═════════════╩════════════════════════╩════════╩═ ═════════════════════════╩═════════════════════╩══ ═══════╩══════════════════════════════════════════ ══╩═══════╩═════════════════════════════╝