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

SQL Server 查询优化

  •  
  •   123go · 2021-03-21 19:19:11 +08:00 · 943 次点击
    这是一个创建于 1103 天前的主题,其中的信息可能已经有所发展或是发生改变。

    现在有两张表 Bs_Articles 、ReferenceRelationship,数据量分别是一千四百万和一亿行数据 Bs_Articles 表是基础表,ReferenceRelationship 表是 Bs_Articles 表的引用关系数据 现在需要 join 两表,根据 Bs_Articles.ID 聚合 ,统计 Bs_Articles 表中四万条数据在 ReferenceRelationship 表中的引用关系数量 原来执行需要近三分钟,重建了两表的索引后现在执行需要一分十秒左右,计划要求在 5 秒左右

    select   a.id, COUNT(distinct b.original_articleid) as UseCount
    from     Bs_Articles as a with(nolock) join ReferenceRelationship as b with(nolock) on a.ID = b.reference_articleid
    where    contains(([Subject], [Abstract]), 'hello world')
    group by a.id
    

    这个是 sql 的执行计划

    image.png

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3228 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 11:31 · PVG 19:31 · LAX 04:31 · JFK 07:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.