有人可以告诉我为什么这之间有区别:
1)
view2 -> view1 -> 远程服务器表
从 view2 中选择 * - 需要 8 分钟
2)
view2 -> table1 -> remoute_server_table
从 view2 中选择 * - 需要 10 秒
两种变体的一切都相同:
- view2 有 5 个连接
- remoute_server_table 是一样的
区别在于使用 table1 或 view1:
视图1:
CREATE VIEW view1
AS
SELECT ...
FROM remoute_server_table as o
WHERE CAST(o.Период as Date) >= DATEADD(d,-1, CAST(getdate() as Date))
表格1:
TRUNCATE TABLE table1;
GO
INSERT table1 (...)
SELECT ...
FROME remoute_server_table as loc
WHERE CAST(loc.Период as Date) >= DATEADD(d,-1, CAST(getdate() as Date))
GO
SO,table1 ~ view1 由select 子句和数据组成。
Edit1:执行计划不同。table1 和 view1 没有索引