January 23, 2008 at 8:20 pm
We'll I'll be... just tried the CTE equivelent of how I build Tally tables (NO, NO RECURSION PLEASE! 😛 ) on the same example data... it does surprisingly well! Still not as fast as a full blown Tally table, but it comes close! 8-10 CPU seconds instead of the 5-6 for the Tally table. Advantage here is that you don't very often need a 6 million row Tally table.
Here's the code I ran against the previous test table...
SET STATISTICS TIME ON
;WITH cTally AS
(SELECT TOP 6000000
        N = ROW_NUMBER() OVER (ORDER BY sc1.OBJECT_ID)
   FROM Master.sys.ALL_Columns sc1
  CROSS JOIN Master.sys.ALL_Columns sc2)
 SELECT N 
   FROM cTally t
   LEFT OUTER JOIN yourtable y
     ON t.N = y.SerialNumber
  WHERE y.SerialNumber IS NULL 
SET STATISTICS IO OFF
SET STATISTICS TIME OFF
[/font]
... and here's the results...
Table 'syscolrdb'. Scan count 2, logical reads 153, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'syscolpars'. Scan count 2, logical reads 10, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'yourtable'. Scan count 1, logical reads 8863, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times:
CPU time = 8640 ms, elapsed time = 51484 ms.
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 1 ms.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 24, 2008 at 11:47 am
Thank you all for your help. I see that my question developed a life of it's own. 🙂
Much to understand in all that, besides the solution to the stated problem. I learn so much every time I post!
To update you, after discussions with users, the concept of a master serial number table with item dispositions was seen as a benefit, so I will have a full number sequence to compare against. Now, I have to design a business process where serial numbers are generated, logged, and dispositions are recorded.
As a tangent to the current discussion, how many DBA's end up having to change business practices in order to implement the solutions they have been tasked with digitally? My mantra around here is "tools are not solutions" (they are starting to get it) and even though I can design and implement software 'tools', I have to design the 'solution' first. The 'solution' process is not just to better define the scope of the tool (a definite benefit), but to solve the problem regardless of the tool, and therefore, not focused on the technology itself. How many database professionals go through this? Is this a common cycle for DBA's?
January 24, 2008 at 12:32 pm
I've never had to change a business process to match the system. I've had business processes that I couldn't enforce with the system, because they weren't things a computer could check (or, earlier in my career, because I simply didn't know how to code them), but I've just left those in the realm of human judgement and policy.
Yes, absolutely yes, you need to know what you're solving and why and how, before you begin to build a system to solve it. I've had plenty of requests for changes to systems which, if implemented, would have had serious negative consequences to the business. I've had solutions proposed that didn't have a problem, or where the problem wasn't clearly understood. I've even had a manager tell me that, "we're not sure what's wrong, but we're assigning the solution to you, since you're good at that kind of thing" (yes, for those who are curious, he was the Vice President of Sales and Marketing).
This doesn't mean spend six years trying to figure out what's going on and how to build a perfect solution to it. It means at least have a good idea of what you're doing and why before you start. Simple as that.
If, on the other hand, your job is to implement pieces of code per specification, with no input on what gets done or why, then this rule doesn't apply.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 3 posts - 16 through 17 (of 17 total)
You must be logged in to reply to this topic. Login to reply