我有2个数据库(v1,v7),它们具有相同的数据结构和架构。 v7上的数据大于v1。当我在v7上运行相同的SQL语句时需要不到1秒 v1也花了11s。
我的SQL声明:
SELECT
bs.[ID], bs.[TapeID], bs.[ChanelID], bs.[ContractID],
bs.[ContractSectionID], bs.[Name], bs.[RegisterDate],
bs.[ValidFrom], bs.[ValidToDate], bs.[GPRP], bs.[Status],
bs.[Note], bs.[Code], bs.[JobCodeID], bs.[SpotCount],
bs.[BookNumber], bs.[Adjusted], bs.[PrintedCNPS],
bs.[UserID], bs.[CreateTime], bs.[ModifiedTime],
'' + t.Code + ' - ' + t.Name, ch.Code,
'[' + c.Code + '] ' + cus.Name, cs.Code,
jb.Code, p.Name, us.UserName, cus.Code, t.Duration,
(select count(*) from Spot
where Position in ('1','2','3','E','D','F')
and bs.ID = Spot.BookScheudlerID
and Status not in (2,3,5)) as SpotUuTien, --mục địch tạo ra column
(select count(*) from Spot
where Position in ('A') and Pending = 1
and bs.ID = Spot.BookScheudlerID
and Status not in (2, 3, 5)) as SpotUuTienFree, /*mục địch tạo ra column*/
FROM
[BookScheduler] bs
INNER JOIN
Tape t on bs.TapeID = t.ID
INNER JOIN
Contract c on bs.ContractID = c.ID
INNER JOIN
ContractSection cs on bs.ContractSectionID = cs.ID
LEFT JOIN
JobCode jb on bs.JobCodeID = jb.ID
INNER JOIN
Product p on t.ProductID = p.ID
INNER JOIN
Chanel ch on bs.ChanelID = ch.ID
INNER JOIN
Customer cus on c.CustomerID = cus.ID
LEFT JOIN
AppUser us on bs.UserID = us.ID
WHERE
bs.ValidFrom >= '05/01/2015 00:00:00'
AND bs.ValidToDate <= '05/30/2015 00:00:00'
我认为v1上的问题索引应该重建其索引。然后运行上面的sql语句,但结果没有改变。
然后我创建了一个与v1结构相同的新数据库,并且我将数据从v1移动到新数据库,当我在新数据库上以非常快的速度运行SQL语句时(如在v7上)。
那么让我问一下我的v1是什么?以及如何在不创建新数据库的情况下提高速度?