这是我的sql,它太慢了,请告诉我如何优化我的表架构或这个sql
SELECT
activityLog.id, activityLog.business_id, activityLog.business_typedict.label,
dict.id, callLog.id, callLog.duration, callLog.record_url,
leads.name AS "leads.name", customer.name AS "customer.name",
niche.name AS "niche.name", contacts.name AS "contacts.name",
task.name AS "task.name"
FROM
biz_business_log activityLog
LEFT JOIN leads_leads leads
ON activityLog.business_type=1 AND activityLog.business_id=leads.id
AND EXISTS (SELECT 1 FROM sys_office
WHERE 1 = 1 AND (id = '5' OR parent_ids LIKE '5,%')
AND id=leads.office_id)
LEFT JOIN cust_customer customer
ON activityLog.business_type=2 AND activityLog.business_id=customer.id
AND EXISTS (SELECT 1 FROM sys_office
WHERE 1 = 1 AND (id = '5' OR parent_ids LIKE '5,%')
AND id=customer.office_id)
LEFT JOIN niche_niche niche
ON activityLog.business_type=3 AND activityLog.business_id=niche.id
AND EXISTS (SELECT 1 FROM sys_office
WHERE 1 = 1 AND (id = '5' OR parent_ids LIKE '5,%')
AND id=niche.office_id)
LEFT JOIN contacts_contacts contacts
ON activityLog.business_type=4 AND activityLog.business_id=contacts.id
AND EXISTS (SELECT 1 FROM sys_office
WHERE 1 = 1 AND (id = '5' OR parent_ids LIKE '5,%')
AND id=contacts.office_id)
LEFT JOIN task_task task
ON activityLog.business_type=5 AND activityLog.business_id=task.id
AND EXISTS (SELECT 1 FROM sys_office
WHERE 1 = 1 AND (id = '5' OR parent_ids LIKE '5,%')
AND id=task.office_id)
LEFT JOIN sys_dict dict
ON activityLog.activity_log_type = dict.value
LEFT JOIN biz_call_log callLog
ON callLog.business_log_id = activityLog.id
WHERE
1=1
AND dict.type='activity_log_type'
AND dict.company_id = 2
AND activityLog.company_id = 2
AND dict.delete_flag = 0
ORDER BY
IFNULL(activityLog.update_time, activityLog.create_time) DESC
LIMIT
0,20
答案 0 :(得分:0)
因为dict没有使用索引并使用临时