我有一个每秒返回大量数据并显示在网格中的 SP。我现在正在尝试减少带宽并考虑仅返回当前在我的网格中显示的列。
这当然是简化和最小化的,但基本上我所拥有的是以下 SP:
SELECT
[Animals].[AnimalID] AS [AnimalID],
[Animals].[name] AS [AnimalName],
[Foods].[DisplayName] AS [Food],
[Animals].[Age] AS [AnimalAge],
[Animals].[AmountOfFood] AS [AmountOfFood]
我目前正在尝试的是传递当前显示在网格上的字段(@fields)名称的 TVP,并仅返回必需的字段,如下所示:
SELECT
[Animals].[AnimalID] AS [AnimalID],
[Animals].[name] AS [AnimalName],
CASE
WHEN ('Food' in (select * from @fields))
THEN [Foods].[DisplayName]
END AS [Food],
CASE
WHEN ('AnimalAge' in (select * from @fields))
THEN [Animals].[Age]
END AS [AnimalAge],
CASE
WHEN ('AmountOfFood' in (select * from @fields))
THEN [Animals].[AmountOfFood]
END AS [AmountOfFood]
我面临的问题是(正如所料)我的 SP 从 ~200 毫秒变为 ~1 秒
有什么办法可以重写它,以免它杀死我们?
我的王国!