我正在用左连接写一个mysql查询它给我结果28秒当我删除并使用左连接调整然后它在一秒钟工作可以任何人告诉我在我的查询中的问题是什么以及它将如何改性?
select *
FROM regist_queue rq
left join appoint ap
on rq.token_number = ap.daily_ticket_no
and rq.LocationId = 15800
and ap.LocationId = 15800
and date(rq.QueueDate) = CURRENT_DATE()
and date(ap.dAppDate) = date(now())
left join patient pr
on ap.iPatID = pr.IPatID
left join gender ge
on pr.vGender = ge.iGenderID
where ifnull(ap.isDel,0) = 0
and ifnull(ap.is_referred,0) != 1
and (ap.LocationId = 15800 or rq.LocationId = 15800 )
order by rq.token_number asc;
我还在所有搜索的参数和应用连接的位置应用了索引。 解释查询计划。 MySql Query Plan
答案 0 :(得分:0)
在SQL查询中使用SQL api
喜欢:
with (nolock)
答案 1 :(得分:0)
基于三个谓词的开头是.........,
我认为sql语句不是基于你的真实目的......
答案 2 :(得分:0)
我的目的不是很清楚。有关联接and rq.LocationId = 15800
and ap.LocationId = 15800
中的示例
以及where子句and (ap.LocationId = 15800 or rq.LocationId = 15800 )
我的建议是拥有这样的东西。
左边加入rq.LocationId = ap.LocationId
中的
以及where子句ap.LocationId = 15800
如果没有真实的数据,很难评估性能。