我正在开发项目管理工具,同时通过管理端生成报告,数据库中的数据加载时间非常多> 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