我正在開發項目管理工具,同時通過管理端生成報告,數據庫中的數據加載時間非常多> 5分鐘。還有,我知道會幫助我提高性能,但現在我需要有幫助如何提高複雜的MySQL select查詢的性能?
SELECT timesheet_client.organisation as client_name, timesheet_project.title as project_name,
timesheet_task.name as task, CONCAT(timesheet_user.first_name, ' ', timesheet_user.last_name) as resource_name,
timesheet_user.bill_factor, timesheet_client.client_type, sum(spent) as spent, sum(delivered_hours) as delivered_hours,
sum(billable_hours) as billable_hours, comments, color, lock_color, updated_by, updated_by_date, timesheet_user_psdb.grp_id,
timesheet_user_psdb.client_id, timesheet_user_psdb.proj_id, timesheet_user_psdb.task_id, timesheet_user_psdb.uid,
timesheet_user_grp.grp_name
FROM timesheet_user_psdb,timesheet_user, timesheet_client,
timesheet_project,timesheet_task,timesheet_user_grp
WHERE timesheet_user.username=timesheet_user_psdb.uid and
timesheet_client.client_id=timesheet_user_psdb.client_id and timesheet_project.proj_id=timesheet_user_psdb.proj_id and
timesheet_task.task_id = timesheet_user_psdb.task_id and timesheet_user_grp.grp_id=timesheet_user_psdb.grp_id and month =3
AND year = 2017 and month!='' and timesheet_user_psdb.client_id=326
GROUP BY timesheet_user_psdb.task_id,timesheet_user_psdb.uid
ORDER BY timesheet_client.client_type desc,timesheet_client.organisation,timesheet_user_psdb.proj_id,
timesheet_user_psdb.task_id,timesheet_user.uid,timesheet_user_psdb.task_id;
我已經使用上的所有主鍵索引SELECT查詢幾點。
幫助這將是非常可觀的。
是強制性在這種情況下的順序?刪除訂單條款可能會有所幫助。 –
在SELECT之前放置EXPLAIN並向我們顯示輸出。 – Adder
您應該提供表定義,'EXPLAIN'的輸出,您正在使用的引擎,任何引擎特定的配置值以及您接收的記錄數。沒有人可以運行這個查詢並告訴你發生了什麼。我的假設是你正在I/O綁定,因爲你正在運行默認的MySQL設置。 – Mjh