123go

SQL Server 查询优化

  •  
  •   123go · Mar 21, 2021 · 1848 views
    This topic created in 1949 days ago, the information mentioned may be changed or developed.

    现在有两张表 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

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5771 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 54ms · UTC 06:14 · PVG 14:14 · LAX 23:14 · JFK 02:14
    ♥ Do have faith in what you're doing.