yunxiaoxiao
V2EX  ›  SQL Server

sqlserver 查询缓慢问题

By yunxiaoxiao at 2023 年 3 月 28 日 · 3740 次点击

请教懂 sqlserver 数据库的大神,帮忙看看我一个 sql 语句查询缓慢的问题:

语句 1:select * from table1 where optime>='2023-03-01' and optime<='2023-03-28',表里有 5000 万数据,optime 字段做有索引,查询在 1 秒之内就出结果了。

语句 2: select count(1) from (select * from table1 where optime>='2023-03-01' and optime<='2023-03-28') a ,查询非常缓慢,基本都是超时。感觉 optime 索引没用一样。

请帮忙看看怎么改进。谢谢

1 条回复
F281M6Dh8DXpD1g2
   1
F281M6Dh8DXpD1g2  
   2023 年 3 月 28 日
看执行计划,大概率 sql server 没选到索引
© 2026 V2EX · 28ms · 3.9.8.5