V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
firetheasshole
V2EX  ›  SQL Server

sqlserver 查询缓慢问题

  •  1
     
  •   firetheasshole · 2023-03-28 11:46:40 +08:00 · 666 次点击
    这是一个创建于 397 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    liprais
        1
    liprais  
       2023-03-28 12:13:28 +08:00
    看执行计划,大概率 sql server 没选到索引
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3241 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 11:52 · PVG 19:52 · LAX 04:52 · JFK 07:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.