Quantcast
Channel: Active questions tagged cte - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 207

SQL Server query with common table expression suspended with pageiolatch_sh

$
0
0

I have a cte based query which runs for a very long time, and on the Activity Monitor for the query there are multiple rows showing the query is suspended in pageiolatch_sh. The strange thing is that this occurs only when executed using CTE (as first code bellow). If I use a temporary table instead (as in the second code bellow) it finish in a split-second.Any idea what can cause this?

QUERY1:

with cte AS(select a.*,    ROW_NUMBER() OVER (ORDER BY RecordDate) as row_number    from tbl_ShiurimList a        inner join tbl_FolderStructure b on a.MainFolderID=b.FolderID    where contains(NodeKeyPath,'0057900 and not (00058058 or 00057901 or 000401980)')        and isnull(IsDeleted,0)=0)select * from cte where row_number=5

QUERY2:

select a.*,  ROW_NUMBER() OVER (ORDER BY RecordDate) as row_numberinto #tempfrom tbl_ShiurimList a    inner join tbl_FolderStructure b on a.MainFolderID=b.FolderIDwhere contains(NodeKeyPath,'0057900 and not (00058058 or 00057901 or 000401980)')    and isnull(IsDeleted,0)=0select * from #temp where row_number=5

Viewing all articles
Browse latest Browse all 207

Trending Articles