August 9, 2006 at 4:54 pm
How does the performance of the function "MAX(primary_key)" and the SQL statement "SELECT TOP 1 primary_key FROM dbo.tbl (fastfirstrow) ORDER BY primary_key DESC" compare (Especially when the column "primary_key" is numeric is the only primary key)?
August 9, 2006 at 5:57 pm
Still no time to open BOL?
_____________
Code for TallyGenerator
August 10, 2006 at 1:29 am
I discovered that the table hint "fastfirstrow" is being deprecated in future versions of SQL Server, but did not find any documentation comparing the feature with similiar features.
For my rather sarcastic reply to Sergiy's original post "Did you try BOL?", see:
August 10, 2006 at 2:17 am
Sergiy, if you're not going to say anything useful, why bother posting at all?
I didn't check BoL, but I tested it out on a large table that I have:
SELECT
max(DateChanged) FROM LargeTable
SELECT
TOP 1 Datechanged FROM LargeTable(fastfirstrow) ORDER BY Datechanged desc
Large table has around 50 million rows and is clustered on the datechanged column.
The select max took 4 ms, according to statistics time, did 5 logical reads and took 51 % of the query cost according to the execution plan. It did a clustered index scan, a top and a stream aggregate.
The select top 1 tok 2ms, did 5 logical reads and took 49% of the query cost. It did a clustered index scan and a top.
I was curious, so did a select top 1 without the hint. It took 1 ms, did 5 reads and had the same execution plan as the top 1 with the hint.
Hope that helps
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
August 10, 2006 at 6:07 am
Are you sure your investigation is really useful?
Gaining 2ms, o-oh, sorry, 3 ms on 50 mil rows table - do you beleive it really worth the efforts?
What kind of question - that kind of answer. There is no useful answer for the question of the toipic. So, why not just have fun?
Glad, the author returned my sarcasm. So, there is still hope.
_____________
Code for TallyGenerator
August 10, 2006 at 6:25 am
No, the gain is not really worth anything.
Except the question was how does the performance of the two compare. Answer, almost the same, no significant difference
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
August 10, 2006 at 6:21 pm
What do you mean "no significant difference"?
3 or 4 times faster (according to your own tests) is not significant difference for you?
Your answer is definetely wrong.
Another question - why to even try to improve performance of the query if response time is less than Windows timer tick duration even on huge tables?
Right answer is not "no significant difference" but "it does not matter".
_____________
Code for TallyGenerator
August 10, 2006 at 11:26 pm
In my experience, picky programmers are good programmers, even when their points can seem agitating.
August 10, 2006 at 11:49 pm
> 3 or 4 times faster (according to your own tests) is not significant difference for you?
As you said, is 3 ms worth the effort. If it was 3 min vs 1 min then it's significant difference. A difference of 3 ms, which may have been caused by machine load, is not significant.
> Your answer is definetely wrong.
Really, do tell.... </sarcasm>
Significant: Having or likely to have a major effect, Fairly large in amount or quantity
> Another question - why to even try to improve performance of the query if response time is less than Windows timer tick duration even on huge tables?
I wouldn't. It's a waste of time better spent on other queries, especially since on a busy machine query times can vary by several ms just due to load.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
August 13, 2006 at 9:30 pm
Thanks for sharing the results of your test, Gail...
--Jeff Moden
Change is inevitable... Change for the better is not.
August 13, 2006 at 10:24 pm
Ack! Not enough coffee! Took me a bit to figure out what the heck Serqiy and Eric were yakking about... took a look at Eric's previous post... I get it... thanks, guys.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply