sqlserver 查询缓慢问题

2023-03-28 11:46:40 +08:00
 firetheasshole

请教懂 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 索引没用一样。

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

699 次点击
所在节点   SQL Server
1 条回复
liprais
2023-03-28 12:13:28 +08:00
看执行计划,大概率 sql server 没选到索引

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/927798

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX