我使用 dapper-dot-net 作为 ORM,它会生成以下执行缓慢(1700 毫秒)的 SQL 代码。
exec sp_executesql N'SELECT TOP 5 SensorValue FROM "Values"
WHERE DeviceId IN (@id1,@id2) AND SensorId = @sensor
AND SensorValue != -32768 AND SensorValue != -32767',N'@id1
bigint,@id2 bigint,@sensor int',@id1=139,@id2=726,@sensor=178
当我通过删除参数来修改此代码时,查询的执行速度非常快(20 毫秒)。缺少这些参数是否真的会产生如此大的差异,为什么?
exec sp_executesql N'SELECT TOP 5 SensorValue FROM "Values"
WHERE DeviceId IN (139,726) AND SensorId = 178
AND SensorValue != -32768 AND SensorValue != -32767'