SQL Server 从非规范化表迁移到规范化表导致性能问题

问题描述 投票:0回答:0

我们的 SQL Server 数据模型中有一个非规范化表,我们希望将其迁移为规范化格式。但是,我们为此迁移创建的查询导致了严重的延迟。我们检查了实际的执行计划,发现估计的行数比实际的行数高很多。

旧表数据模型:

A列(PK列):长 Column1:字符串 Column2:字符串 Column3:字符串 新表数据模型:

A列(PK列):长 Column1:Long(FK值通过引用另一个表) Column2:Long(FK值通过引用另一个表) Column3:Long(FK值通过引用另一个表)

insert into newTable (
    pkcolumn,
    column1,
    column2,
    column3
)
select 
    pkColumn,
    anothertable1.id,
    anothertable2.id,
    anothertable3.id
left join anothertable as anothertable1 on 
    anothertable1.field_id = 1 and 
    anothertable1.value = oldtable.column1 and 
    oldtable.pkColumn in (1,2,3,4,5,6,7,8,9,10)
left join anothertable as anothertable2 on 
    anothertable2.field_id = 2 and 
    anothertable2.value = oldtable.column2 and 
    oldtable.pkColumn in (1,2,3,4,5,6,7,8,9,10)
left join anothertable as anothertable3 on 
    anothertable3.field_id = 3 and 
    anothertable3.value = oldtable.column3 and 
    oldtable.pkColumn in (1,2,3,4,5,6,7,8,9,10)

批量大小: oldtable.pkColumn in (1,2,3,4,5,6,7,8,9,10....1000)

问题: 我们为从非规范化表迁移到规范化表而创建的查询导致了严重的延迟。我们检查了实际的执行计划,发现估计的行数比实际的行数高很多。我们已经更新了查询涉及的表的统计信息,并重建了查询中使用的列的索引。

问题: 在这种情况下,有什么方法可以提高迁移的性能吗?

附加信息: 查询计划:Link

sql sql-server query-optimization data-migration
© www.soinside.com 2019 - 2024. All rights reserved.