ロジック間のいくつかを使用してデータのチャンクを戻すストアド プロシージャがあります。私のステートメントの PostFamilyTags テーブルには、約 150 万行あります。以下の sql ステートメントは非常に遅く実行されます。
SELECT TOP(100)* FROM
(SELECT ROW_NUMBER()
OVER(ORDER BY p.date DESC) as NUM,
m.postfamilymediaID,
m.postfamilyID,
p.blogID,
p.userID,
p.BlogPostID,
m.postfamilymediatypeID as Type,
p.Title,
m.Address,
m.AddressEncoded,
m.ThumbNailAddress,
p.Date,
p.Summary,
p.Url,
m.ThumbNailIndex,
m.ThumbNailHeight,
m.ThumbNailWidth,
m.ThumbNailHeightAlt,
m.ThumbNailWidthAlt,
m.ItemName,
m.id3Title,
m.id3SubTitle,
m.id3ContributingArtists,
m.id3AlbumArtist,
m.id3Album,
m.id3Year,
m.id3Genre,
m.id3Length,
m.IsPublic
FROM
PostFamilyMedia as m
inner join
PostFamily as p on m.postfamilyID = p.postfamilyID
inner join
PostFamilyTags as pt on p.postfamilyID = pt.postfamilyID
inner join --Tags
Tags as t on pt.tagID = t.tagID
Where t.TagLevel = 1 and t.Tag = 'Electronic'
) AS a WHERE NUM >= (100 + 1) AND NUM <= (100 + 100)
しかし、その間のロジックを取り除くと、うまく機能します。
SELECT TOP(100)
m.postfamilymediaID,
m.postfamilyID,
p.blogID,
p.userID,
p.BlogPostID,
m.postfamilymediatypeID as Type,
p.Title,
m.Address,
m.AddressEncoded,
m.ThumbNailAddress,
p.Date,
p.Summary,
p.Url,
m.ThumbNailIndex,
m.ThumbNailHeight,
m.ThumbNailWidth,
m.ThumbNailHeightAlt,
m.ThumbNailWidthAlt,
m.ItemName,
m.id3Title,
m.id3SubTitle,
m.id3ContributingArtists,
m.id3AlbumArtist,
m.id3Album,
m.id3Year,
m.id3Genre,
m.id3Length,
m.IsPublic
FROM
PostFamilyMedia as m
inner join
PostFamily as p on m.postfamilyID = p.postfamilyID
inner join
PostFamilyTags as pt on p.postfamilyID = pt.postfamilyID
inner join --Tags
Tags as t on pt.tagID = t.tagID
Where t.TagLevel = 1 and t.Tag = 'Electronic'
最初の sql ステートメントの実行を高速化するのを手伝ってくれる人はいますか?