gpt4 book ai didi

mysql - 查询运行太慢?

转载 作者:行者123 更新时间:2023-11-29 17:43:52 25 4
gpt4 key购买 nike

我正在编写一个带有左连接的 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 查询计划:
MySql Query Plan

最佳答案

我不太清楚你的目的。对于连接 和 rq.LocationId = 15800 中的示例
和 ap.LocationId = 15800
并在 where 子句中 and (ap.LocationId = 15800 或 rq.LocationId = 15800 )

我的建议是拥有这样的东西。

在左侧加入rq.LocationId = ap.LocationId并在 where 子句中 ap.LocationId = 15800

没有真实数据很难评估性能。

关于mysql - 查询运行太慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49892669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com