January 19, 2012 at 7:47 pm
j-1064772 (1/19/2012)
How do the newfangled Analytics functions compare with the Quirky Update method used for - among other things - creating running totals in term of performance ?
The Analytic functions don't, but the OVER clause enhancements allows running totals with the SUM() function and the enhanced OVER clause. See my previous article: The OVER Clause enhancements in SQL Server code named “Denali”, CTP3.[/url] You might also want to see my blog post on this: http://blog.waynesheffield.com/wayne/archive/2011/08/running-totals-in-denali-ctp3/[/url]. In short, the QU still wins, but the newly enhanced OVER clause beats everything else.
Did you click the "TSQL Challenges Winner" icon in my signature? It beat everything else quite handily doing a running total challenge.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
January 19, 2012 at 7:48 pm
Zeev Kazhdan (1/19/2012)
Finally they will have what Oracle had delivered ages ago....
and MySql, and DB2, and... well, nearly everyone else. It is long overdue, and should have been in 2008.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
January 19, 2012 at 7:51 pm
Jack Corbett (1/19/2012)
Good article Wayne. One thing I like to see in articles like this though is how you might solve the same problem without using the new functions. Just to see how much the new functions help.
Thanks Jack. That is a very good idea... I'll have to keep it in mind.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
January 19, 2012 at 7:53 pm
Jason, Geoff, Mark, Tim and KWymore...
Thanks, I'm very glad that you'll like it.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
January 20, 2012 at 12:53 am
WayneS (1/19/2012)
Actually...this article only talks about the Analytic functions. You might want to look at my previous article The OVER Clause enhancements in SQL Server code named “Denali”, CTP3[/url].
Basically, the MIN/MAX functions DO allow you to order your partition by a different column. But let's talk about this "over there"... it's more appropriate there.
Thanks for your link the the other article. I was not aware that these were also upgraded.
Best Regards,
Chris Büttner
January 20, 2012 at 9:56 am
Wonderful article, Wayne. The charts summarize a nicely laid out and well written article and make it real easy to get extra information. Thanks for taking the time to write a class article!
--Jeff Moden
Change is inevitable... Change for the better is not.
January 21, 2012 at 4:24 pm
January 22, 2012 at 4:58 pm
Great article Wayne!
Thanks for sharing.
-- Gianluca Sartori
January 24, 2012 at 6:01 am
Great article Wayne, thanks.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
January 29, 2013 at 12:07 pm
I see first_value and last_value function, but do not see second or third value function!
How can I write for example second_value() function by using analytical window function?
January 29, 2013 at 9:29 pm
zombieisdead2020 (1/29/2013)
I see first_value and last_value function, but do not see second or third value function!How can I write for example second_value() function by using analytical window function?
You will probably have to revert to the ROW_NUMBER() function, then look for where ROW_NUMBER() = 2, 3, etc.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
December 26, 2013 at 8:08 am
Wayne,
Excellent job.
Thomas
Thomas LeBlanc, MVP Data Platform Consultant
December 27, 2013 at 9:55 am
I just read this article. Great work Wayne.
-- Itzik Ben-Gan 2001
December 27, 2013 at 3:24 pm
Thanks Thomas and Alan!
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
January 1, 2014 at 8:59 pm
First of all Wayne, this is a great primer on using the new SQL 2012 analytic functions, and I know I for one will be referring folks to it if they have any questions.
RichB (1/19/2012)
Any idea what the performance of these things is like?
I can comment on using LAG (vs. LEAD) to calculate gaps. I did a recent test on a 1M row test harness (partitioned sets) and came up with the following results.
MEDIAN CPU (ms) Elapsed (ms)
SQL 2012 LEAD 1747 1740
SQL 2012 LAG 1357 1363
I am not sure why LAG works faster than LEAD but it seemed to be consistent. Neither of them is overall elapsed time winner compared to other solutions I've tried.
My thought question: Have you ever been told that your query runs too fast?
My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St
Viewing 15 posts - 16 through 30 (of 33 total)
You must be logged in to reply to this topic. Login to reply