我编写了一个查询,在该查询中创建了一个字符串并根据条件从表中获取不同的值。
该表有大约 5000 行。此查询需要将近 20 秒才能执行。
我相信字符串比较使查询变得如此缓慢。但我想知道我的替代方案是什么。
询问:
select distinct
Convert(nvarchar, p1.trafficSerial) +' ('+ p1.sourceTraffic + ' - ' + p1.sinkTraffic + ' )' as traffic
from
portList as p1
inner join
portList as p2 ON p1.pmId = p2.sinkId
AND P1.trafficSerial IS NOT NULL
AND (p1.trafficSerial = p2.trafficSerial)
AND (P1.sourceTraffic = P2.sourceTraffic)
AND (P1.sinkTraffic = P2.sinkTraffic)
where
p1.siteCodeID = @SiteId