我跑步时
select d.part, d."key"
from dbo.orderdtl d
inner join dbo.dwgroute r on ltrim(d.part) = ltrim(r.partmade)
order by d.part offset 0 rows
它返回13行,查询大约需要半秒钟,但是当我运行时
select d.part, d."key"
from dbo.orderdtl d
inner join dbo.dwgroute r on ltrim(d.part) = ltrim(r.partmade)
order by d.part
offset 0 rows fetch first 10 rows only
查询挂起,将永远不会返回任何结果。
奇怪的是,删除ltrim
以便查询读取
select d.part, d."key"
from dbo.orderdtl d
inner join dbo.dwgroute r on d.part = r.partmade
order by d.part
offset 0 rows fetch first 10 rows only
也会使查询快速执行,但我确实需要保留ltrim
才能从查询中获得所需的结果。
有人知道导致这种现象的原因是什么吗?我正在使用SQL Server 2017(v14.0.3192.2)。
select d.part, d."key"
from dbo.orderdtl d
inner join dbo.dwgroute r on ltrim(d.part) = ltrim(r.partmade)
order by d.part
offset 0 rows fetch next 10 rows only
如果您的目标是仅查看前十名,也可以使用:
select top 10 d.part, d."key" from dbo.orderdtl d inner join dbo.dwgroute r on ltrim(d.part) = ltrim(r.partmade) order by d.part