table150k には 150k レコードがあり、table3m には 3m レコードがある以下のようなクエリがあります。運用サーバーでは、一度に 1 つのレコードに対してこのクエリを非常に頻繁に実行する必要があります。これには多くの CPU パワーが必要です。
select t.id, t1.field1 as f1, t2.field1 as f2, t3.field1 as f3, ..., t12.field1 as f12
from table150k t
inner join table3m t1 on t1.fk = t.id and t1.[type] = 1
inner join table3m t2 on t2.fk = t.id and t2.[type] = 2
inner join table3m t3 on t3.fk = t.id and t3.[type] = 3
...
inner join table3m t12 on t12.fk = t.id and t12.[type] = 12
where t.id = @id
このクエリから内部結合を削除すると、正常に機能します。それらが含まれている場合、サーバーは CPU に負担をかけます。
このクエリ、データ構造、またはシナリオを最適化して、データの頻繁なフェッチで CPU のコストが高くならないようにするにはどうすればよいですか?