use*_*575 2 sql-server sql-server-2008
我们可以做一些不同的事情,而不是在where子句中使用函数.
DateAdd花时间表现不佳我猜...
如何优化这个sql
SELECT cust_id, order_date, price
FROM customers
WHERE DATEADD(DD,50,order_date)>=GETDATE()
不要运行你的功能order_date,getdate()而是运行反向运行
select cust_id, order_date, price
from customers
where order_date>=dateadd(Day,-50,getdate())
函数调用order_date将导致索引扫描,如果您改为在过滤条件上运行函数,则getdate()可以在此列上保留索引搜索.(如果它有索引).
SQL Server中的SARGable函数 - Rob Farley
| 归档时间: | 
 | 
| 查看次数: | 95 次 | 
| 最近记录: |