| | |
CROSS APPLY - drives me mad
Please support our MS SQL advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2008
Posts: 1
Reputation:
Solved Threads: 0
Allright.
I have two queries, which provide the exact same result, yet the simpler one is roughly 100 times slower than the more complicated one.
I have absolutely no idea what is going on here.
And let me add, there is no recursion so this is no idiocyncracy of the query execution plan.
These are the queries:
1. tblFamily has a primary key on path, which is a condensed path of [(ancestor_id,)*this_id,]
There are no problems with that whatsoever in the various procedures accessing it.
2. util_list2tbl is simply Erland Sommarskog's table-valued function which splits a comma-delimited string og numbers into a table of (number, position_in_list)*.
No problems with that either.
As already mentioned, the first query shows up in the execution plan with 99% of the load, and the latter with 1%.
It takes 1:45 minutes on my home computer.
This is the output from io and time:
So I am wondering whether the whole implementation of cross apply is, erm, not-so-good.
Anyone?
I have two queries, which provide the exact same result, yet the simpler one is roughly 100 times slower than the more complicated one.
I have absolutely no idea what is going on here.
And let me add, there is no recursion so this is no idiocyncracy of the query execution plan.
These are the queries:
MS SQL Syntax (Toggle Plain Text)
SELECT dub.* FROM ( SELECT top 1 path FROM tblFamily WHERE 0 = 0 AND lvl = 3 ) AS sub CROSS apply ( SELECT path FROM tblFamily WHERE 0 = 0 AND id IN ( SELECT number FROM dbo.util_list2tbl (sub.path) ) ) AS dub SELECT lub.* FROM ( SELECT top 1 path FROM tblFamily WHERE 0 = 0 AND lvl = 3 ) AS sub CROSS apply ( SELECT number FROM dbo.util_list2tbl (sub.path) ) AS dub CROSS apply ( SELECT path FROM tblFamily WHERE 0 = 0 AND id = dub.number ) AS lub
1. tblFamily has a primary key on path, which is a condensed path of [(ancestor_id,)*this_id,]
There are no problems with that whatsoever in the various procedures accessing it.
2. util_list2tbl is simply Erland Sommarskog's table-valued function which splits a comma-delimited string og numbers into a table of (number, position_in_list)*.
No problems with that either.
As already mentioned, the first query shows up in the execution plan with 99% of the load, and the latter with 1%.
It takes 1:45 minutes on my home computer.
This is the output from io and time:
MS SQL Syntax (Toggle Plain Text)
SQL Server parse AND compile time: CPU time = 0 ms, elapsed time = 1 ms. (3 row(s) affected) TABLE '#1367E606'. Scan count 24422, logical reads 24422, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. TABLE 'tblFamily'. Scan count 2, logical reads 183, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. (1 row(s) affected) SQL Server Execution Times: CPU time = 82781 ms, elapsed time = 105673 ms. (3 row(s) affected) TABLE 'tblFamily'. Scan count 1, logical reads 13, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. TABLE '#1367E606'. Scan count 1, logical reads 1, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. (1 row(s) affected) SQL Server Execution Times: CPU time = 16 ms, elapsed time = 139 ms. SQL Server parse AND compile time: CPU time = 0 ms, elapsed time = 1 ms. SQL Server Execution Times: CPU time = 0 ms, elapsed time = 1 ms.
So I am wondering whether the whole implementation of cross apply is, erm, not-so-good.
Anyone?
![]() |
Other Threads in the MS SQL Forum
- Previous Thread: Error Code 424: object required
- Next Thread: insert data between SQL servers
Views: 2280 | Replies: 0
| Thread Tools | Search this Thread |
Tag cloud for MS SQL
"last autogrowth business connectingtodatabaseinuse count cursor data database dateadd datepart day" dbsize deadlock delete_trigger exploit getdate hack highperformancecomputing hpc hpcserver2008 ibm iis limit loop maximum microsoft ms mssql multiple multithreading news number password permission position query reporting result security server services sets single source sql sql-injection sqlserver sqlserver2005 subtype supercomputing supertype tables uniqueid update view weekday





