使用硬编码的 1=0 和 1=1 值测试查询。当我用一个变量代替它们时,查询速度会变慢。和建议?
DECLARE @BoxType int
SET @BoxType = 2
Select blah from table t
INNER JOIN table2 t2
ON (t2.blah = t.blah AND 1=1 OR t2.blah = t.blah AND 1=0)
- 非常快
重写使用:
...
INNER JOIN table t
ON (t2.blah = t.blah AND @BoxType = 2 OR t2.blah = t.blah AND @BoxType = 1)
- 非常慢