,下面的语句引起如此大的压力到MySQL引擎它几乎挂起:很慢的SQL语句
select c.title, c.initial, c.surname, c.labelno, c.email, br1.bookingdate
from explorer.booking_record br1
inner join explorer.client c
on c.labelno = br1.labelno
and email not like ''
where br1.bookingdate >= '2009-01-01'
and br1.bookingdate < '2009-01-31'
and c.labelno Not In (Select labelno from explorer.booking_record br2 where br2.labelno = br1.labelno and br2.bookingdate >= '2010-01-01' and br2.bookingdate < '2010-01-31')
我已经试过上一些变化同样,没有连接和两个子语句,按照文档的建议添加'order by'。数据库中实际上并没有那么多记录,booking_record有大约50万条记录,客户端有450,000条记录。如果我让查询运行,它通常会在70-80秒后得到20个结果,但这会导致服务进入循环状态。
任何意见将不胜感激。
丹尼尔。
您是否在labelno&bookingdate(或两者上都有复杂的一个)上定义了索引? – 2010-01-18 12:04:04
我实际上没有对数据库本身的任何控制,所以我不能告诉你 - 我会看看它作为索引看起来是一个普通的话题在这里 – 2010-01-18 12:33:50
好吧,我已经看了一下,labelno是一个索引在客户端,但在booking_record中的索引是在bookingref(实际上并未在此查询中使用) – 2010-01-18 12:41:38