【问题标题】:Why when I use variables on SQL the Database Engine avoid the indexes?为什么当我在 SQL 上使用变量时,数据库引擎会避开索引?
【发布时间】:2020-10-13 16:07:25
【问题描述】:

我正在改进通过“声明”传递变量的 SSIS 流程,我发现:

不使用声明(执行时间:1秒)

select *
from fact_Venta
where Data_ID >= 20201001
and Data_ID <= 20201001

使用声明(执行时间:2分钟)

declare @data1 as int = 20201001
declare @data2 as int = 20201001
select *
from fact_Venta
where Data_ID >= @data1
and Data_ID <= @data2

如您所见,当我使用“声明”SQL 数据库引擎时,不要使用索引

有关更多信息,这是用于“位置”列的索引

谁能解释一下为什么会这样?

谢谢!

【问题讨论】:

标签: sql indexing ssis


【解决方案1】:
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多