只想问哪个需要更多时间。
以下示例方案:
SELECT *
FROM
(SELECT *
FROM t1
WHERE [Date] BETWEEN "20151012" AND "20151018"
UNION ALL
SELECT *
FROM t2
WHERE [Date] BETWEEN "20151012" AND "20151018"
UNION ALL
SELECT *
FROM t3
WHERE [Date] BETWEEN "20151012" AND "20151018"
) AS T
或本声明:
SELECT *
FROM
(SELECT * FROM t1
UNION ALL
SELECT * FROM t2
UNION ALL
SELECT * FROM t3) AS T
WHERE
[Date] BETWEEN "20151012" AND "20151018"
非常感谢!
答案 0 :(得分:0)
我认为最安全,最明确的版本是:
SELECT *
FROM t1
WHERE [Date] BETWEEN "20151012" AND "20151018"
UNION ALL
SELECT *
FROM t2
WHERE [Date] BETWEEN "20151012" AND "20151018"
UNION ALL
SELECT *
FROM t3
WHERE [Date] BETWEEN "20151012" AND "20151018"
没有必要希望查询计划能够确定哪些索引可以在子查询中使用。你可能会获得同等的表现,但你不会因为这个而变得更糟。
答案 1 :(得分:0)
SQL Server在将谓词推送到基表时没有问题。
您可以检查执行计划以验证这一点。
我更关心字符串文字的双引号。您应该使用单引号,以便查询在默认quoted_identifier
设置下正常工作,并且它不会将20151012
解释为尝试的列引用。