【发布时间】:2018-04-18 23:36:27
【问题描述】:
我为复杂视图创建了一个索引。在 Sql Server 管理工作室中运行以下查询需要 0 到几秒钟。查询计划显示 99% 的成本在我为主大表创建的索引上的 Index Seek 上。 (总子树成本为 7.5)
select * from ComplexView where id = 10000 and theDate = '1/1/2018'
但是,下面的查询
declare @id int = 10000, @theDate datetime = '1/1/2018'
select * from ComplexView where id = @id and theDate = @theDate
需要很长时间(3 到 10 分钟),查询计划捕获显示 57% 的成本在主大表上的 Table Scan 上(加上 10% 的过滤器和 14% 的哈希匹配和 17% 的排序, 总子树成本为 260)。
【问题讨论】:
标签: sql-server parameters sql-execution-plan