【发布时间】:2015-01-26 22:57:59
【问题描述】:
我有以下 SQL 语句,我想让它更有效率。查看执行计划,我可以看到@newWebcastEvents 上有一个聚集索引扫描。有没有办法可以把它变成一个寻求?或者有什么其他方法可以让下面的工作更有效率吗?
declare @newWebcastEvents table (
webcastEventId int not null primary key clustered (webcastEventId) with (ignore_dup_key=off)
)
insert into @newWebcastEvents
select wel.WebcastEventId
from WebcastChannelWebcastEventLink wel with (nolock)
where wel.WebcastChannelId = 1178
Update WebcastEvent
set WebcastEventTitle = LEFT(WebcastEventTitle, CHARINDEX('(CLONE)',WebcastEventTitle,0) - 2)
where
WebcastEvent.WebcastEventId in (select webcastEventId from @newWebcastEvents)
【问题讨论】:
-
它只是一个临时表,而不仅仅是主键。该表很小,最多只有 15 行。我正在更新的表可能有数千行。
-
WebcastChannelWebcastEventLink 中大约有 5000 行,该表大约有 15 行被选入@newWebcastEvents
标签: sql performance tsql indexing